From e2af58d720f449d4f742e8bc4f5b331eda0c760a Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:42:39 +0800 Subject: [PATCH] [server] Implement con_exec() --- server/console.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++- server/main.h | 10 ++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/server/console.cpp b/server/console.cpp index f25f032..f467656 100644 --- a/server/console.cpp +++ b/server/console.cpp @@ -19,7 +19,69 @@ void con_echo() } } -void con_exec() {} // TODO: con_exec W: 0048BA80 L: 080A0340 +void con_exec() +{ + char* arg = strtok(NULL, " "); + if (arg) + { + char tmp[1025]; + char tmpvarname[1025]; + sprintf(tmp, "%s.cfg", arg); + FILE* f = fopen(tmp, "r"); + if (!f) + { + logprintf("Unable to exec file '%s'.", tmp); + } else { + memset(tmp, 0, sizeof(tmp)); + while (fgets(tmp, 1024, f)) + { + int len = strlen(tmp); + if (len > 1024) continue; + if (len > 0 && tmp[len-1] == '\n') + tmp[strlen(tmp)-1] = 0; + len = strlen(tmp); + if (len > 0 && tmp[len-1] == '\r') + tmp[strlen(tmp)-1] = 0; + if (tmp[0] == 0) + continue; + // If the line has a comment, finish it there. + for (size_t i=0; i 2) + { + if ((tmp[0] != '/') && (tmp[1] != '/')) { + memset(tmpvarname, 0, sizeof(tmpvarname)); + for(int i = 0; tmp[i] != '\0'; i++) + { + if (tmp[i] == ' ') + { + tmpvarname[i] = '\0'; + break; + } + tmpvarname[i] = tmp[i]; + } + if (pConsole->FindVariable(tmpvarname)) + { + pConsole->Execute(tmp); + } + } + } + memset(tmp, 0, sizeof(tmp)); + } + fclose(f); + } + } else { + logprintf("Usage:"); + logprintf(" exec "); + } +} + void con_kick() {} // TODO: con_kick W: 0048A530 L: 0809ECB0 void con_ban() {} // TODO: con_ban W: 0048A5D0 L: 0809ED80 void con_banip() {} // TODO: con_banip W: 0048A740 L: 0809EF40 diff --git a/server/main.h b/server/main.h index b5d98e6..3b57cfe 100644 --- a/server/main.h +++ b/server/main.h @@ -67,6 +67,16 @@ #include "netgame.h" #include "plugins.h" +// --------- +// EXTERNALS +// --------- + +extern CConsole* pConsole; + +// ------------------- +// FUNCTION PROTOTYPES +// ------------------- + void logprintf(char* format, ...); void flogprintf(char* format, ...);