From 9ae99ae2949716cb05cd8fee618cb4ce67fff4a5 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Thu, 16 Feb 2023 09:20:25 -0500 Subject: Work on configuration --- .gitignore | 1 + .vscode/launch.json | 7 +++++++ .vscode/tasks.json | 23 +++++++++++++++++++++++ Makefile | 2 +- README.md | 2 +- src/main.c | 21 +++++++++++++++++++++ 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 1451ed6..90c86f9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 687ca80..374051e 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README.md b/README.md index e29af61..d8f43d2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/main.c b/src/main.c index 2c45a58..07a3f2c 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,9 @@ #include "log.h" #include #include +#include + +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); -- cgit v1.2.3