Explorar el Código

Update server

Ensure mounts are configurable.
feature/data-structs
TheoryOfNekomata hace 2 años
padre
commit
e80c557d63
Se han modificado 8 ficheros con 88 adiciones y 54 borrados
  1. +1
    -0
      src/packages/game/IZ_config.h
  2. +0
    -1
      src/packages/game/input/IZ_midi.c
  3. +0
    -2
      src/packages/game/memory/memory.test.c
  4. +6
    -0
      src/packages/game/output/IZ_video.c
  5. +8
    -2
      src/packages/game/output/IZ_video.h
  6. +7
    -1
      src/packages/server/IZ_app.c
  7. +58
    -47
      src/packages/server/network/IZ_wsserver.c
  8. +8
    -1
      src/packages/server/network/IZ_wsserver.h

+ 1
- 0
src/packages/game/IZ_config.h Ver fichero

@@ -4,6 +4,7 @@
#include <SDL_filesystem.h>
#include <string.h>

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

#endif

+ 0
- 1
src/packages/game/input/IZ_midi.c Ver fichero

@@ -181,7 +181,6 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(const char* config_path, IZ_MIDIInputS
}

u8 player_index;
// TODO Pm_CountDevices(), only filter input devices
u8 midi_devices_count = Pm_CountDevices();
u8 input_midi_devices_count = 0;
u8 device_index;


+ 0
- 2
src/packages/game/memory/memory.test.c Ver fichero

@@ -62,8 +62,6 @@ spec("memory") {

it("assigns contiguous memory") {
IZ_PoolInitialize(&pool, POOL_MAX_SIZE);

// FIXME: access violation error
void* p1 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){
.size = sizeof(struct DummyStruct),
.priority = 0,


+ 6
- 0
src/packages/game/output/IZ_video.c Ver fichero

@@ -108,6 +108,12 @@ void IZ_VideoUpdate(IZ_VideoState* video_state, u64 ticks, IZ_InputState* input_
// Update window
SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0x00, 0x00, 0xff);
SDL_RenderClear(video_state->renderer);
for (u8 i = 0; i < MAX_ACTIVE_SPRITES; i += 1) {
if (!video_state->active_sprites[i]) {
continue;
}
// TODO draw sprites
}
IZ_VideoUpdateForDebug(video_state, input_state, ticks);
SDL_RenderPresent(video_state->renderer);
video_state->last_update_at = ticks;


+ 8
- 2
src/packages/game/output/IZ_video.h Ver fichero

@@ -5,11 +5,15 @@
#include <minIni.h>
#include <SDL_render.h>

// TODO move this out from video, refer to app's state instead
#include "../input/IZ_input.h"
#include "../IZ_common.h"
#include "../IZ_config.h"

#define MAX_ACTIVE_SPRITES 32

// TODO properly define sprites
typedef char IZ_Sprite;

typedef struct {
u16 width;
u16 height;
@@ -18,9 +22,10 @@ typedef struct {

typedef struct {
IZ_VideoConfig config;
uint64_t last_update_at;
u64 last_update_at;
SDL_Window* window;
SDL_Renderer* renderer;
IZ_Sprite active_sprites[MAX_ACTIVE_SPRITES];
} IZ_VideoState;

static const IZ_VideoState IZ_DEFAULT_VIDEO_STATE = {
@@ -32,6 +37,7 @@ static const IZ_VideoState IZ_DEFAULT_VIDEO_STATE = {
.last_update_at = 0,
.renderer = NULL,
.window = NULL,
.active_sprites = {},
};

IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, const char*);


+ 7
- 1
src/packages/server/IZ_app.c Ver fichero

@@ -22,10 +22,16 @@ void IZ_AppLoadConfig(IZ_App *app, u8 argc, const char **argv) {
IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) {
interrupted = false;
signal(SIGINT, IZ_AppHandleSignal);
//signal(SIGTERM, IZ_AppHandleSignal);

IZ_AppLoadConfig(app, argc, argv);
IZ_LogInterceptWSMessages(app->config.log_level);
if (IZ_WSServerCreateContext(&app->context, app->config.port)) {
if (IZ_WSServerCreateContext(&app->context, (IZ_WSServerCreateContextParams) {
.protocol = NULL,
.port = app->config.port,
.default_filename = NULL,
.origin = NULL,
})) {
return 1;
}



+ 58
- 47
src/packages/server/network/IZ_wsserver.c Ver fichero

@@ -1,47 +1,5 @@
#include "IZ_wsserver.h"

static struct lws_protocols protocols[] = {
{
.name = NETWORK_PROTOCOL,
.callback = IZ_WSServerCallback,
.per_session_data_size = sizeof(IZ_WSServerSessionData),
.rx_buffer_size = 0,
.id = 0,
.user = NULL,
.tx_packet_size = 0,
},
{
.name = "http",
.callback = lws_callback_http_dummy,
.per_session_data_size = 0,
.rx_buffer_size = 0,
.id = 0,
.user = NULL,
.tx_packet_size = 0,
},
LWS_PROTOCOL_LIST_TERM,
};

static const struct lws_http_mount mount = {
.mount_next = NULL, /* linked-list "next" */
.mountpoint = "/", /* mountpoint URL */
.origin = "./mount-origin", /* serve from dir */
.def = "index.html", /* default filename */
.protocol = NULL,
.cgienv = NULL,
.extra_mimetypes = NULL,
.interpret = NULL,
.cgi_timeout = 0,
.cache_max_age = 0,
.auth_mask = 0,
.cache_reusable = 0,
.cache_revalidate = 0,
.cache_intermediaries = 0,
.origin_protocol = LWSMPRO_FILE, /* files in a dir */
.mountpoint_len = 1, /* char count */
.basic_auth_login_file = NULL,
};

static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) {
u32 oldest_tail = lws_ring_get_oldest_tail(vhd->ring);
IZ_WSServerSessionData *old_pss = NULL;
@@ -135,8 +93,8 @@ static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) {

/* destroys the message when everyone has had a copy of it */

void IZ_ProtocolDestroyMessage(void *_msg) {
IZ_WSServerMessage *msg = _msg;
void IZ_ProtocolDestroyMessage(void* msg_raw) {
IZ_WSServerMessage *msg = msg_raw;

free(msg->payload);
msg->payload = NULL;
@@ -324,13 +282,66 @@ i32 IZ_WSServerCallback(
return 0;
}

IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context** context, u16 port) {
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context** context, IZ_WSServerCreateContextParams params) {
struct lws_context_creation_info info;
memset(&info, 0, sizeof info);
info.port = port;
info.port = params.port;

static struct lws_http_mount mount = {
.mount_next = NULL, /* linked-list "next" */
.mountpoint = "/", /* mountpoint URL */
.origin = "./public", /* serve from dir */
.def = "index.html", /* default filename */
.protocol = "http",
.cgienv = NULL,
.extra_mimetypes = NULL,
.interpret = NULL,
.cgi_timeout = 0,
.cache_max_age = 0,
.auth_mask = 0,
.cache_reusable = 0,
.cache_revalidate = 0,
.cache_intermediaries = 0,
.origin_protocol = LWSMPRO_FILE, /* files in a dir */
.mountpoint_len = 1, /* char count */
.basic_auth_login_file = NULL,
};

if (params.origin) {
mount.origin = params.origin;
}

if (params.default_filename) {
mount.def = params.default_filename;
}

if (params.protocol) {
mount.protocol = params.protocol;
}
info.mounts = &mount;

static const struct lws_protocols protocols[] = {
{
.name = NETWORK_PROTOCOL,
.callback = IZ_WSServerCallback,
.per_session_data_size = sizeof(IZ_WSServerSessionData),
.rx_buffer_size = 0,
.id = 0,
.user = NULL,
.tx_packet_size = 0,
},
{
.name = "http",
.callback = lws_callback_http_dummy,
.per_session_data_size = 0,
.rx_buffer_size = 0,
.id = 0,
.user = NULL,
.tx_packet_size = 0,
},
LWS_PROTOCOL_LIST_TERM,
};
info.protocols = protocols;
// TODO initialize protocols
info.options = (
LWS_SERVER_OPTION_VALIDATE_UTF8
| LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE


+ 8
- 1
src/packages/server/network/IZ_wsserver.h Ver fichero

@@ -40,6 +40,13 @@ i32 IZ_WSServerCallback(
size_t
);

IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context**, u16);
typedef struct {
u16 port;
const char* origin;
const char* default_filename;
const char* protocol;
} IZ_WSServerCreateContextParams;

IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context**, IZ_WSServerCreateContextParams);

#endif

Cargando…
Cancelar
Guardar