Bladeren bron

Extract common code

Remove symlinks and make codebase use common modules instead.
feature/data-structs
TheoryOfNekomata 2 jaren geleden
bovenliggende
commit
9cde8ff876
57 gewijzigde bestanden met toevoegingen van 297 en 307 verwijderingen
  1. +28
    -22
      CMakeLists.txt
  2. +1
    -1
      __mocks__/SDL_joystick.mock.h
  3. +1
    -1
      __mocks__/SDL_keyboard.mock.h
  4. +1
    -1
      __mocks__/SDL_render.mock.h
  5. +1
    -1
      __mocks__/SDL_stdinc.mock.h
  6. +1
    -1
      __mocks__/minIni.mock.h
  7. +1
    -1
      __mocks__/portmidi.mock.h
  8. +6
    -6
      docs/reference/files/config-server.ini
  9. +0
    -0
      src/packages/common/IZ_common.h
  10. +2
    -2
      src/packages/config/IZ_config.c
  11. +4
    -4
      src/packages/config/IZ_config.h
  12. +3
    -3
      src/packages/game/IZ_app.c
  13. +2
    -2
      src/packages/game/IZ_app.h
  14. +2
    -2
      src/packages/game/IZ_app_config.h
  15. +4
    -4
      src/packages/game/IZ_app_input.c
  16. +13
    -13
      src/packages/game/IZ_app_net.c
  17. +0
    -1
      src/packages/game/IZ_app_net.h
  18. +5
    -5
      src/packages/game/IZ_app_video.c
  19. +3
    -3
      src/packages/game/IZ_subsystem.h
  20. +1
    -1
      src/packages/game/core/IZ_creature.h
  21. +1
    -1
      src/packages/game/data/IZ_list.h
  22. +1
    -1
      src/packages/game/data/data.test.c
  23. +1
    -1
      src/packages/game/geometry/IZ_point2d.h
  24. +1
    -1
      src/packages/game/input/IZ_action.h
  25. +1
    -1
      src/packages/game/input/IZ_input.c
  26. +1
    -1
      src/packages/game/input/IZ_input.h
  27. +1
    -1
      src/packages/game/input/IZ_joystick.h
  28. +1
    -1
      src/packages/game/input/IZ_keyboard.h
  29. +1
    -1
      src/packages/game/input/IZ_midi.h
  30. +1
    -1
      src/packages/game/memory/IZ_pool.h
  31. +0
    -75
      src/packages/game/net/IZ_net.h
  32. +4
    -4
      src/packages/game/output/video/IZ_video.h
  33. +1
    -1
      src/packages/game/util/IZ_midi.h
  34. +0
    -0
      src/packages/log/IZ_log.c
  35. +3
    -3
      src/packages/log/IZ_log.h
  36. +27
    -27
      src/packages/net/IZ_net_client.c
  37. +74
    -0
      src/packages/net/IZ_net_client.h
  38. +12
    -9
      src/packages/net/IZ_net_server.c
  39. +43
    -0
      src/packages/net/IZ_net_server.h
  40. +0
    -0
      src/packages/net/core/IZ_websocket.c
  41. +3
    -1
      src/packages/net/core/IZ_websocket.h
  42. +0
    -0
      src/packages/net/svc/IZ_wsclient.c
  43. +3
    -1
      src/packages/net/svc/IZ_wsclient.h
  44. +0
    -0
      src/packages/net/svc/IZ_wsserver.c
  45. +1
    -1
      src/packages/net/svc/IZ_wsserver.h
  46. +1
    -1
      src/packages/server/IZ_app.c
  47. +6
    -7
      src/packages/server/IZ_app.h
  48. +12
    -0
      src/packages/server/IZ_app_config.c
  49. +8
    -0
      src/packages/server/IZ_app_config.h
  50. +0
    -1
      src/packages/server/IZ_common.h
  51. +0
    -31
      src/packages/server/IZ_config.c
  52. +0
    -13
      src/packages/server/IZ_config.h
  53. +4
    -0
      src/packages/server/IZ_subsystem.h
  54. +6
    -6
      src/packages/server/db/IZ_repo.h
  55. +0
    -1
      src/packages/server/log
  56. +0
    -40
      src/packages/server/net/IZ_net.h
  57. +0
    -1
      src/packages/server/net/core

+ 28
- 22
CMakeLists.txt Bestand weergeven

@@ -51,7 +51,7 @@ add_executable(
dependencies/getopt-for-windows/getopt.c
src/packages/game/output/video/IZ_video.h
src/packages/game/output/video/IZ_video.c
src/packages/game/IZ_common.h
src/packages/common/IZ_common.h
src/packages/game/input/IZ_action.h
src/packages/game/IZ_app.h
src/packages/game/IZ_app.c
@@ -60,8 +60,8 @@ add_executable(
src/packages/game/input/IZ_joystick.h
src/packages/game/input/IZ_keyboard.c
src/packages/game/input/IZ_keyboard.h
src/packages/game/config/IZ_config.c
src/packages/game/config/IZ_config.h
src/packages/config/IZ_config.c
src/packages/config/IZ_config.h
src/packages/game/geometry/IZ_point2d.c
src/packages/game/geometry/IZ_point2d.h
src/packages/game/geometry/IZ_vector2d.c
@@ -82,15 +82,15 @@ 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/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/net/svc/IZ_wsclient.c
src/packages/net/svc/IZ_wsclient.h
src/packages/log/IZ_log.c
src/packages/log/IZ_log.h
src/packages/game/util/IZ_midi.c
src/packages/game/util/IZ_midi.h
src/packages/game/net/core/IZ_websocket.h
src/packages/game/net/core/IZ_websocket.c
src/packages/game/net/IZ_net.c src/packages/game/net/IZ_net.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h)
src/packages/net/core/IZ_websocket.h
src/packages/net/core/IZ_websocket.c
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h)

target_link_libraries(
game
@@ -130,7 +130,7 @@ add_executable(
__mocks__/SDL_stdinc.mock.h
__mocks__/portmidi.mock.h

src/packages/game/config/IZ_config.h
src/packages/config/IZ_config.h

src/packages/game/input/IZ_keyboard.h
src/packages/game/input/IZ_keyboard.c
@@ -157,7 +157,7 @@ add_executable(
__mocks__/SDL_stdinc.mock.h
__mocks__/SDL_render.mock.h

src/packages/game/config/IZ_config.h
src/packages/config/IZ_config.h

src/packages/game/output/video/IZ_video.h
src/packages/game/output/video/IZ_video.c
@@ -194,19 +194,25 @@ add_executable(
dependencies/sqlite/sqlite3.c
dependencies/minIni/dev/minIni.h
dependencies/minIni/dev/minIni.c
src/packages/server/IZ_common.h
src/packages/server/log/IZ_log.h
src/packages/server/log/IZ_log.c
src/packages/log/IZ_log.h
src/packages/log/IZ_log.c
src/packages/server/main.c
src/packages/server/IZ_app.c
src/packages/server/IZ_app.h
src/packages/server/IZ_config.c
src/packages/server/IZ_config.h
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
src/packages/server/net/IZ_net.c src/packages/server/net/IZ_net.h src/packages/server/db/IZ_repo.c src/packages/server/db/IZ_repo.h)
src/packages/server/IZ_app_config.h
src/packages/server/IZ_app_config.c
src/packages/net/svc/IZ_wsserver.c
src/packages/net/svc/IZ_wsserver.h
src/packages/net/core/IZ_websocket.h
src/packages/net/core/IZ_websocket.c
src/packages/config/IZ_config.h
src/packages/config/IZ_config.c
src/packages/net/IZ_net_server.c
src/packages/net/IZ_net_server.h
src/packages/server/db/IZ_repo.c
src/packages/server/db/IZ_repo.h
src/packages/server/IZ_subsystem.h
)

target_link_libraries(
server


+ 1
- 1
__mocks__/SDL_joystick.mock.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef SDL_JOYSTICK_MOCK_H
#define SDL_JOYSTICK_MOCK_H

#include "../src/packages/game/IZ_common.h"
#include "../src/packages/common/IZ_common.h"
#include "../src/packages/test/IZ_test.h"

typedef struct _SDL_Joystick {} SDL_Joystick;


+ 1
- 1
__mocks__/SDL_keyboard.mock.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef SDL_KEYBOARD_MOCK_H
#define SDL_KEYBOARD_MOCK_H

#include "../src/packages/game/IZ_common.h"
#include "../src/packages/common/IZ_common.h"
#include "../src/packages/test/IZ_test.h"

mock(SDL_GetKeyName) const char* SDL_GetKeyName(i32 key) {


+ 1
- 1
__mocks__/SDL_render.mock.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef SDL_RENDER_MOCK_H
#define SDL_RENDER_MOCK_H

#include "../src/packages/game/IZ_common.h"
#include "../src/packages/common/IZ_common.h"
#include "../src/packages/test/IZ_test.h"

typedef struct SDL_Renderer SDL_Renderer;


+ 1
- 1
__mocks__/SDL_stdinc.mock.h Bestand weergeven

@@ -2,7 +2,7 @@
#define SDL_STDINC_MOCK_H

#include <string.h>
#include "../src/packages/game/IZ_common.h"
#include "../src/packages/common/IZ_common.h"
#include "../src/packages/test/IZ_test.h"

mock(SDL_memcpy) void* SDL_memcpy(void* dst, const void* src, size_t len) {


+ 1
- 1
__mocks__/minIni.mock.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef MININI_MOCK_H
#define MININI_MOCK_H

#include "../src/packages/game/IZ_common.h"
#include "../src/packages/common/IZ_common.h"
#include "../src/packages/test/IZ_test.h"

mock(ini_getl) long ini_getl(const char *Section, const char *Key, long DefValue, const char *Filename) {


+ 1
- 1
__mocks__/portmidi.mock.h Bestand weergeven

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

#define PORTMIDI_INCLUDED

#include "../src/packages/game/IZ_common.h"
#include "../src/packages/common/IZ_common.h"

typedef i32 PmDeviceID;
typedef void PortMidiStream;


+ 6
- 6
docs/reference/files/config-server.ini Bestand weergeven

@@ -1,6 +1,6 @@
[Network]
Name=Izanagi
Motd=
Port=42069
[Database]
Path=db.sqlite
[Network]
Name=Izanagi Server
Motd=
Port=42069
[Database]
Path=server.sqlite

src/packages/game/IZ_common.h → src/packages/common/IZ_common.h Bestand weergeven


src/packages/game/config/IZ_config.c → src/packages/config/IZ_config.c Bestand weergeven

@@ -29,7 +29,7 @@ typedef bool IZ_ConfigLoadParamsU16Validator(u16);

typedef bool IZ_ConfigLoadParamsU8Validator(u8);

void IZ_ConfigEnsureValidString(IZ_ConfigItem item, char* buffer) {
void IZ_ConfigEnsureValidString(IZ_ConfigItem item, const char* buffer) {
char dest[item.dest_size];
if (item.validator) {
IZ_ConfigLoadParamsStringValidator* validator = item.validator;
@@ -48,7 +48,7 @@ void IZ_ConfigEnsureValidString(IZ_ConfigItem item, char* buffer) {

void IZ_ConfigLoadString(IZ_ConfigItem item, const char* config_path) {
char buffer[item.dest_size];
ini_gets(item.section, item.key, item.default_value, buffer, item.dest_size, config_path);
ini_gets(item.section, item.key, item.default_value, buffer, (i32) item.dest_size, config_path);
IZ_ConfigEnsureValidString(item, buffer);
}


src/packages/game/config/IZ_config.h → src/packages/config/IZ_config.h Bestand weergeven

@@ -1,10 +1,10 @@
#ifndef IZ_CONFIG_H
#define IZ_CONFIG_H

#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <minIni.h>
#include "../IZ_common.h"
#include "../common/IZ_common.h"

typedef enum {
IZ_CONFIG_TYPE_VOID,
@@ -26,9 +26,9 @@ typedef struct {

void IZ_ConfigGetDefaultPath(const char*, size_t);

const char* IZ_ConfigGetCommandlineOption(u8, const char**, const char*);
const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*);

void IZ_ConfigInit(IZ_ConfigItem[], const char*, u8, const char**);
void IZ_ConfigInit(IZ_ConfigItem[], const char*, u8, const char*[]);

IZ_ProcedureResult IZ_ConfigSave(IZ_ConfigItem[], const char*);


+ 3
- 3
src/packages/game/IZ_app.c Bestand weergeven

@@ -8,7 +8,7 @@ void IZ_AppBindConnection(struct IZ_App* app, struct lws* wsi) {
app->net_state.binding.connection = wsi;
}

IZ_NetState* IZ_AppGetNetState(struct IZ_App* app) {
IZ_NetClientState* IZ_AppGetNetState(struct IZ_App* app) {
return &app->net_state;
}

@@ -47,7 +47,7 @@ IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* arg
return IZ_APP_RUN_INPUT_INIT_ERROR;
}

if (IZ_NetInitialize(&app->net_state, app, IZ_AppRunNetworkingThread, config_path, argc, argv)) {
if (IZ_NetClientInitialize(&app->net_state, app, IZ_AppRunNetworkingThread, config_path, argc, argv)) {
return IZ_APP_RUN_NETWORKING_ERROR;
}

@@ -58,7 +58,7 @@ IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* arg
}

void IZ_AppTeardown(struct IZ_App* app) {
IZ_NetDisconnect(&app->net_state);
IZ_NetClientDisconnect(&app->net_state);
IZ_PoolTeardown(&app->pool);
IZ_InputTeardown(&app->input_state);
IZ_VideoTeardown(&app->video_state);


+ 2
- 2
src/packages/game/IZ_app.h Bestand weergeven

@@ -24,9 +24,9 @@ typedef struct IZ_App {
IZ_Pool pool;

u64 ticks;
IZ_NetState net_state;
IZ_NetClientState net_state;
} IZ_App;

IZ_ProcedureResult IZ_AppRun(struct IZ_App*, u8, const char**);
IZ_ProcedureResult IZ_AppRun(struct IZ_App*, u8, const char*[]);

#endif

+ 2
- 2
src/packages/game/IZ_app_config.h Bestand weergeven

@@ -1,8 +1,8 @@
#ifndef IZ_APP_CONFIG_H
#define IZ_APP_CONFIG_H

#include "SDL_filesystem.h"
#include <SDL_filesystem.h>
#include "IZ_subsystem.h"
#include "config/IZ_config.h"
#include "../config/IZ_config.h"

#endif

+ 4
- 4
src/packages/game/IZ_app_input.c Bestand weergeven

@@ -3,7 +3,7 @@
IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) {
SDL_Event e;
IZ_InputState* input_state = IZ_AppGetInputState(app);
IZ_NetState* net_state = IZ_AppGetNetState(app);
IZ_NetClientState* net_state = IZ_AppGetNetState(app);

while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
@@ -12,7 +12,7 @@ IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) {

if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_PAGEUP) {
IZ_NetConnect(
IZ_NetClientConnect(
net_state,
(IZ_WSClientInitializeParams) {
.host = "127.0.0.1",
@@ -21,9 +21,9 @@ IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) {
}
);
} else if (e.key.keysym.sym == SDLK_PAGEDOWN) {
IZ_NetDisconnect(net_state);
IZ_NetClientDisconnect(net_state);
} else if (e.key.keysym.sym == SDLK_INSERT) {
IZ_NetSendTextMessage(net_state, "hello", 5);
IZ_NetClientSendTextMessage(net_state, "hello", 5);
}
}



+ 13
- 13
src/packages/game/IZ_app_net.c Bestand weergeven

@@ -16,7 +16,7 @@ void IZ_AppHandleNetworkingInboundTextEvents(struct IZ_App* app, const char* tex

void IZ_AppHandleOutboundNetworking(struct IZ_App* app) {
// TODO implement queueing of messages
IZ_NetState* net_state = IZ_AppGetNetState(app);
IZ_NetClientState* net_state = IZ_AppGetNetState(app);
IZ_InputState* input_state = IZ_AppGetInputState(app);

u8 player_index;
@@ -34,7 +34,7 @@ void IZ_AppHandleOutboundNetworking(struct IZ_App* app) {
msg->action.player[0].index = player_index;
msg->action.player[0].value = input_state->action[player_index];
msg->action.player[0].state = 0;
IZ_NetSendBinaryMessage(
IZ_NetClientSendBinaryMessage(
net_state,
msg,
sizeof(*msg)
@@ -60,8 +60,8 @@ void IZ_WSClientAttemptConnect(struct lws_sorted_usec_list *sul) {
vhd->i.pwsi = &vhd->client_wsi;

struct IZ_App* app = (struct IZ_App*) vhd->app;
IZ_NetState* net_state = IZ_AppGetNetState(app);
net_state->status = IZ_NET_STATUS_CONNECTING;
IZ_NetClientState* net_state = IZ_AppGetNetState(app);
net_state->status = IZ_NET_CLIENT_STATUS_CONNECTING;
if (lws_client_connect_via_info(&vhd->i)) {
return;
}
@@ -124,8 +124,8 @@ void IZ_WSClientProtocolTeardown(struct lws* wsi) {

lws_sul_cancel(&vhd->sul);
struct IZ_App* app = (struct IZ_App*) vhd->app;
IZ_NetState* net_state = IZ_AppGetNetState(app);
net_state->status = IZ_NET_STATUS_PRISTINE;
IZ_NetClientState* net_state = IZ_AppGetNetState(app);
net_state->status = IZ_NET_CLIENT_STATUS_PRISTINE;
}

IZ_ProcedureResult IZ_WSClientConnectionError(struct lws* wsi, void* in) {
@@ -142,13 +142,13 @@ IZ_ProcedureResult IZ_WSClientConnectionError(struct lws* wsi, void* in) {
struct IZ_App* app = (struct IZ_App*) vhd->app;
IZ_AppBindConnection(app, NULL);
vhd->client_wsi = NULL;
IZ_NetState* net_state = IZ_AppGetNetState(app);
IZ_NetClientState* net_state = IZ_AppGetNetState(app);
if (net_state->retries == net_state->config.max_reconnect_retries) {
lwsl_err("Max number of retries reached!\n");
net_state->status = IZ_NET_STATUS_PRISTINE;
net_state->status = IZ_NET_CLIENT_STATUS_PRISTINE;
return -1;
}
net_state->status = IZ_NET_STATUS_ERROR;
net_state->status = IZ_NET_CLIENT_STATUS_ERROR;
net_state->retries += 1;
lws_sul_schedule(
vhd->context,
@@ -167,15 +167,15 @@ IZ_ProcedureResult IZ_WSClientOnOpen(struct lws* wsi, IZ_WSClientSessionData* ps
lws_get_protocol(wsi)
);
struct IZ_App* app = (struct IZ_App*) vhd->app;
IZ_NetState* net_state = IZ_AppGetNetState(app);
IZ_NetClientState* net_state = IZ_AppGetNetState(app);
pss->ring = lws_ring_create(sizeof(IZ_WebsocketMessage), RING_COUNT,IZ_WebsocketDestroyMessage);
if (!pss->ring) {
net_state->status = IZ_NET_STATUS_ERROR;
net_state->status = IZ_NET_CLIENT_STATUS_ERROR;
return -1;
}

IZ_AppBindConnection(app, wsi);
net_state->status = IZ_NET_STATUS_CONNECTED;
net_state->status = IZ_NET_CLIENT_STATUS_CONNECTED;
net_state->retries = 0;
pss->tail = 0;
return 0;
@@ -287,7 +287,7 @@ void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in
}

IZ_ProcedureResult IZ_AppRunNetworkingThread(struct IZ_App* app) {
IZ_NetState* net_state = IZ_AppGetNetState(app);
IZ_NetClientState* net_state = IZ_AppGetNetState(app);

if (IZ_WSClientInitialize(&net_state->binding, net_state->params)) {
return -1;


+ 0
- 1
src/packages/game/IZ_app_net.h Bestand weergeven

@@ -1,7 +1,6 @@
#ifndef IZ_APP_NET_H
#define IZ_APP_NET_H

#include "net/IZ_net.h"
#include "IZ_subsystem.h"

typedef enum {


+ 5
- 5
src/packages/game/IZ_app_video.c Bestand weergeven

@@ -52,19 +52,19 @@ void IZ_VideoUpdateForDebugInput(IZ_VideoState* video_state, IZ_InputState* inpu
}
}

void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetState* net_state) {
void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetClientState* net_state) {
const u8 size = 4;

switch (net_state->status) {
default:
return;
case IZ_NET_STATUS_ERROR:
case IZ_NET_CLIENT_STATUS_ERROR:
SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0x00, 0x00, 0xff);
break;
case IZ_NET_STATUS_CONNECTING:
case IZ_NET_CLIENT_STATUS_CONNECTING:
SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0xff, 0x00, 0xff);
break;
case IZ_NET_STATUS_CONNECTED:
case IZ_NET_CLIENT_STATUS_CONNECTED:
SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0xff, 0x00, 0xff);
break;
}
@@ -108,7 +108,7 @@ void IZ_VideoUpdate(IZ_VideoState* video_state) {
struct IZ_App* app = video_state->user_data;
u64 ticks = IZ_AppGetTicks(app);
IZ_InputState* input_state = IZ_AppGetInputState(app);
IZ_NetState* net_state = IZ_AppGetNetState(app);
IZ_NetClientState* net_state = IZ_AppGetNetState(app);

if (ticks - video_state->last_update_at > 1000 / video_state->config.max_fps) {
// Update window


+ 3
- 3
src/packages/game/IZ_subsystem.h Bestand weergeven

@@ -1,15 +1,15 @@
#ifndef IZ_SUBSYSTEM_H
#define IZ_SUBSYSTEM_H

#include "IZ_common.h"
#include "net/IZ_net.h"
#include "../common/IZ_common.h"
#include "../net/IZ_net_client.h"
#include "input/IZ_input.h"

struct IZ_App;

u64 IZ_AppGetTicks(struct IZ_App*);

IZ_NetState* IZ_AppGetNetState(struct IZ_App*);
IZ_NetClientState* IZ_AppGetNetState(struct IZ_App*);

IZ_InputState* IZ_AppGetInputState(struct IZ_App*);



+ 1
- 1
src/packages/game/core/IZ_creature.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef IZ_CREATURE_H
#define IZ_CREATURE_H

#include "../IZ_common.h"
#include "../../common/IZ_common.h"
#include "IZ_object.h"

typedef struct {


+ 1
- 1
src/packages/game/data/IZ_list.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef IZ_LIST_H
#define IZ_LIST_H

#include "../IZ_common.h"
#include "../../common/IZ_common.h"
#include "SDL_stdinc.h"

typedef struct IZ_ListNode {


+ 1
- 1
src/packages/game/data/data.test.c Bestand weergeven

@@ -1,5 +1,5 @@
#include "../../test/IZ_test.h"
#include "../../game/IZ_common.h"
#include "../../common/IZ_common.h"
#include "../../../__mocks__/SDL_stdinc.mock.h"
#include "IZ_list.h"



+ 1
- 1
src/packages/game/geometry/IZ_point2d.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef IZ_POINT2D_H
#define IZ_POINT2D_H

#include "../IZ_common.h"
#include "../../common/IZ_common.h"

typedef struct {
f32 x;


+ 1
- 1
src/packages/game/input/IZ_action.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef IZ_ACTION_H
#define IZ_ACTION_H

#include "../IZ_common.h"
#include "../../common/IZ_common.h"

#define CONTROLS (unsigned char) 16



+ 1
- 1
src/packages/game/input/IZ_input.c Bestand weergeven

@@ -9,7 +9,7 @@ void IZ_InputHandlePortMIDIEvents(IZ_InputState* state, PmEvent e) {
IZ_MIDIInputHandleEvents(&state->midi_input_state, &state->action, e);
}

IZ_ProcedureResult IZ_InputInitialize(IZ_InputState* state, const char* config_path, u8 argc, const char** argv) {
IZ_ProcedureResult IZ_InputInitialize(IZ_InputState* state, const char* config_path, u8 argc, const char* argv[]) {
*state = (IZ_InputState) {
.action = {},
.joystick_state = {},


+ 1
- 1
src/packages/game/input/IZ_input.h Bestand weergeven

@@ -17,7 +17,7 @@ void IZ_InputHandleSDLEvents(IZ_InputState*, SDL_Event);

void IZ_InputHandlePortMIDIEvents(IZ_InputState*, PmEvent);

IZ_ProcedureResult IZ_InputInitialize(IZ_InputState*, const char*, u8, const char**);
IZ_ProcedureResult IZ_InputInitialize(IZ_InputState*, const char*, u8, const char*[]);

void IZ_InputTeardown(IZ_InputState*);



+ 1
- 1
src/packages/game/input/IZ_joystick.h Bestand weergeven

@@ -86,7 +86,7 @@ IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(*)[IZ_PLAYERS], const

void IZ_JoystickHandleEvents(IZ_JoystickState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event);

IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[IZ_PLAYERS], const char*, u8, const char**);
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[IZ_PLAYERS], const char*, u8, const char*[]);

void IZ_JoystickTeardown(IZ_JoystickState(*)[IZ_PLAYERS]);



+ 1
- 1
src/packages/game/input/IZ_keyboard.h Bestand weergeven

@@ -66,6 +66,6 @@ IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(*)[IZ_PLAYERS], const

void IZ_KeyboardHandleEvents(IZ_KeyboardState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event);

IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(*)[IZ_PLAYERS], const char*, u8, const char**);
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(*)[IZ_PLAYERS], const char*, u8, const char*[]);

#endif

+ 1
- 1
src/packages/game/input/IZ_midi.h Bestand weergeven

@@ -90,7 +90,7 @@ IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(*)[IZ_PLAYERS], cons

void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], PmEvent);

IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(*)[IZ_PLAYERS], const char*, u8, const char**);
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(*)[IZ_PLAYERS], const char*, u8, const char*[]);

void IZ_MIDIInputTeardown(IZ_MIDIInputState(*)[IZ_PLAYERS]);



+ 1
- 1
src/packages/game/memory/IZ_pool.h Bestand weergeven

@@ -2,7 +2,7 @@
#define IZ_POOL_H

#include <SDL_stdinc.h>
#include "../IZ_common.h"
#include "../../common/IZ_common.h"
#include "../data/IZ_list.h"

#define POOL_MAX_SIZE (1llu << 23) // 16MB


+ 0
- 75
src/packages/game/net/IZ_net.h Bestand weergeven

@@ -1,75 +0,0 @@
#ifndef IZ_NET_H
#define IZ_NET_H

#include <minIni.h>
#include <SDL_thread.h>
#include "../IZ_common.h"
#include "../config/IZ_config.h"
#include "../input/IZ_action.h"
#include "core/IZ_websocket.h"
#include "svc/IZ_wsclient.h"

typedef enum {
IZ_NET_STATUS_PRISTINE,
IZ_NET_STATUS_CONNECTING,
IZ_NET_STATUS_ERROR,
IZ_NET_STATUS_CONNECTED,
} IZ_NetStatus;

typedef struct {
u16 packet_interval_ms;
u8 max_reconnect_retries;
u8 reconnect_interval_secs;
char username[32];
} IZ_NetConfig;

typedef struct {
SDL_Thread* client_thread;
IZ_NetConfig config;
IZ_Websocket binding;
IZ_WSClientInitializeParams params;
void* callback;
IZ_Action action[IZ_PLAYERS];
u8 retries;
IZ_NetStatus status;
// TODO add message queue
} IZ_NetState;

static IZ_NetState IZ_NET_DEFAULT_STATE = {
.client_thread = NULL,
.config = {
.packet_interval_ms = 200,
.max_reconnect_retries = 3,
.reconnect_interval_secs = 3,
.username = "Player",
},
.binding = {
.interrupted = false,
.context = NULL,
.connection = NULL,
.user_data = NULL,
},
.params = {
.port = 42069,
.path = "/",
.host = "localhost",
},
.callback = NULL,
.action = {},
.retries = 3,
.status = IZ_NET_STATUS_PRISTINE,
};

IZ_ProcedureResult IZ_NetInitialize(IZ_NetState*, void*, void*, const char*, u8, const char**);

void IZ_NetConnect(IZ_NetState*, IZ_WSClientInitializeParams);

void IZ_NetDisconnect(IZ_NetState*);

IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState*, const char*);

void IZ_NetSendBinaryMessage(IZ_NetState*, void*, size_t);

void IZ_NetSendTextMessage(IZ_NetState*, char*, size_t);

#endif

+ 4
- 4
src/packages/game/output/video/IZ_video.h Bestand weergeven

@@ -5,10 +5,10 @@
#include "minIni.h"
#include "SDL_render.h"

#include "../../../net/IZ_net_client.h"
#include "../../../config/IZ_config.h"
#include "../../input/IZ_input.h"
#include "../../net/IZ_net.h"
#include "../../IZ_common.h"
#include "../../config/IZ_config.h"
#include "../../../common/IZ_common.h"

#define MAX_ACTIVE_SPRITES 32

@@ -43,7 +43,7 @@ static const IZ_VideoState IZ_VIDEO_DEFAULT_STATE = {
.active_sprites = {},
};

IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, void*, const char*, u8, const char**);
IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, void*, const char*, u8, const char*[]);

IZ_ProcedureResult IZ_VideoSaveConfig(IZ_VideoState*, const char*);



+ 1
- 1
src/packages/game/util/IZ_midi.h Bestand weergeven

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

#include <stdio.h>
#include <string.h>
#include "../IZ_common.h"
#include "../../common/IZ_common.h"

typedef u8 IZ_MIDINote;



src/packages/game/log/IZ_log.c → src/packages/log/IZ_log.c Bestand weergeven


src/packages/game/log/IZ_log.h → src/packages/log/IZ_log.h Bestand weergeven

@@ -1,9 +1,9 @@
#ifndef IZ_LOG_H
#define IZ_LOG_H

#include <SDL_log.h>
#include <libwebsockets.h>
#include "../IZ_common.h"
#include "SDL_log.h"
#include "libwebsockets.h"
#include "../common/IZ_common.h"

void IZ_LogInterceptWSMessages(i32);


src/packages/game/net/IZ_net.c → src/packages/net/IZ_net_client.c Bestand weergeven

@@ -1,14 +1,14 @@
#include "IZ_net.h"
#include "IZ_net_client.h"

bool IZ_NetIsValidPacketIntervalMs(long packet_interval_ms) {
bool IZ_NetClientIsValidPacketIntervalMs(long packet_interval_ms) {
return (100 <= packet_interval_ms && packet_interval_ms <= 500);
}

bool IZ_NetIsValidMaxReconnectRetries(long max_reconnect_retries) {
bool IZ_NetClientIsValidMaxReconnectRetries(long max_reconnect_retries) {
return (0 <= max_reconnect_retries && max_reconnect_retries <= 8);
}

bool IZ_NetIsValidReconnectIntervalSeconds(long reconnect_interval_secs) {
bool IZ_NetClientIsValidReconnectIntervalSeconds(long reconnect_interval_secs) {
return (3 <= reconnect_interval_secs && reconnect_interval_secs <= 10);
}

@@ -19,7 +19,7 @@ static IZ_ConfigItem net_config_items[] = {
"Network",
"Username",
NULL,
&IZ_NET_DEFAULT_STATE.config.username,
&IZ_NET_CLIENT_DEFAULT_STATE.config.username,
NULL
},
{
@@ -28,8 +28,8 @@ static IZ_ConfigItem net_config_items[] = {
"Network",
"PacketIntervalMs",
"-i",
&IZ_NET_DEFAULT_STATE.config.packet_interval_ms,
IZ_NetIsValidPacketIntervalMs,
&IZ_NET_CLIENT_DEFAULT_STATE.config.packet_interval_ms,
IZ_NetClientIsValidPacketIntervalMs,
},
{
IZ_CONFIG_TYPE_U8,
@@ -37,8 +37,8 @@ static IZ_ConfigItem net_config_items[] = {
"Network",
"MaxReconnectRetries",
NULL,
&IZ_NET_DEFAULT_STATE.config.max_reconnect_retries,
IZ_NetIsValidMaxReconnectRetries,
&IZ_NET_CLIENT_DEFAULT_STATE.config.max_reconnect_retries,
IZ_NetClientIsValidMaxReconnectRetries,
},
{
IZ_CONFIG_TYPE_U8,
@@ -46,33 +46,33 @@ static IZ_ConfigItem net_config_items[] = {
"Network",
"ReconnectIntervalSeconds",
NULL,
&IZ_NET_DEFAULT_STATE.config.reconnect_interval_secs,
IZ_NetIsValidReconnectIntervalSeconds,
&IZ_NET_CLIENT_DEFAULT_STATE.config.reconnect_interval_secs,
IZ_NetClientIsValidReconnectIntervalSeconds,
},
};

void IZ_NetBindStateToConfig(IZ_NetState* state, IZ_ConfigItem config_items[]) {
void IZ_NetClientBindStateToConfig(IZ_NetClientState* state, IZ_ConfigItem config_items[]) {
config_items[0].dest = &state->config.username;
config_items[1].dest = &state->config.packet_interval_ms;
config_items[2].dest = &state->config.max_reconnect_retries;
config_items[3].dest = &state->config.reconnect_interval_secs;
}

IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path) {
IZ_NetBindStateToConfig(state, net_config_items);
IZ_ProcedureResult IZ_NetClientSaveConfig(IZ_NetClientState* state, const char* config_path) {
IZ_NetClientBindStateToConfig(state, net_config_items);
return IZ_ConfigSave(net_config_items, config_path);
}

IZ_ProcedureResult IZ_NetInitialize(
IZ_NetState* state,
IZ_ProcedureResult IZ_NetClientInitialize(
IZ_NetClientState* state,
void* user_data,
void* callback,
const char* config_path,
u8 argc,
const char* argv[]
) {
memcpy_s(state, sizeof(IZ_NetState), &IZ_NET_DEFAULT_STATE, sizeof(IZ_NetState));
IZ_NetBindStateToConfig(state, net_config_items);
memcpy_s(state, sizeof(IZ_NetClientState), &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState));
IZ_NetClientBindStateToConfig(state, net_config_items);
IZ_ConfigInit(net_config_items, config_path, argc, argv);
if (!user_data) {
return -2;
@@ -88,16 +88,16 @@ IZ_ProcedureResult IZ_NetInitialize(
return 0;
}

void IZ_NetConnect(IZ_NetState* state, IZ_WSClientInitializeParams params) {
void IZ_NetClientConnect(IZ_NetClientState* state, IZ_WSClientInitializeParams params) {
if (!state->callback) {
return;
}

if (state->status == IZ_NET_STATUS_CONNECTED) {
if (state->status == IZ_NET_CLIENT_STATUS_CONNECTED) {
return;
}

if (state->status == IZ_NET_STATUS_CONNECTING) {
if (state->status == IZ_NET_CLIENT_STATUS_CONNECTING) {
return;
}

@@ -111,8 +111,8 @@ void IZ_NetConnect(IZ_NetState* state, IZ_WSClientInitializeParams params) {
SDL_DetachThread(state->client_thread);
}

void IZ_NetDisconnect(IZ_NetState* state) {
if (state->status == IZ_NET_STATUS_PRISTINE) {
void IZ_NetClientDisconnect(IZ_NetClientState* state) {
if (state->status == IZ_NET_CLIENT_STATUS_PRISTINE) {
return;
}
if (state->binding.connection) {
@@ -128,8 +128,8 @@ void IZ_NetDisconnect(IZ_NetState* state) {
IZ_WSClientCancelService(&state->binding);
}

void IZ_NetSendBinaryMessage(IZ_NetState* state, void* in, size_t len) {
if (state->status != IZ_NET_STATUS_CONNECTED) {
void IZ_NetClientSendBinaryMessage(IZ_NetClientState* state, void* in, size_t len) {
if (state->status != IZ_NET_CLIENT_STATUS_CONNECTED) {
return;
}

@@ -150,8 +150,8 @@ void IZ_NetSendBinaryMessage(IZ_NetState* state, void* in, size_t len) {
lws_callback_on_writable(state->binding.connection);
}

void IZ_NetSendTextMessage(IZ_NetState* state, char* in, size_t len) {
if (state->status != IZ_NET_STATUS_CONNECTED) {
void IZ_NetClientSendTextMessage(IZ_NetClientState* state, char* in, size_t len) {
if (state->status != IZ_NET_CLIENT_STATUS_CONNECTED) {
return;
}


+ 74
- 0
src/packages/net/IZ_net_client.h Bestand weergeven

@@ -0,0 +1,74 @@
#ifndef IZ_NET_CLIENT_H
#define IZ_NET_CLIENT_H

#include "minIni.h"
#include "SDL_thread.h"
#include "../config/IZ_config.h"
#include "../common/IZ_common.h"
#include "../game/input/IZ_action.h"
#include "svc/IZ_wsclient.h"

typedef enum {
IZ_NET_CLIENT_STATUS_PRISTINE,
IZ_NET_CLIENT_STATUS_CONNECTING,
IZ_NET_CLIENT_STATUS_ERROR,
IZ_NET_CLIENT_STATUS_CONNECTED,
} IZ_NetClientStatus;

typedef struct {
u16 packet_interval_ms;
u8 max_reconnect_retries;
u8 reconnect_interval_secs;
char username[32];
} IZ_NetClientConfig;

typedef struct {
SDL_Thread* client_thread;
IZ_NetClientConfig config;
IZ_NetBinding binding;
IZ_NetInitializeParams params;
void* callback;
IZ_Action action[IZ_PLAYERS];
u8 retries;
IZ_NetClientStatus status;
// TODO add message queue
} IZ_NetClientState;

static IZ_NetClientState IZ_NET_CLIENT_DEFAULT_STATE = {
.client_thread = NULL,
.config = {
.packet_interval_ms = 200,
.max_reconnect_retries = 3,
.reconnect_interval_secs = 3,
.username = "Player",
},
.binding = {
.interrupted = false,
.context = NULL,
.connection = NULL,
.user_data = NULL,
},
.params = {
.port = 42069,
.path = "/",
.host = "localhost",
},
.callback = NULL,
.action = {},
.retries = 3,
.status = IZ_NET_CLIENT_STATUS_PRISTINE,
};

IZ_ProcedureResult IZ_NetClientInitialize(IZ_NetClientState*, void*, void*, const char *, u8, const char *[]);

void IZ_NetClientConnect(IZ_NetClientState*, IZ_WSClientInitializeParams);

void IZ_NetClientDisconnect(IZ_NetClientState*);

IZ_ProcedureResult IZ_NetClientSaveConfig(IZ_NetClientState*, const char*);

void IZ_NetClientSendBinaryMessage(IZ_NetClientState*, void*, size_t);

void IZ_NetClientSendTextMessage(IZ_NetClientState*, char*, size_t);

#endif

src/packages/server/net/IZ_net.c → src/packages/net/IZ_net_server.c Bestand weergeven

@@ -1,18 +1,18 @@
#include "IZ_net.h"
#include "IZ_net_server.h"

void IZ_NetLoadConfig(IZ_NetState* state, const char* config_path) {
void IZ_NetLoadConfig(IZ_NetServerState* state, const char* config_path) {
char buffer[128];

ini_gets("Network", "Name", IZ_NET_DEFAULT_STATE.config.name, buffer, 128, config_path);
ini_gets("Network", "Name", IZ_NET_SERVER_DEFAULT_STATE.config.name, buffer, 128, config_path);
memcpy_s(state->config.name, 64, buffer, 64);

ini_gets("Network", "Motd", IZ_NET_DEFAULT_STATE.config.motd, buffer, 128, config_path);
ini_gets("Network", "Motd", IZ_NET_SERVER_DEFAULT_STATE.config.motd, buffer, 128, config_path);
memcpy_s(state->config.motd, 128, buffer, 128);

state->config.port = ini_getl("Network", "Port", IZ_NET_DEFAULT_STATE.config.port, config_path);
state->config.port = ini_getl("Network", "Port", IZ_NET_SERVER_DEFAULT_STATE.config.port, config_path);
}

IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path) {
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState* state, const char* config_path) {
if (!ini_puts("Network", "Name", state->config.name, config_path)) {
return -1;
}
@@ -28,7 +28,7 @@ IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path)
return 0;
}

void IZ_NetOverrideConfig(IZ_NetState* state, u8 argc, const char* argv[]) {
void IZ_NetOverrideConfig(IZ_NetServerState* state, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
char* rest_of_string;
u16 port;
@@ -49,7 +49,7 @@ void IZ_NetOverrideConfig(IZ_NetState* state, u8 argc, const char* argv[]) {
}

IZ_ProcedureResult IZ_NetInitialize(
IZ_NetState* state,
IZ_NetServerState* state,
void* user_data,
const char* config_path,
u8 argc,
@@ -58,7 +58,7 @@ IZ_ProcedureResult IZ_NetInitialize(
if (!user_data) {
return -1;
}
memcpy_s(state, sizeof(IZ_NetState), &IZ_NET_DEFAULT_STATE, sizeof(IZ_NetState));
memcpy_s(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState));
IZ_NetLoadConfig(state, config_path);
if (IZ_NetSaveConfig(state, config_path) < 0) {
return -2;
@@ -68,3 +68,6 @@ IZ_ProcedureResult IZ_NetInitialize(
return 0;
}

void IZ_NetServerCancelService(IZ_NetServerState* state) {
IZ_WSServerCancelService(&state->ws);
}

+ 43
- 0
src/packages/net/IZ_net_server.h Bestand weergeven

@@ -0,0 +1,43 @@
#ifndef IZ_NET_SERVER_H
#define IZ_NET_SERVER_H

#include <minIni.h>
#include "../config/IZ_config.h"
#include "../common/IZ_common.h"
#include "core/IZ_websocket.h"
#include "svc/IZ_wsserver.h"

#define IZ_DEFAULT_MOTD ""

typedef struct {
u16 port;
char name[64];
char motd[128];
} IZ_NetServerConfig;

typedef struct {
IZ_NetServerConfig config;
IZ_NetBinding ws;
} IZ_NetServerState;

static IZ_NetServerState IZ_NET_SERVER_DEFAULT_STATE = {
.config = {
.port = 42069,
.name = IZ_APP_NAME " Server",
.motd = IZ_DEFAULT_MOTD,
},
.ws = {
.interrupted = false,
.context = NULL,
.connection = NULL,
.user_data = NULL,
},
};

IZ_ProcedureResult IZ_NetInitialize(IZ_NetServerState*, void*, const char*, u8, const char*[]);

IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState*, const char*);

void IZ_NetServerCancelService(IZ_NetServerState*);

#endif

src/packages/game/net/core/IZ_websocket.c → src/packages/net/core/IZ_websocket.c Bestand weergeven


src/packages/game/net/core/IZ_websocket.h → src/packages/net/core/IZ_websocket.h Bestand weergeven

@@ -2,7 +2,7 @@
#define IZ_WEBSOCKET_H

#include "libwebsockets.h"
#include "../../IZ_common.h"
#include "../../common/IZ_common.h"

#define NETWORK_PROTOCOL "izanagi-networking"
#define RING_COUNT 32
@@ -23,6 +23,8 @@ typedef struct {
u8 interrupted: 1;
} IZ_Websocket;

typedef IZ_Websocket IZ_NetBinding;

void IZ_WebsocketInitialize(IZ_Websocket*);

IZ_ProcedureResult IZ_WebsocketHandle(IZ_Websocket*);

src/packages/game/net/svc/IZ_wsclient.c → src/packages/net/svc/IZ_wsclient.c Bestand weergeven


src/packages/game/net/svc/IZ_wsclient.h → src/packages/net/svc/IZ_wsclient.h Bestand weergeven

@@ -1,7 +1,7 @@
#ifndef IZ_WSCLIENT_H
#define IZ_WSCLIENT_H

#include "../../IZ_common.h"
#include "../../common/IZ_common.h"
#include "../core/IZ_websocket.h"

typedef struct {
@@ -35,6 +35,8 @@ typedef struct {
u16 port;
} IZ_WSClientInitializeParams;

typedef IZ_WSClientInitializeParams IZ_NetInitializeParams;

IZ_ProcedureResult IZ_WSClientInitialize(IZ_Websocket*, IZ_WSClientInitializeParams);

IZ_ProcedureResult IZ_WSClientHandle(IZ_Websocket*);

src/packages/server/net/svc/IZ_wsserver.c → src/packages/net/svc/IZ_wsserver.c Bestand weergeven


src/packages/server/net/svc/IZ_wsserver.h → src/packages/net/svc/IZ_wsserver.h Bestand weergeven

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

#include <sys/stat.h>
#include <string.h>
#include "../../IZ_common.h"
#include "../../common/IZ_common.h"
#include "../core/IZ_websocket.h"

#ifndef S_ISDIR

+ 1
- 1
src/packages/server/IZ_app.c Bestand weergeven

@@ -4,7 +4,7 @@ static IZ_App* global_app;

void IZ_AppHandleSignal(i32 _signal) {
global_app->net_state.ws.interrupted = true;
IZ_WSServerCancelService(&global_app->net_state.ws);
IZ_NetServerCancelService(&global_app->net_state);
}

IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) {


+ 6
- 7
src/packages/server/IZ_app.h Bestand weergeven

@@ -3,18 +3,17 @@

#include <signal.h>
#include <stdbool.h>
#include "net/svc/IZ_wsserver.h"
#include "log/IZ_log.h"
#include "IZ_common.h"
#include "IZ_config.h"
#include "net/IZ_net.h"
#include "../common/IZ_common.h"
#include "../net/IZ_net_server.h"
#include "../log/IZ_log.h"
#include "db/IZ_repo.h"
#include "IZ_app_config.h"

typedef struct {
IZ_NetState net_state;
IZ_NetServerState net_state;
IZ_RepoState repo_state;
} IZ_App;

IZ_ProcedureResult IZ_AppRun(IZ_App*, u8, const char**);
IZ_ProcedureResult IZ_AppRun(IZ_App*, u8, const char*[]);

#endif

+ 12
- 0
src/packages/server/IZ_app_config.c Bestand weergeven

@@ -0,0 +1,12 @@
#include "IZ_app_config.h"

void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) {
#ifdef IZ_DEBUG
const char* config_path_dir = SDL_GetBasePath();
#else
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME);
#endif

memcpy_s(config_path, string_size, config_path_dir, 128);
strcat_s(config_path, string_size, "config-server.ini");
}

+ 8
- 0
src/packages/server/IZ_app_config.h Bestand weergeven

@@ -0,0 +1,8 @@
#ifndef IZ_APP_CONFIG_H
#define IZ_APP_CONFIG_H

#include <SDL_filesystem.h>
#include "../config/IZ_config.h"
#include "IZ_subsystem.h"

#endif

+ 0
- 1
src/packages/server/IZ_common.h Bestand weergeven

@@ -1 +0,0 @@
../game/IZ_common.h

+ 0
- 31
src/packages/server/IZ_config.c Bestand weergeven

@@ -1,31 +0,0 @@
#include "IZ_config.h"

void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) {
//const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME);
const char* config_path_dir = SDL_GetBasePath();
memcpy_s(config_path, string_size, config_path_dir, 128);
strcat_s(config_path, string_size, "config-server.ini");
}

const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) {
size_t n = strlen(val);
int c = argc;

while (--c > 0) {

if (!strncmp(argv[c], val, n)) {
if (!*(argv[c] + n) && c < argc - 1) {
/* coverity treats unchecked argv as "tainted" */
if (!argv[c + 1] || strlen(argv[c + 1]) > 1024)
return NULL;
return argv[c + 1];
}

if (argv[c][n] == '=')
return &argv[c][n + 1];
return argv[c] + n;
}
}

return NULL;
}

+ 0
- 13
src/packages/server/IZ_config.h Bestand weergeven

@@ -1,13 +0,0 @@
#ifndef IZ_CONFIG_H
#define IZ_CONFIG_H

#include <SDL_filesystem.h>
#include <string.h>
#include "IZ_common.h"

// TODO unify loading of config from cmdline and config file
void IZ_ConfigGetDefaultPath(const char*, size_t);

const char* IZ_ConfigGetCommandlineOption(u8, const char**, const char*);

#endif

+ 4
- 0
src/packages/server/IZ_subsystem.h Bestand weergeven

@@ -0,0 +1,4 @@
#ifndef IZ_SUBSYSTEM_H
#define IZ_SUBSYSTEM_H

#endif

+ 6
- 6
src/packages/server/db/IZ_repo.h Bestand weergeven

@@ -1,11 +1,11 @@
#ifndef IZ_REPO_H
#define IZ_REPO_H

#include "minIni.h"
#include "sqlite3.h"
#include <minIni.h>
#include <sqlite3.h>
#include <string.h>
#include "../IZ_common.h"
#include "../IZ_config.h"
#include "../../common/IZ_common.h"
#include "../../config/IZ_config.h"

typedef struct {
char path[64];
@@ -18,12 +18,12 @@ typedef struct {

static IZ_RepoState IZ_REPO_DEFAULT_STATE = {
.config = {
.path = "db.sqlite",
.path = "server.sqlite",
},
.db = NULL,
};

IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState*, const char*, u8, const char**);
IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState*, const char*, u8, const char*[]);

void IZ_RepoTeardown(IZ_RepoState*);



+ 0
- 1
src/packages/server/log Bestand weergeven

@@ -1 +0,0 @@
../game/log

+ 0
- 40
src/packages/server/net/IZ_net.h Bestand weergeven

@@ -1,40 +0,0 @@
#ifndef IZ_NET_H
#define IZ_NET_H

#include <minIni.h>
#include "../IZ_common.h"
#include "../IZ_config.h"
#include "core/IZ_websocket.h"

#define IZ_DEFAULT_MOTD ""

typedef struct {
u16 port;
char name[64];
char motd[128];
} IZ_NetConfig;

typedef struct {
IZ_NetConfig config;
IZ_Websocket ws;
} IZ_NetState;

static IZ_NetState IZ_NET_DEFAULT_STATE = {
.config = {
.port = 42069,
.name = IZ_APP_NAME " Server",
.motd = IZ_DEFAULT_MOTD,
},
.ws = {
.interrupted = false,
.context = NULL,
.connection = NULL,
.user_data = NULL,
},
};

IZ_ProcedureResult IZ_NetInitialize(IZ_NetState*, void*, const char*, u8, const char**);

IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState*, const char*);

#endif

+ 0
- 1
src/packages/server/net/core Bestand weergeven

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

Laden…
Annuleren
Opslaan