2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
 
 
 
 
 
 

85 line
2.2 KiB

  1. #include <libwebsockets.h>
  2. #include <string.h>
  3. #include <signal.h>
  4. #include "IZ_common.h"
  5. #include "log/IZ_log.h"
  6. #define LWS_PLUGIN_STATIC
  7. #include "protocol_lws_minimal.c"
  8. static struct lws_protocols protocols[] = {
  9. //{ "http", lws_callback_http_dummy, 0, 0, 0, NULL, 0 },
  10. LWS_PLUGIN_PROTOCOL_MINIMAL,
  11. LWS_PROTOCOL_LIST_TERM
  12. };
  13. static int interrupted;
  14. static const struct lws_http_mount mount = {
  15. /* .mount_next */ NULL, /* linked-list "next" */
  16. /* .mountpoint */ "/", /* mountpoint URL */
  17. /* .origin */ "./mount-origin", /* serve from dir */
  18. /* .def */ "index.html", /* default filename */
  19. /* .protocol */ NULL,
  20. /* .cgienv */ NULL,
  21. /* .extra_mimetypes */ NULL,
  22. /* .interpret */ NULL,
  23. /* .cgi_timeout */ 0,
  24. /* .cache_max_age */ 0,
  25. /* .auth_mask */ 0,
  26. /* .cache_reusable */ 0,
  27. /* .cache_revalidate */ 0,
  28. /* .cache_intermediaries */ 0,
  29. /* .origin_protocol */ LWSMPRO_FILE, /* files in a dir */
  30. /* .mountpoint_len */ 1, /* char count */
  31. /* .basic_auth_login_file */ NULL,
  32. };
  33. void sigint_handler(int sig)
  34. {
  35. interrupted = 1;
  36. }
  37. int main(int argc, const char **argv)
  38. {
  39. struct lws_context_creation_info info;
  40. struct lws_context *context;
  41. const char *p;
  42. int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE
  43. /* for LLL_ verbosity above NOTICE to be built into lws,
  44. * lws must have been configured and built with
  45. * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */
  46. /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */
  47. /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */
  48. /* | LLL_DEBUG */;
  49. signal(SIGINT, sigint_handler);
  50. if ((p = lws_cmdline_option(argc, argv, "-d")))
  51. logs = atoi(p);
  52. IZ_LogInterceptWSMessages(logs);
  53. lwsl_user("LWS minimal ws server (lws_ring) | visit http://localhost:7681\n");
  54. memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
  55. info.port = 42069;
  56. info.mounts = &mount;
  57. info.protocols = protocols;
  58. info.options =
  59. LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
  60. context = lws_create_context(&info);
  61. if (!context) {
  62. lwsl_err("lws init failed\n");
  63. return 1;
  64. }
  65. while (n >= 0 && !interrupted)
  66. n = lws_service(context, 0);
  67. lws_context_destroy(context);
  68. return 0;
  69. }