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.
 
 
 
 
 
 

86 lines
1.9 KiB

  1. #ifndef IZ_NET_CLIENT_H
  2. #define IZ_NET_CLIENT_H
  3. #include <SDL_thread.h>
  4. #include <ini-config.h>
  5. #include <ini-config/source/types/int.h>
  6. #include <ini-config/source/types/string.h>
  7. #include "../common/IZ_common.h"
  8. #include "../game/input/IZ_action.h"
  9. #include "../log/IZ_log.h"
  10. #include "../stdinc/IZ_string.h"
  11. #include "svc/IZ_wsclient.h"
  12. typedef enum {
  13. IZ_NET_CLIENT_STATUS_PRISTINE,
  14. IZ_NET_CLIENT_STATUS_CONNECTING,
  15. IZ_NET_CLIENT_STATUS_ERROR,
  16. IZ_NET_CLIENT_STATUS_CONNECTED,
  17. } IZ_NetClientStatus;
  18. typedef struct {
  19. u16 packet_interval_ms;
  20. u8 max_reconnect_retries;
  21. u8 reconnect_interval_secs;
  22. char usernames[IZ_PLAYERS][32];
  23. } IZ_NetClientConfig;
  24. typedef struct {
  25. void* thread;
  26. IZ_NetClientConfig config;
  27. IZ_NetBinding binding;
  28. IZ_NetInitializeParams params;
  29. void* callback;
  30. IZ_Action action[IZ_PLAYERS];
  31. u8 retries;
  32. IZ_NetClientStatus status;
  33. // TODO add message queue
  34. } IZ_NetClientState;
  35. static IZ_NetClientState IZ_NET_CLIENT_DEFAULT_STATE = {
  36. .thread = NULL,
  37. .config = {
  38. .packet_interval_ms = 200,
  39. .max_reconnect_retries = 3,
  40. .reconnect_interval_secs = 3,
  41. .usernames = {
  42. "Player 1",
  43. #if IZ_PLAYERS > 1
  44. "Player 2"
  45. #endif
  46. },
  47. },
  48. .binding = {
  49. .interrupted = false,
  50. .context = NULL,
  51. .connection = NULL,
  52. .user_data = NULL,
  53. },
  54. .params = {
  55. .port = 42069,
  56. .path = "/",
  57. .host = "localhost",
  58. },
  59. .callback = NULL,
  60. .action = {},
  61. .retries = 3,
  62. .status = IZ_NET_CLIENT_STATUS_PRISTINE,
  63. };
  64. IZ_ProcedureResult IZ_NetClientInitialize(IZ_NetClientState*, void*, void*, const char *, u8, const char *[]);
  65. void IZ_NetClientConnect(IZ_NetClientState*, IZ_WSClientInitializeParams);
  66. void IZ_NetClientDisconnect(IZ_NetClientState*);
  67. IZ_ProcedureResult IZ_NetClientSaveConfig(IZ_NetClientState*, const char*);
  68. void IZ_NetClientSendBinaryMessage(IZ_NetClientState*, void*, size_t);
  69. void IZ_NetClientSendTextMessage(IZ_NetClientState*, char*, size_t);
  70. void IZ_NetClientTeardown(IZ_NetClientState*);
  71. #endif