From 9b294ffa7a1f3cf7ee19111b7e5f4882f130dd21 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 19:31:33 +0300 Subject: [PATCH] Added message of the day and made it properly configurable using /#setting (not saved to config file yet) --- src/defaultsettings.cpp | 1 + src/server.cpp | 9 +++++++- src/servercommand.cpp | 3 ++- src/servercommand.h | 5 ++++- src/strfnd.h | 50 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 947892d12..c1104eff0 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -77,6 +77,7 @@ void set_default_settings() g_settings.setDefault("screenshot_path", "."); // Server stuff + g_settings.setDefault("motd", ""); g_settings.setDefault("enable_experimental", "false"); g_settings.setDefault("creative_mode", "false"); g_settings.setDefault("enable_damage", "true"); diff --git a/src/server.cpp b/src/server.cpp index b0c087d09..0b312fbc3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3196,9 +3196,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) line += L"Server: "; message = message.substr(commandprefix.size()); + + WStrfnd f1(message); + f1.next(L" "); + std::wstring paramstring = f1.next(L""); ServerCommandContext *ctx = new ServerCommandContext( str_split(message, L' '), + paramstring, this, &m_env, player, @@ -4018,7 +4023,9 @@ std::wstring Server::getStatusString() } os<isSavingEnabled() == false) - os<<" WARNING: Map saving is disabled."<parms[1] + L" = " + ctx->parms[2]); + std::string confline = wide_to_narrow( + ctx->parms[1] + L" = " + ctx->paramstring); g_settings.parseConfigLine(confline); os<< L"-!- Setting changed."; } diff --git a/src/servercommand.h b/src/servercommand.h index 9013bc2a6..cee4976b1 100644 --- a/src/servercommand.h +++ b/src/servercommand.h @@ -29,6 +29,7 @@ struct ServerCommandContext { std::vector parms; + std::wstring paramstring; Server* server; ServerEnvironment *env; Player* player; @@ -39,11 +40,13 @@ struct ServerCommandContext ServerCommandContext( std::vector parms, + std::wstring paramstring, Server* server, ServerEnvironment *env, Player* player, u64 privs) - : parms(parms), server(server), env(env), player(player), privs(privs) + : parms(parms), paramstring(paramstring), + server(server), env(env), player(player), privs(privs) { } diff --git a/src/strfnd.h b/src/strfnd.h index 2be92d43b..e3d380e37 100644 --- a/src/strfnd.h +++ b/src/strfnd.h @@ -74,6 +74,56 @@ public: } }; +class WStrfnd{ + std::wstring tek; + unsigned int p; +public: + void start(std::wstring niinq){ + tek = niinq; + p=0; + } + unsigned int where(){ + return p; + } + void to(unsigned int i){ + p = i; + } + std::wstring what(){ + return tek; + } + std::wstring next(std::wstring plop){ + //std::cout<<"tek=\""<=tek.size()"<=tek.size()) return true; + return false; + } + WStrfnd(std::wstring s){ + start(s); + } +}; + inline std::string trim(const std::string &s) { std::string str = s; -- 2.25.1