From cdadbdbd17d624dd45cca67f41309cbe776dc348 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 19:49:42 +0300 Subject: [PATCH] Server configuration is now written when "/#setting whatever = whatever" is issued. --- src/game.cpp | 5 +++-- src/game.h | 3 ++- src/main.cpp | 5 +++-- src/server.cpp | 10 ++++++---- src/server.h | 13 ++++++++++++- src/servercommand.cpp | 12 +++++++++--- src/servermain.cpp | 2 +- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 74b8e5029..6c0474ee7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -715,7 +715,8 @@ void the_game( std::string password, std::string address, u16 port, - std::wstring &error_message + std::wstring &error_message, + std::string configpath ) { video::IVideoDriver* driver = device->getVideoDriver(); @@ -755,7 +756,7 @@ void the_game( if(address == ""){ draw_load_screen(L"Creating server...", driver, font); std::cout<start(port); } diff --git a/src/game.h b/src/game.h index eb289b8f2..95623316a 100644 --- a/src/game.h +++ b/src/game.h @@ -70,7 +70,8 @@ void the_game( std::string password, std::string address, u16 port, - std::wstring &error_message + std::wstring &error_message, + std::string configpath ); #endif diff --git a/src/main.cpp b/src/main.cpp index 9a9b22f87..3cc748954 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1302,7 +1302,7 @@ int main(int argc, char *argv[]) g_timegetter = new SimpleTimeGetter(); // Create server - Server server(map_dir.c_str()); + Server server(map_dir.c_str(), configpath); server.start(port); // Run server @@ -1641,7 +1641,8 @@ int main(int argc, char *argv[]) password, address, port, - error_message + error_message, + configpath ); } //try diff --git a/src/server.cpp b/src/server.cpp index 0b312fbc3..96e64b314 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1058,7 +1058,8 @@ u32 PIChecksum(core::list &l) */ Server::Server( - std::string mapsavedir + std::string mapsavedir, + std::string configpath ): m_env(new ServerMap(mapsavedir), this), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), @@ -1069,6 +1070,7 @@ Server::Server( m_time_of_day_send_timer(0), m_uptime(0), m_mapsavedir(mapsavedir), + m_configpath(configpath), m_shutdown_requested(false), m_ignore_map_edit_events(false), m_ignore_map_edit_events_peer_id(0) @@ -3198,7 +3200,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) message = message.substr(commandprefix.size()); WStrfnd f1(message); - f1.next(L" "); + f1.next(L" "); // Skip over /#whatever std::wstring paramstring = f1.next(L""); ServerCommandContext *ctx = new ServerCommandContext( @@ -4023,9 +4025,9 @@ std::wstring Server::getStatusString() } os<isSavingEnabled() == false) - os<parms[1] + L" = " + ctx->paramstring); + /*std::string confline = wide_to_narrow( + ctx->parms[1] + L" = " + ctx->params[2]);*/ + + std::string confline = wide_to_narrow(ctx->paramstring); + g_settings.parseConfigLine(confline); - os<< L"-!- Setting changed."; + + ctx->server->saveConfig(); + + os<< L"-!- Setting changed and configuration saved."; } void cmd_teleport(std::wostringstream &os, diff --git a/src/servermain.cpp b/src/servermain.cpp index 146c548c5..91fd1d3a5 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -323,7 +323,7 @@ int main(int argc, char *argv[]) map_dir = g_settings.get("map-dir"); // Create server - Server server(map_dir.c_str()); + Server server(map_dir.c_str(), configpath); server.start(port); // Run server