From bfbba84b5c772bc317237fa76cd6daf3c4d97956 Mon Sep 17 00:00:00 2001 From: snit Date: Thu, 17 Oct 2024 15:14:16 -0500 Subject: [PATCH] i forgor that common lib is technically a system lib so it should be in <> and not "" --- client/src/main.c | 15 ++++++++------- client/src/render/render.h | 2 +- client/src/sock.c | 9 +++++---- client/src/sock.h | 2 +- doc/TODO.gmi | 5 ++++- server/src/daemon.h | 2 +- server/src/data.h | 3 ++- server/src/main.c | 2 +- server/src/opts.h | 2 +- server/src/sock.h | 2 +- 10 files changed, 25 insertions(+), 19 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 8eb5317..9bbb7bd 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -4,8 +4,9 @@ #include #include -#include "world.h" -#include "error.h" +#include +#include + #include "sock.h" int main(void) { @@ -13,31 +14,31 @@ int main(void) { int sock; err = sock_init(&sock); - if (err) goto handle_error; + if (err) goto error; char ibuf[8192] = { 0 }; read(sock, ibuf, 8192); struct world_t world = { 0 }; err = world_deserialise_str(&world, ibuf); - if (err != ERR_OK) goto handle_error_sock; + if (err != ERR_OK) goto error_socket; printf("CLIENT: (%zu %zu) ->", world.height++, world.width ++); printf(" (%zu %zu)\n", world.height, world.width); char obuf[8192] = { 0 }; err = world_serialise_buf(&world, obuf, 8192); - if (err != ERR_OK) goto handle_error_sock; + if (err != ERR_OK) goto error_socket; write(sock, obuf, 8192); close(sock); return ERR_OK; -handle_error_sock: +error_socket: close(sock); -handle_error: +error: printf("CLIENT ERROR: %s\n", ERROR_STRS[err]); return err; } diff --git a/client/src/render/render.h b/client/src/render/render.h index 78738f5..285e155 100644 --- a/client/src/render/render.h +++ b/client/src/render/render.h @@ -1,7 +1,7 @@ #ifndef RENDER_H #define RENDER_H -#include "world.h" +#include void render_world(struct world_t const *); diff --git a/client/src/sock.c b/client/src/sock.c index b14179e..375f3cb 100644 --- a/client/src/sock.c +++ b/client/src/sock.c @@ -12,19 +12,20 @@ enum error_t sock_init(int *sockptr) { assert(sockptr != NULL); int const sock = socket(AF_UNIX, SOCK_STREAM, 0); - if (sock < 0) goto sock_init_error; + if (sock < 0) goto error; struct sockaddr_un sa = { 0 }; sa.sun_family = AF_UNIX; strcpy(sa.sun_path, SOCK_PATH); - if (connect(sock, (struct sockaddr *)&sa, sizeof(sa))) goto sock_error; + if (connect(sock, (struct sockaddr *)&sa, sizeof(sa))) goto error_connect; *sockptr = sock; return ERR_OK; -sock_error: +error_connect: close(sock); -sock_init_error: + +error: return ERR_SOCKET; } diff --git a/client/src/sock.h b/client/src/sock.h index e9d095b..a42e94b 100644 --- a/client/src/sock.h +++ b/client/src/sock.h @@ -1,7 +1,7 @@ #ifndef SOCK_H #define SOCK_H -#include "error.h" +#include #define SOCK_PATH "/tmp/swd.sock" diff --git a/doc/TODO.gmi b/doc/TODO.gmi index 30f4671..7817741 100644 --- a/doc/TODO.gmi +++ b/doc/TODO.gmi @@ -2,6 +2,9 @@ A list of things I'd like to accomplish ## In Progress +* Client send request +* Server handle request and send response +* Client handle response * Have client render world data (return to pre-daemonised equivalent state) ## Completed @@ -16,7 +19,7 @@ A list of things I'd like to accomplish * Write Makefile to automate compilation ## Planned -* Game loop +* Split game ticking and socket connecting logic (can only tick on connection atm) * Create and load worlds * Display environment and pan camera * Time controls (play/pause/speed up) diff --git a/server/src/daemon.h b/server/src/daemon.h index 2fbe159..df71f08 100644 --- a/server/src/daemon.h +++ b/server/src/daemon.h @@ -1,7 +1,7 @@ #ifndef DAEMON_H #define DAEMON_H -#include "error.h" +#include enum error_t daemonise(void); diff --git a/server/src/data.h b/server/src/data.h index 5295ca5..cc0a570 100644 --- a/server/src/data.h +++ b/server/src/data.h @@ -1,7 +1,8 @@ #ifndef DAEMON_DATA_H #define DAEMON_DATA_H -#include "world.h" +#include + #include "opts.h" struct data_t { diff --git a/server/src/main.c b/server/src/main.c index a7a00f0..59bedfe 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -8,7 +8,7 @@ #include #include -#include "error.h" +#include #include "opts.h" #include "sock.h" diff --git a/server/src/opts.h b/server/src/opts.h index a4dac14..001eb21 100644 --- a/server/src/opts.h +++ b/server/src/opts.h @@ -3,7 +3,7 @@ #include -#include "error.h" +#include struct options_t { bool daemonise; diff --git a/server/src/sock.h b/server/src/sock.h index 6509dcf..d7a5c5d 100644 --- a/server/src/sock.h +++ b/server/src/sock.h @@ -1,7 +1,7 @@ #ifndef SOCK_H #define SOCK_H -#include "error.h" +#include #include "data.h"