2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

98 rader
2.0 KiB

  1. #include "IZ_net_server.h"
  2. bool IZ_NetServerIsValidPort(u16 port) {
  3. return (1000 <= port && port <= 59999);
  4. }
  5. static IZ_ConfigItem net_server_config_items[] = {
  6. {
  7. IZ_CONFIG_TYPE_STRING,
  8. sizeof(char) * 64,
  9. "Network",
  10. "Name",
  11. "-n",
  12. &IZ_NET_SERVER_DEFAULT_STATE.config.name,
  13. NULL,
  14. {
  15. .serialize = NULL,
  16. .deserialize = NULL,
  17. },
  18. NULL,
  19. },
  20. {
  21. IZ_CONFIG_TYPE_STRING,
  22. sizeof(char) * 128,
  23. "Network",
  24. "Motd",
  25. "-m",
  26. &IZ_NET_SERVER_DEFAULT_STATE.config.motd,
  27. NULL,
  28. {
  29. .serialize = NULL,
  30. .deserialize = NULL,
  31. },
  32. NULL,
  33. },
  34. {
  35. IZ_CONFIG_TYPE_U16,
  36. sizeof(u16),
  37. "Network",
  38. "Port",
  39. "-p",
  40. &IZ_NET_SERVER_DEFAULT_STATE.config.port,
  41. IZ_NetServerIsValidPort,
  42. {
  43. .serialize = NULL,
  44. .deserialize = NULL,
  45. },
  46. NULL,
  47. },
  48. IZ_CONFIG_ITEM_NULL,
  49. };
  50. void IZ_NetServerBindStateToConfig(IZ_NetServerState* state, IZ_ConfigItem config_items[]) {
  51. config_items[0].dest = &state->config.name;
  52. config_items[1].dest = &state->config.motd;
  53. config_items[2].dest = &state->config.port;
  54. }
  55. IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState* state, const char* config_path) {
  56. IZ_NetServerBindStateToConfig(state, net_server_config_items);
  57. return IZ_ConfigSave(net_server_config_items, config_path);
  58. }
  59. IZ_ProcedureResult IZ_NetServerInitializeConfig(
  60. IZ_NetServerState* state,
  61. const char* config_path,
  62. u8 argc,
  63. const char* argv[]
  64. ) {
  65. IZ_NetServerBindStateToConfig(state, net_server_config_items);
  66. if (IZ_ConfigInitialize(net_server_config_items, config_path, argc, argv) < 0) {
  67. return -1;
  68. }
  69. return 0;
  70. }
  71. IZ_ProcedureResult IZ_NetServerInitialize(
  72. IZ_NetServerState* state,
  73. void* user_data,
  74. const char* config_path,
  75. u8 argc,
  76. const char* argv[]
  77. ) {
  78. if (!user_data) {
  79. return -1;
  80. }
  81. memcpy_s(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState));
  82. if (IZ_NetServerInitializeConfig(state, config_path, argc, argv) < 0) {
  83. return -2;
  84. }
  85. state->binding.user_data = user_data;
  86. return 0;
  87. }
  88. void IZ_NetServerCancelService(IZ_NetServerState* state) {
  89. IZ_WSServerCancelService(&state->binding);
  90. }