diff options
author | Cara Salter <cara@devcara.com> | 2023-02-16 09:20:25 -0500 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2023-02-16 09:20:25 -0500 |
commit | 9ae99ae2949716cb05cd8fee618cb4ce67fff4a5 (patch) | |
tree | 53ed1b21667e524674deb69dc6f416c8bef9dcd1 | |
parent | 085ca0d6ca31223b14855525dc82bcdae93cf7f7 (diff) | |
download | cmud-9ae99ae2949716cb05cd8fee618cb4ce67fff4a5.tar.gz cmud-9ae99ae2949716cb05cd8fee618cb4ce67fff4a5.zip |
Work on configuration
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .vscode/launch.json | 7 | ||||
-rw-r--r-- | .vscode/tasks.json | 23 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/main.c | 21 |
6 files changed, 54 insertions, 2 deletions
@@ -193,3 +193,4 @@ tags [._]*.un~ # End of https://www.toptal.com/developers/gitignore/api/autotools,vim +config.cfg diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +}
\ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5a2c071 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Make (development)", + "type": "shell", + "command": "make dev", + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Make (clean)", + "type": "shell", + "command": "make clean", + "problemMatcher": [] + } + ] +}
\ No newline at end of file @@ -2,7 +2,7 @@ CC=gcc CFLAGS=-I. SRCS=$(wildcard src/*.c) BIN=cmud -LFLAGS=-largon2 -lpthread -lclog -Wall +LFLAGS=-largon2 -lpthread -lclog -lconfig -Wall %.o: %.c $(CC) -c -o $@ $< $(CFLAGS) @@ -5,7 +5,7 @@ This is a spiritual successor of `~muirrum/hakkardrs`, but that project never really got off the ground. ## Dependencies -This project requires `argon2`, `pthread`, and your preferred libc. Development +This project requires `argon2`, `pthread`, `libconfig`, and your preferred libc. Development happens on a Gentoo x86 laptop with glibc. ## Building @@ -5,6 +5,9 @@ #include "log.h" #include <stdlib.h> #include <stdio.h> +#include <libconfig.h> + +config_t cfg; /** * Server entrypoint @@ -12,6 +15,24 @@ * sets up everything needed to handle sockets and connections * */ int main() { + + debug("Initializing config..."); + config_init(&cfg); + if (config_read_file(&cfg, "config.cfg") != CONFIG_TRUE) { + error("Could not read config:"); + printf("%s (%d): %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + + exit(-1); + } + debug("Done"); + + const char* name; + if (!config_lookup_string(&cfg, "name", &name)) { + error("Invalid config"); + exit(-1); + } + + info("Starting up %s game server", name); int err = 0; server_t server = {0}; err = server_listen(&server); |