Add subdirectories for grouping net-related functions.feature/data-structs
@@ -75,14 +75,14 @@ add_executable( | |||||
src/packages/game/input/IZ_midi.h | src/packages/game/input/IZ_midi.h | ||||
src/packages/game/data/IZ_list.c | src/packages/game/data/IZ_list.c | ||||
src/packages/game/data/IZ_list.h | src/packages/game/data/IZ_list.h | ||||
src/packages/game/network/IZ_wsclient.c | |||||
src/packages/game/network/IZ_wsclient.h | |||||
src/packages/game/net/svc/IZ_wsclient.c | |||||
src/packages/game/net/svc/IZ_wsclient.h | |||||
src/packages/game/log/IZ_log.c | src/packages/game/log/IZ_log.c | ||||
src/packages/game/log/IZ_log.h | src/packages/game/log/IZ_log.h | ||||
src/packages/game/util/IZ_midi.c | src/packages/game/util/IZ_midi.c | ||||
src/packages/game/util/IZ_midi.h | src/packages/game/util/IZ_midi.h | ||||
src/packages/game/network/IZ_websocket.h | |||||
src/packages/game/network/IZ_websocket.c | |||||
src/packages/game/net/core/IZ_websocket.h | |||||
src/packages/game/net/core/IZ_websocket.c | |||||
) | ) | ||||
target_link_libraries( | target_link_libraries( | ||||
@@ -193,10 +193,10 @@ add_executable( | |||||
src/packages/server/IZ_app.h | src/packages/server/IZ_app.h | ||||
src/packages/server/IZ_config.c | src/packages/server/IZ_config.c | ||||
src/packages/server/IZ_config.h | src/packages/server/IZ_config.h | ||||
src/packages/server/network/IZ_wsserver.c | |||||
src/packages/server/network/IZ_wsserver.h | |||||
src/packages/server/network/IZ_websocket.h | |||||
src/packages/server/network/IZ_websocket.c | |||||
src/packages/server/net/svc/IZ_wsserver.c | |||||
src/packages/server/net/svc/IZ_wsserver.h | |||||
src/packages/server/net/core/IZ_websocket.h | |||||
src/packages/server/net/core/IZ_websocket.c | |||||
) | ) | ||||
target_link_libraries( | target_link_libraries( | ||||
@@ -6,7 +6,7 @@ | |||||
#include "input/IZ_input.h" | #include "input/IZ_input.h" | ||||
#include "output/IZ_video.h" | #include "output/IZ_video.h" | ||||
#include "memory/IZ_pool.h" | #include "memory/IZ_pool.h" | ||||
#include "network/IZ_wsclient.h" | |||||
#include "net/svc/IZ_wsclient.h" | |||||
typedef enum { | typedef enum { | ||||
IZ_APP_RUN_RESULT_OK, | IZ_APP_RUN_RESULT_OK, | ||||
@@ -1,8 +1,8 @@ | |||||
#ifndef IZ_WEBSOCKET_H | #ifndef IZ_WEBSOCKET_H | ||||
#define IZ_WEBSOCKET_H | #define IZ_WEBSOCKET_H | ||||
#include <libwebsockets.h> | |||||
#include "../IZ_common.h" | |||||
#include "libwebsockets.h" | |||||
#include "../../IZ_common.h" | |||||
#define NETWORK_PROTOCOL "izanagi-networking" | #define NETWORK_PROTOCOL "izanagi-networking" | ||||
#define RING_COUNT 32 | #define RING_COUNT 32 |
@@ -1,9 +1,9 @@ | |||||
#ifndef IZ_WSCLIENT_H | #ifndef IZ_WSCLIENT_H | ||||
#define IZ_WSCLIENT_H | #define IZ_WSCLIENT_H | ||||
#include <libwebsockets.h> | |||||
#include "../IZ_common.h" | |||||
#include "IZ_websocket.h" | |||||
#include "libwebsockets.h" | |||||
#include "../../IZ_common.h" | |||||
#include "../core/IZ_websocket.h" | |||||
typedef struct { | typedef struct { | ||||
struct lws_context *context; | struct lws_context *context; |
@@ -3,7 +3,7 @@ | |||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include "network/IZ_wsserver.h" | |||||
#include "net/svc/IZ_wsserver.h" | |||||
#include "log/IZ_log.h" | #include "log/IZ_log.h" | ||||
#include "IZ_common.h" | #include "IZ_common.h" | ||||
#include "IZ_config.h" | #include "IZ_config.h" | ||||
@@ -0,0 +1 @@ | |||||
../../game/net/core |
@@ -44,12 +44,21 @@ void IZ_WSServerLoadConfig(IZ_WSServerState* state, const char* config_path, u8 | |||||
} | } | ||||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) { | if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) { | ||||
sprintf_s(state->config.server_name, 64, "%s Dedicated Server [%s]", IZ_APP_NAME, cmdline_buffer); | |||||
} else { | |||||
sprintf_s(state->config.server_name, 128, "%s Dedicated Server", IZ_APP_NAME); | |||||
memcpy_s(state->config.server_name, 64, cmdline_buffer, 64); | |||||
} | } | ||||
} | } | ||||
const char* IZ_WSServerTestPath(const char* base_dir, const char* file) { | |||||
static char test_path[32]; | |||||
sprintf_s(test_path, 32, "%s/%s", base_dir, file); | |||||
struct stat stats; | |||||
stat(test_path, &stats); | |||||
if (stats.st_mode & S_IREAD) { | |||||
return file; | |||||
} | |||||
return NULL; | |||||
} | |||||
IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata, const char* config_path, u8 argc, const char* argv[]) { | IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata, const char* config_path, u8 argc, const char* argv[]) { | ||||
IZ_WSServerLoadConfig(state, config_path, argc, argv); | IZ_WSServerLoadConfig(state, config_path, argc, argv); | ||||
state->userdata = userdata; | state->userdata = userdata; | ||||
@@ -57,9 +66,15 @@ IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata | |||||
struct lws_context_creation_info info; | struct lws_context_creation_info info; | ||||
memset(&info, 0, sizeof info); | memset(&info, 0, sizeof info); | ||||
info.port = state->config.port; | info.port = state->config.port; | ||||
// char server_string[64]; | |||||
// if (*state->config.server_name) { | |||||
// sprintf_s(server_string, 64, "%s Dedicated Server [%s]", IZ_APP_NAME, state->config.server_name); | |||||
// } else { | |||||
// sprintf_s(server_string, 64, "%s Dedicated Server", IZ_APP_NAME, state->config.server_name); | |||||
// } | |||||
// info.server_string = server_string; | |||||
const char* origin = "./public"; | const char* origin = "./public"; | ||||
struct stat stats; | struct stat stats; | ||||
stat(origin, &stats); | stat(origin, &stats); | ||||
if (S_ISDIR(stats.st_mode)) { | if (S_ISDIR(stats.st_mode)) { | ||||
@@ -67,7 +82,7 @@ IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata | |||||
.mount_next = NULL, /* linked-list "next" */ | .mount_next = NULL, /* linked-list "next" */ | ||||
.mountpoint = "/", /* mountpoint URL */ | .mountpoint = "/", /* mountpoint URL */ | ||||
.origin = NULL, /* serve from dir */ | .origin = NULL, /* serve from dir */ | ||||
.def = "index.html", /* default filename */ | |||||
.def = "index.htm", /* default filename */ | |||||
.protocol = "http", | .protocol = "http", | ||||
.cgienv = NULL, | .cgienv = NULL, | ||||
.extra_mimetypes = NULL, | .extra_mimetypes = NULL, | ||||
@@ -83,6 +98,19 @@ IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata | |||||
.basic_auth_login_file = NULL, | .basic_auth_login_file = NULL, | ||||
}; | }; | ||||
mount.origin = origin; | mount.origin = origin; | ||||
const char* (alt_test_paths[]) = { | |||||
"index.html", | |||||
}; | |||||
const char* default_filename; | |||||
u8 i; | |||||
for (i = 0; i < 1; i += 1) { | |||||
default_filename = IZ_WSServerTestPath(origin, alt_test_paths[i]); | |||||
} | |||||
if (default_filename) { | |||||
mount.def = default_filename; | |||||
} | |||||
info.mounts = &mount; | info.mounts = &mount; | ||||
} | } | ||||
@@ -2,11 +2,11 @@ | |||||
#define IZ_WSSERVER_H | #define IZ_WSSERVER_H | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <libwebsockets.h> | |||||
#include "libwebsockets.h" | |||||
#include <string.h> | #include <string.h> | ||||
#include "../IZ_common.h" | |||||
#include "../IZ_config.h" | |||||
#include "IZ_websocket.h" | |||||
#include "../../IZ_common.h" | |||||
#include "../../IZ_config.h" | |||||
#include "../core/IZ_websocket.h" | |||||
#ifndef S_ISDIR | #ifndef S_ISDIR | ||||
#define S_ISDIR(s) s & S_IFDIR | #define S_ISDIR(s) s & S_IFDIR | ||||
@@ -33,7 +33,7 @@ typedef struct { | |||||
typedef struct { | typedef struct { | ||||
u16 port; | u16 port; | ||||
const char server_name[64]; | |||||
char server_name[64]; | |||||
} IZ_WSServerInitializeParams; | } IZ_WSServerInitializeParams; | ||||
typedef struct { | typedef struct { |
@@ -1 +0,0 @@ | |||||
../../game/network/IZ_websocket.c |
@@ -1 +0,0 @@ | |||||
../../game/network/IZ_websocket.h |