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.
 
 
 
 
 
 

74 lines
2.1 KiB

  1. #include "IZ_net_server.h"
  2. void IZ_NetLoadConfig(IZ_NetServerState* state, const char* config_path) {
  3. char buffer[128];
  4. ini_gets("Network", "Name", IZ_NET_SERVER_DEFAULT_STATE.config.name, buffer, 128, config_path);
  5. memcpy_s(state->config.name, 64, buffer, 64);
  6. ini_gets("Network", "Motd", IZ_NET_SERVER_DEFAULT_STATE.config.motd, buffer, 128, config_path);
  7. memcpy_s(state->config.motd, 128, buffer, 128);
  8. state->config.port = ini_getl("Network", "Port", IZ_NET_SERVER_DEFAULT_STATE.config.port, config_path);
  9. }
  10. IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState* state, const char* config_path) {
  11. if (!ini_puts("Network", "Name", state->config.name, config_path)) {
  12. return -1;
  13. }
  14. if (!ini_puts("Network", "Motd", state->config.motd, config_path)) {
  15. return -1;
  16. }
  17. if (!ini_putl("Network", "Port", state->config.port, config_path)) {
  18. return -1;
  19. }
  20. return 0;
  21. }
  22. void IZ_NetOverrideConfig(IZ_NetServerState* state, u8 argc, const char* argv[]) {
  23. const char* cmdline_buffer;
  24. char* rest_of_string;
  25. u16 port;
  26. if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-p"))) {
  27. port = strtol(cmdline_buffer, &rest_of_string, 10);
  28. if (strcmp(cmdline_buffer, rest_of_string) != 0) {
  29. state->config.port = port;
  30. }
  31. }
  32. if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) {
  33. memcpy_s(state->config.name, 64, cmdline_buffer, 64);
  34. }
  35. if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-m"))) {
  36. memcpy_s(state->config.motd, 128, cmdline_buffer, 128);
  37. }
  38. }
  39. IZ_ProcedureResult IZ_NetInitialize(
  40. IZ_NetServerState* state,
  41. void* user_data,
  42. const char* config_path,
  43. u8 argc,
  44. const char* argv[]
  45. ) {
  46. if (!user_data) {
  47. return -1;
  48. }
  49. memcpy_s(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState));
  50. IZ_NetLoadConfig(state, config_path);
  51. if (IZ_NetSaveConfig(state, config_path) < 0) {
  52. return -2;
  53. }
  54. IZ_NetOverrideConfig(state, argc, argv);
  55. state->ws.user_data = user_data;
  56. return 0;
  57. }
  58. void IZ_NetServerCancelService(IZ_NetServerState* state) {
  59. IZ_WSServerCancelService(&state->ws);
  60. }