Added message of the day and made it properly configurable using /#setting (not saved...
authorPerttu Ahola <celeron55@gmail.com>
Sat, 30 Jul 2011 16:31:33 +0000 (19:31 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 30 Jul 2011 16:31:33 +0000 (19:31 +0300)
src/defaultsettings.cpp
src/server.cpp
src/servercommand.cpp
src/servercommand.h
src/strfnd.h

index 947892d12a0d3a4f396fd5e899ae65d4b595fbe9..c1104eff065b348699785eca547a3db279f43c18 100644 (file)
@@ -77,6 +77,7 @@ void set_default_settings()
        g_settings.setDefault("screenshot_path", ".");
 
        // Server stuff
+       g_settings.setDefault("motd", "<Message of the day (motd) not set>");
        g_settings.setDefault("enable_experimental", "false");
        g_settings.setDefault("creative_mode", "false");
        g_settings.setDefault("enable_damage", "true");
index b0c087d09a102d405aa5cb1e89f7ca5b152ec3f2..0b312fbc3e838d9a9e7a0ebb3fe4788379ad04d8 100644 (file)
@@ -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<<L"}";
        if(((ServerMap*)(&m_env.getMap()))->isSavingEnabled() == false)
-               os<<" WARNING: Map saving is disabled."<<std::endl;
+               os<<std::endl<<" WARNING: Map saving is disabled.";
+       if(g_settings.get("motd") != "")
+               os<<std::endl<<narrow_to_wide(g_settings.get("motd"));
        return os.str();
 }
 
index 333e29084cd85ddec67496005de0b03b353ccd2a..a2001b0c515ce1cd4c798b4624b96f5159e71ac1 100644 (file)
@@ -142,7 +142,8 @@ void cmd_setting(std::wostringstream &os,
                return;
        }
 
-       std::string confline = wide_to_narrow(ctx->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.";
 }
index 9013bc2a6da15779ebba1f00d08849f436fe4c99..cee4976b165d29620d5f60060e6bc327e40394d3 100644 (file)
@@ -29,6 +29,7 @@ struct ServerCommandContext
 {
 
        std::vector<std::wstring> parms;
+       std::wstring paramstring;
        Server* server;
        ServerEnvironment *env;
        Player* player;
@@ -39,11 +40,13 @@ struct ServerCommandContext
 
        ServerCommandContext(
                std::vector<std::wstring> 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)
        {
        }
 
index 2be92d43b03d6b51dbf1c4907a1d16f5d268f948..e3d380e377a5233e3f7f33a099a03f661b827bbe 100644 (file)
@@ -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<<"\" plop=\""<<plop<<"\""<<std::endl;
+        size_t n;
+        std::wstring palautus;
+        if (p < tek.size())
+        {  
+            //std::cout<<"\tp<tek.size()"<<std::endl;
+            if ((n = tek.find(plop, p)) == std::wstring::npos || plop == L"")
+            {  
+                //std::cout<<"\t\tn == string::npos || plop == \"\""<<std::endl;
+                n = tek.size();
+            }
+            else
+            {  
+                //std::cout<<"\t\tn != string::npos"<<std::endl;
+            }
+            palautus = tek.substr(p, n-p);
+            p = n + plop.length();
+        }
+        //else
+            //std::cout<<"\tp>=tek.size()"<<std::endl;
+               //std::cout<<"palautus=\""<<palautus<<"\""<<std::endl;
+        return palautus;
+    }
+    bool atend(){
+        if(p>=tek.size()) return true;
+        return false;
+    }
+    WStrfnd(std::wstring s){
+        start(s);
+    }
+};
+
 inline std::string trim(const std::string &s)
 {
        std::string str = s;