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.
 
 
 
 
 
 

65 lines
1.7 KiB

  1. #include "IZ_net.h"
  2. void IZ_NetLoadConfig(IZ_NetState* state, const char* config_path) {
  3. char buffer[128];
  4. ini_gets("Network", "Name", IZ_APP_NAME, buffer, 128, config_path);
  5. memcpy_s(state->config.name, 64, buffer, 64);
  6. ini_gets("Network", "Motd", "", buffer, 128, config_path);
  7. memcpy_s(state->config.motd, 128, buffer, 128);
  8. state->config.port = ini_getl("Network", "Port", IZ_NET_DEFAULT_STATE.config.port, config_path);
  9. }
  10. IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* 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_NetState* state, u8 argc, const char* argv[]) {
  23. const char* cmdline_buffer;
  24. if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-p"))) {
  25. state->config.port = atoi(cmdline_buffer);
  26. }
  27. if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) {
  28. memcpy_s(state->config.name, 64, cmdline_buffer, 128);
  29. }
  30. if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-m"))) {
  31. memcpy_s(state->config.motd, 128, cmdline_buffer, 128);
  32. }
  33. }
  34. IZ_ProcedureResult IZ_NetInitialize(
  35. IZ_NetState* state,
  36. void* user_data,
  37. const char* config_path,
  38. u8 argc,
  39. const char* argv[]
  40. ) {
  41. memcpy_s(state, sizeof(IZ_NetState), &IZ_NET_DEFAULT_STATE, sizeof(IZ_NetState));
  42. IZ_NetLoadConfig(state, config_path);
  43. if (IZ_NetSaveConfig(state, config_path) < 0) {
  44. return -1;
  45. }
  46. IZ_NetOverrideConfig(state, argc, argv);
  47. if (!user_data) {
  48. return -2;
  49. }
  50. state->ws.user_data = user_data;
  51. return 0;
  52. }