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.
 
 
 
 
 
 

114 lines
2.6 KiB

  1. #include "IZ_wsclient.h"
  2. IZ_ProcedureResult IZ_WSClientCallback(
  3. struct lws* wsi,
  4. enum lws_callback_reasons reason,
  5. void* user,
  6. void* in,
  7. size_t len
  8. ) {
  9. switch (reason) {
  10. case LWS_CALLBACK_PROTOCOL_INIT:
  11. return IZ_WSClientProtocolInitialize(wsi, in);
  12. case LWS_CALLBACK_PROTOCOL_DESTROY:
  13. IZ_WSClientProtocolTeardown(wsi);
  14. break;
  15. case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
  16. return IZ_WSClientConnectionError(wsi, in);
  17. case LWS_CALLBACK_CLIENT_ESTABLISHED:
  18. return IZ_WSClientOnOpen(wsi, user);
  19. case LWS_CALLBACK_CLIENT_CLOSED:
  20. IZ_WSClientOnClose(wsi);
  21. break;
  22. case LWS_CALLBACK_CLIENT_RECEIVE:
  23. IZ_WSClientOnReceive(wsi, user, in, len);
  24. break;
  25. case LWS_CALLBACK_CLIENT_WRITEABLE:
  26. return IZ_WSClientWritable(wsi);
  27. default:
  28. break;
  29. }
  30. return lws_callback_http_dummy(wsi, reason, user, in, len);
  31. }
  32. IZ_ProcedureResult IZ_WSClientInitialize(IZ_Websocket* state, IZ_WSClientInitializeParams params) {
  33. struct lws_context_creation_info info;
  34. memset(&info, 0, sizeof info);
  35. info.port = CONTEXT_PORT_NO_LISTEN;
  36. static const struct lws_protocols protocols[] = {
  37. {
  38. .name = NETWORK_PROTOCOL,
  39. .callback = IZ_WSClientCallback,
  40. .per_session_data_size = sizeof(IZ_WSClientSessionData),
  41. .rx_buffer_size = 1024,
  42. .id = 0,
  43. .user = NULL,
  44. .tx_packet_size = 0,
  45. },
  46. LWS_PROTOCOL_LIST_TERM
  47. };
  48. info.protocols = protocols;
  49. static struct lws_protocol_vhost_options pvo_address = {
  50. NULL,
  51. NULL,
  52. "address", /* pvo name */
  53. "localhost" /* pvo value */
  54. };
  55. pvo_address.value = params.host;
  56. static struct lws_protocol_vhost_options pvo_path = {
  57. &pvo_address,
  58. NULL,
  59. "path", /* pvo name */
  60. "/" /* pvo value */
  61. };
  62. pvo_path.value = params.path;
  63. static struct lws_protocol_vhost_options pvo_port = {
  64. &pvo_path,
  65. NULL,
  66. "port", /* pvo name */
  67. NULL /* pvo value */
  68. };
  69. pvo_port.value = (void*) &params.port;
  70. static struct lws_protocol_vhost_options pvo_app = {
  71. &pvo_port,
  72. NULL,
  73. "app",
  74. NULL,
  75. };
  76. pvo_app.value = state->user_data;
  77. static const struct lws_protocol_vhost_options pvo = {
  78. NULL, /* "next" pvo linked-list */
  79. &pvo_app, /* "child" pvo linked-list */
  80. NETWORK_PROTOCOL, /* protocol name we belong to on this vhost */
  81. "" /* ignored */
  82. };
  83. info.pvo = &pvo;
  84. info.fd_limit_per_thread = 1 + 1 + 1;
  85. IZ_WebsocketInitialize(state);
  86. state->context = lws_create_context(&info);
  87. if (!state->context) {
  88. return -1;
  89. }
  90. return 0;
  91. }
  92. IZ_ProcedureResult IZ_WSClientHandle(IZ_Websocket* state) {
  93. return IZ_WebsocketHandle(state);
  94. }
  95. void IZ_WSClientTeardown(IZ_Websocket* state) {
  96. IZ_WebsocketTeardown(state);
  97. }
  98. void IZ_WSClientCancelService(IZ_Websocket* state) {
  99. IZ_WebsocketCancelService(state);
  100. }