From 7620bf42b2a4f8e030857fababd67fbbc087603b Mon Sep 17 00:00:00 2001 From: flash Date: Mon, 4 Nov 2024 19:44:42 +0100 Subject: [PATCH] Local stuff I hadn't committed yet from like a month ago. --- mikoto.cfg | 29 +++++++++++ source/app.d | 106 +++++++++++++++++++++++++++++++---------- source/config/config.d | 6 +++ 3 files changed, 116 insertions(+), 25 deletions(-) create mode 100644 mikoto.cfg create mode 100644 source/config/config.d diff --git a/mikoto.cfg b/mikoto.cfg new file mode 100644 index 0000000..4a69c43 --- /dev/null +++ b/mikoto.cfg @@ -0,0 +1,29 @@ +# and ; can be used at the start of a line for comments. + +# General Configuration +#chat:port 6770 +#chat:msgMaxLength 5000 +#chat:connMaxCount 5 +#chat:floodKickLength 30 +chat:floodKickExemptRank 10 + +# Channels +chat:channels lounge staff + +# Lounge channel settings +chat:channels:lounge:name Lounge +chat:channels:lounge:autoJoin true + +# Staff channel settings +chat:channels:staff:name Staff +chat:channels:staff:minRank 5 + +# Misuzu integration settings +msz:secret veemo57c092d519d6764ebe2afe6207fa403f47885627a61e +#msz:url https://flashii.net/_sockchat + +# MariaDB configuration +mariadb:host localhost +mariadb:user chat +mariadb:pass F5o6AVpWYe9K3qQphldxw9NAlpmrINAF +mariadb:db chat diff --git a/source/app.d b/source/app.d index 04ca780..efd6a41 100644 --- a/source/app.d +++ b/source/app.d @@ -1,41 +1,25 @@ import std.stdio; import core.thread; -import core.stdc.signal; -import core.sys.windows.windows; + +enum CONFIG_PATH = "mikoto.cfg"; __gshared bool hasCancelled; -version(Posix) { - extern(C) void signalHander(int num) nothrow @nogc @system { - if(num == SIGINT) - hasCancelled = true; - } -} - -version(Windows) { - extern(Windows) BOOL ctrlHandler(DWORD fdwCtrlType) nothrow @nogc @system { - switch(fdwCtrlType) { - case CTRL_C_EVENT: - case CTRL_CLOSE_EVENT: - hasCancelled = true; - return TRUE; - - default: - return FALSE; - } - } -} - void main() { + import std.file : exists; import std.range : padLeft; import std.string : format; - version(Windows) + version(Windows) { + import core.sys.windows.windows : SetConsoleCtrlHandler, TRUE; if(!SetConsoleCtrlHandler(&ctrlHandler, TRUE)) stderr.writeln("Failed to register Windows CTRL handler."); + } - version(Posix) + version(Posix) { + import core.stdc.signal : signal, SIGINT; signal(SIGINT, &signalHander); + } if(hasCancelled) return; @@ -50,6 +34,13 @@ void main() { if(hasCancelled) return; + string configPath = CONFIG_PATH; + + if(!configPath.exists && configPath == CONFIG_PATH) + createExampleConfig(configPath); + + if(hasCancelled) return; + for(;;) { Thread.sleep(1.seconds); if(hasCancelled) @@ -58,3 +49,68 @@ void main() { writeln("Exiting!"); } + +void createExampleConfig(string path) { + auto cfg = File(path, "wb+"); + cfg.writeln("# and ; can be used at the start of a line for comments."); + + cfg.writeln(); + cfg.writeln("# General Configuration"); + cfg.writeln(";chat:port {SockChatServer.DEFAULT_PORT}"); + cfg.writeln(";chat:msgMaxLength {SockChatServer.DEFAULT_MSG_LENGTH_MAX}"); + cfg.writeln(";chat:connMaxCount {SockChatServer.DEFAULT_MAX_CONNECTIONS}"); + cfg.writeln(";chat:floodKickLength {SockChatServer.DEFAULT_FLOOD_KICK_LENGTH}"); + + cfg.writeln(); + cfg.writeln("# Channels"); + cfg.writeln("chat:channels lounge staff"); + + cfg.writeln(); + cfg.writeln("# Lounge channel settings"); + cfg.writeln("chat:channels:lounge:name Lounge"); + cfg.writeln("chat:channels:lounge:autoJoin true"); + + cfg.writeln(); + cfg.writeln("# Staff channel settings"); + cfg.writeln("chat:channels:staff:name Staff"); + cfg.writeln("chat:channels:staff:minRank 5"); + + cfg.writeln(); + cfg.writeln("# Misuzu integration settings"); + cfg.writeln(";msz:secret woomy"); + cfg.writeln(";msz:url https://flashii.net/_sockchat"); + + cfg.writeln(); + cfg.writeln("# MariaDB configuration"); + cfg.writeln(";mariadb:host "); + cfg.writeln(";mariadb:user "); + cfg.writeln(";mariadb:pass "); + cfg.writeln(";mariadb:db "); +} + +version(Posix) { + extern(C) void signalHander(int num) nothrow @nogc @system { + import core.stdc.signal : SIGINT; + + if(num == SIGINT) + hasCancelled = true; + } +} + +version(Windows) { + import core.sys.windows.windows : BOOL, DWORD; + + extern(Windows) BOOL ctrlHandler(DWORD fdwCtrlType) nothrow @nogc @system { + import core.sys.windows.windows : CTRL_C_EVENT, CTRL_CLOSE_EVENT, TRUE, FALSE; + + switch(fdwCtrlType) { + case CTRL_C_EVENT: + case CTRL_CLOSE_EVENT: + hasCancelled = true; + return TRUE; + + default: + return FALSE; + } + } +} diff --git a/source/config/config.d b/source/config/config.d new file mode 100644 index 0000000..f7bd53e --- /dev/null +++ b/source/config/config.d @@ -0,0 +1,6 @@ +module mikoto.config; + +interface Config { + Config scopeTo(string prefix); + string readValue(string name, string fallback = null); +}