Browse Source

Refactor directory structure

Add subdirectories for grouping net-related functions.
feature/data-structs
TheoryOfNekomata 2 years ago
parent
commit
c1f6d92cc8
12 changed files with 54 additions and 27 deletions
  1. +8
    -8
      CMakeLists.txt
  2. +1
    -1
      src/packages/game/IZ_app.h
  3. +0
    -0
      src/packages/game/net/core/IZ_websocket.c
  4. +2
    -2
      src/packages/game/net/core/IZ_websocket.h
  5. +0
    -0
      src/packages/game/net/svc/IZ_wsclient.c
  6. +3
    -3
      src/packages/game/net/svc/IZ_wsclient.h
  7. +1
    -1
      src/packages/server/IZ_app.h
  8. +1
    -0
      src/packages/server/net/core
  9. +33
    -5
      src/packages/server/net/svc/IZ_wsserver.c
  10. +5
    -5
      src/packages/server/net/svc/IZ_wsserver.h
  11. +0
    -1
      src/packages/server/network/IZ_websocket.c
  12. +0
    -1
      src/packages/server/network/IZ_websocket.h

+ 8
- 8
CMakeLists.txt View File

@@ -75,14 +75,14 @@ add_executable(
src/packages/game/input/IZ_midi.h
src/packages/game/data/IZ_list.c
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.h
src/packages/game/util/IZ_midi.c
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(
@@ -193,10 +193,10 @@ add_executable(
src/packages/server/IZ_app.h
src/packages/server/IZ_config.c
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(


+ 1
- 1
src/packages/game/IZ_app.h View File

@@ -6,7 +6,7 @@
#include "input/IZ_input.h"
#include "output/IZ_video.h"
#include "memory/IZ_pool.h"
#include "network/IZ_wsclient.h"
#include "net/svc/IZ_wsclient.h"

typedef enum {
IZ_APP_RUN_RESULT_OK,


src/packages/game/network/IZ_websocket.c → src/packages/game/net/core/IZ_websocket.c View File


src/packages/game/network/IZ_websocket.h → src/packages/game/net/core/IZ_websocket.h View File

@@ -1,8 +1,8 @@
#ifndef 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 RING_COUNT 32

src/packages/game/network/IZ_wsclient.c → src/packages/game/net/svc/IZ_wsclient.c View File


src/packages/game/network/IZ_wsclient.h → src/packages/game/net/svc/IZ_wsclient.h View File

@@ -1,9 +1,9 @@
#ifndef 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 {
struct lws_context *context;

+ 1
- 1
src/packages/server/IZ_app.h View File

@@ -3,7 +3,7 @@

#include <signal.h>
#include <stdbool.h>
#include "network/IZ_wsserver.h"
#include "net/svc/IZ_wsserver.h"
#include "log/IZ_log.h"
#include "IZ_common.h"
#include "IZ_config.h"


+ 1
- 0
src/packages/server/net/core View File

@@ -0,0 +1 @@
../../game/net/core

src/packages/server/network/IZ_wsserver.c → src/packages/server/net/svc/IZ_wsserver.c View File

@@ -44,12 +44,21 @@ void IZ_WSServerLoadConfig(IZ_WSServerState* state, const char* config_path, u8
}

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_WSServerLoadConfig(state, config_path, argc, argv);
state->userdata = userdata;
@@ -57,9 +66,15 @@ IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata
struct lws_context_creation_info info;
memset(&info, 0, sizeof info);
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";

struct stat stats;
stat(origin, &stats);
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" */
.mountpoint = "/", /* mountpoint URL */
.origin = NULL, /* serve from dir */
.def = "index.html", /* default filename */
.def = "index.htm", /* default filename */
.protocol = "http",
.cgienv = NULL,
.extra_mimetypes = NULL,
@@ -83,6 +98,19 @@ IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata
.basic_auth_login_file = NULL,
};
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;
}


src/packages/server/network/IZ_wsserver.h → src/packages/server/net/svc/IZ_wsserver.h View File

@@ -2,11 +2,11 @@
#define IZ_WSSERVER_H

#include <sys/stat.h>
#include <libwebsockets.h>
#include "libwebsockets.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
#define S_ISDIR(s) s & S_IFDIR
@@ -33,7 +33,7 @@ typedef struct {

typedef struct {
u16 port;
const char server_name[64];
char server_name[64];
} IZ_WSServerInitializeParams;

typedef struct {

+ 0
- 1
src/packages/server/network/IZ_websocket.c View File

@@ -1 +0,0 @@
../../game/network/IZ_websocket.c

+ 0
- 1
src/packages/server/network/IZ_websocket.h View File

@@ -1 +0,0 @@
../../game/network/IZ_websocket.h

Loading…
Cancel
Save