aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-02-16 09:20:25 -0500
committerCara Salter <cara@devcara.com>2023-02-16 09:20:25 -0500
commit9ae99ae2949716cb05cd8fee618cb4ce67fff4a5 (patch)
tree53ed1b21667e524674deb69dc6f416c8bef9dcd1
parent085ca0d6ca31223b14855525dc82bcdae93cf7f7 (diff)
downloadcmud-9ae99ae2949716cb05cd8fee618cb4ce67fff4a5.tar.gz
cmud-9ae99ae2949716cb05cd8fee618cb4ce67fff4a5.zip
Work on configuration
-rw-r--r--.gitignore1
-rw-r--r--.vscode/launch.json7
-rw-r--r--.vscode/tasks.json23
-rw-r--r--Makefile2
-rw-r--r--README.md2
-rw-r--r--src/main.c21
6 files changed, 54 insertions, 2 deletions
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 <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);