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.
 
 
 
 
 
 

76 lines
1.6 KiB

  1. #ifndef IZ_NET_H
  2. #define IZ_NET_H
  3. #include <minIni.h>
  4. #include <SDL_thread.h>
  5. #include "../IZ_common.h"
  6. #include "../config/IZ_config.h"
  7. #include "../input/IZ_action.h"
  8. #include "core/IZ_websocket.h"
  9. #include "svc/IZ_wsclient.h"
  10. typedef enum {
  11. IZ_NET_STATUS_PRISTINE,
  12. IZ_NET_STATUS_CONNECTING,
  13. IZ_NET_STATUS_ERROR,
  14. IZ_NET_STATUS_CONNECTED,
  15. } IZ_NetStatus;
  16. typedef struct {
  17. u16 packet_interval_ms;
  18. u8 max_reconnect_retries;
  19. u8 reconnect_interval_secs;
  20. char username[32];
  21. } IZ_NetConfig;
  22. typedef struct {
  23. SDL_Thread* client_thread;
  24. IZ_NetConfig config;
  25. IZ_Websocket binding;
  26. IZ_WSClientInitializeParams params;
  27. void* callback;
  28. IZ_Action action[IZ_PLAYERS];
  29. u8 retries;
  30. IZ_NetStatus status;
  31. // TODO add message queue
  32. } IZ_NetState;
  33. static IZ_NetState IZ_NET_DEFAULT_STATE = {
  34. .client_thread = NULL,
  35. .config = {
  36. .packet_interval_ms = 200,
  37. .max_reconnect_retries = 3,
  38. .reconnect_interval_secs = 3,
  39. .username = "Player",
  40. },
  41. .binding = {
  42. .interrupted = false,
  43. .context = NULL,
  44. .connection = NULL,
  45. .user_data = NULL,
  46. },
  47. .params = {
  48. .port = 42069,
  49. .path = "/",
  50. .host = "localhost",
  51. },
  52. .callback = NULL,
  53. .action = {},
  54. .retries = 3,
  55. .status = IZ_NET_STATUS_PRISTINE,
  56. };
  57. IZ_ProcedureResult IZ_NetInitialize(IZ_NetState*, void*, void*, const char*, u8, const char**);
  58. void IZ_NetConnect(IZ_NetState*, IZ_WSClientInitializeParams);
  59. void IZ_NetDisconnect(IZ_NetState*);
  60. IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState*, const char*);
  61. void IZ_NetSendBinaryMessage(IZ_NetState*, void*, size_t);
  62. void IZ_NetSendTextMessage(IZ_NetState*, char*, size_t);
  63. #endif