diff --git a/.gitignore b/.gitignore index ac4a0fb..5534f44 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ *.code-workspace -.secrets \ No newline at end of file +.secrets +controller \ No newline at end of file diff --git a/config.cfg b/config.cfg index e46ef44..44b3748 100644 --- a/config.cfg +++ b/config.cfg @@ -1,3 +1,51 @@ -port 8888 -# Minecraft is a cool game yep -program minecraft # still cool \ No newline at end of file +# Syntax for this config file: +# Comments are marked with # +# Every line needs 2 things, a name and a value +# Name and value are separated by whitespace +# Leading and trailing whitespace is irrelevant, so feel free to indent to increase readability +# There must not be any whitespace inside of values. +# For example, file paths must not have spaces in them, otherwise the parser will not work +# Names are case sensitive + +# The port the web server will listen on +port 8888 # Inline comments are supported + +# program defines the name of a program to launch and manage. +# It also marks the beginning of the program definition +# The program name needs to have at least these attributes immediately following: +# - id +# - path +program Godot + # ID is the internal ID of the program. It is an unsigned char, so there cannot be more than 255 programs total + id 0 # REQUIRED + + # The path to the program binary / executable + # The controller will fork, replace stdin, stdout, and sterr with pipes, and then execv this path + path ~/Documents/Godot/Versions/Godot_v4.4.1-stable_linux.x86_64 # REQUIRED + + # Indicates if the site/api should allow viewing if the program is running or not + status-console 1 # Optional. Will default to 1 if not defined + + # Boolean. 0 for false, 1 for true. Indicates if the site/api should allow sending commands to the program stdin + # Useful for game servers that allow console commands + admin-console 0 # Optional. Will default to 0 if not defined + +# user defines the name of a use +user Nolan + # Like program IDs, it is an unsigned char. Maximum value of 255 + id 0 # REQUIRED + + # Indicates a program that a user has admin access to by ID + # -1 indicates universal admin access + # This name can be repeated as many times as necessary + admin -1 # Optional + + # Indicates a program that a user can turn on or off by ID + # -1 indicates universal admin access + # This name can be repeated as many times as necessary + launch -1 # Optional + + # Indicates a program that a user may view, but without admin access by ID + # -1 indicates universal view privilages + # This name can be repeated as many times as necessary + view -1 # Optional diff --git a/controller b/controller deleted file mode 100755 index bc49771..0000000 Binary files a/controller and /dev/null differ diff --git a/makefile b/makefile index a3fbddb..4b72d06 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ controller: - gcc -Wall ServerController.c -o controller -lmicrohttpd -lyaml + gcc -Wall src/ServerController.c -o controller -lmicrohttpd clean: rm controller \ No newline at end of file diff --git a/ServerController.c b/src/ServerController.c similarity index 57% rename from ServerController.c rename to src/ServerController.c index 8fb808b..f776877 100644 --- a/ServerController.c +++ b/src/ServerController.c @@ -1,16 +1,6 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "ServerController.h" -#define CONFIG "config.cfg" +#define CONFIG "../config.cfg" #define SECRETS ".secrets" const int PORT; @@ -29,17 +19,15 @@ void readConfig(){ FILE *file = fopen("config.cfg", "r"); char buf[1024]; while (fgets(buf, 1024, file) != NULL){ - printf("Line: \n%s\n", buf); char *newbuf = calloc(1024, 1); for (int i = 0; i < 1024; i++){ if (buf[i] == '#') break; else newbuf[i] = buf[i]; } - printf("Newbuf: %s\n", newbuf); char buf1[512]; char buf2[512]; - if (sscanf(newbuf, "%s %s", buf1, buf2) == 2){ - printf("Values: %s %s\n", buf1, buf2); + if (sscanf(newbuf, "%s %s\n", buf1, buf2) == 2){ + printf("(%s,%s)\n", buf1, buf2); } free(newbuf); } diff --git a/src/ServerController.h b/src/ServerController.h new file mode 100644 index 0000000..9872576 --- /dev/null +++ b/src/ServerController.h @@ -0,0 +1,15 @@ +#ifndef CONTROLLER + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif \ No newline at end of file