2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

96 lines
2.5 KiB

  1. #include <libwebsockets.h>
  2. #include <signal.h>
  3. #include "IZ_common.h"
  4. static struct lws_protocols protocols[] = {
  5. { "http", lws_callback_http_dummy, 0, 0, 0, NULL, 0},
  6. LWS_PROTOCOL_LIST_TERM
  7. };
  8. static const lws_retry_bo_t retry = {
  9. .secs_since_valid_ping = 3,
  10. .secs_since_valid_hangup = 10,
  11. };
  12. static i32 interrupted;
  13. static const struct lws_http_mount mount = {
  14. /* .mount_next */ NULL, /* linked-list "next" */
  15. /* .mountpoint */ "/", /* mountpoint URL */
  16. /* .origin */ "./mount-origin", /* serve from dir */
  17. /* .def */ "index.html", /* default filename */
  18. /* .protocol */ NULL,
  19. /* .cgienv */ NULL,
  20. /* .extra_mimetypes */ NULL,
  21. /* .interpret */ NULL,
  22. /* .cgi_timeout */ 0,
  23. /* .cache_max_age */ 0,
  24. /* .auth_mask */ 0,
  25. /* .cache_reusable */ 0,
  26. /* .cache_revalidate */ 0,
  27. /* .cache_intermediaries */ 0,
  28. /* .origin_protocol */ LWSMPRO_FILE, /* files in a dir */
  29. /* .mountpoint_len */ 1, /* char count */
  30. /* .basic_auth_login_file */ NULL,
  31. };
  32. void sigint_handler(i32 sig) {
  33. interrupted = 1;
  34. }
  35. IZ_ProcedureResult main(i32 arg_count, char* arg_values[]) {
  36. struct lws_context_creation_info info;
  37. struct lws_context* context;
  38. const char* p;
  39. i32 n = 0;
  40. i32 logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
  41. signal(SIGINT, sigint_handler);
  42. if ((p = lws_cmdline_option(arg_count, arg_values, "-d")))
  43. logs = atoi(p);
  44. lws_set_log_level(logs, NULL);
  45. lwsl_user("LWS minimal ws server | visit http://localhost:7681 (-s = use TLS / https)\n");
  46. memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
  47. info.port = 7681;
  48. info.mounts = &mount;
  49. info.protocols = protocols;
  50. info.vhost_name = "localhost";
  51. #if defined(LWS_WITH_PLUGINS)
  52. info.pvo = &pvo;
  53. #endif
  54. info.options =
  55. LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
  56. #if defined(LWS_WITH_TLS)
  57. if (lws_cmdline_option(arg_count, arg_values, "-s")) {
  58. lwsl_user("Server using TLS\n");
  59. info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
  60. info.ssl_cert_filepath = "localhost-100y.cert";
  61. info.ssl_private_key_filepath = "localhost-100y.key";
  62. }
  63. #endif
  64. if (lws_cmdline_option(arg_count, arg_values, "-h"))
  65. info.options |= LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK;
  66. if (lws_cmdline_option(arg_count, arg_values, "-v"))
  67. info.retry_and_idle_policy = &retry;
  68. context = lws_create_context(&info);
  69. if (!context) {
  70. lwsl_err("lws init failed\n");
  71. return 1;
  72. }
  73. while (n >= 0 && !interrupted)
  74. n = lws_service(context, 0);
  75. lws_context_destroy(context);
  76. return 0;
  77. }