diff options
Diffstat (limited to 'src/core/gameserver.cc')
-rw-r--r-- | src/core/gameserver.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index fce758e..ea97eaf 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -5,6 +5,7 @@ */ #include <iomanip> +#include <fstream> #include "auxiliary/functions.h" #include "sys/sys.h" @@ -13,6 +14,7 @@ #include "core/func.h" #include "core/gameserver.h" #include "core/netserver.h" +#include "filesystem/filesystem.h" namespace core { @@ -119,6 +121,8 @@ GameServer::GameServer() : GameInterface() return; } + load_config(); + // set the name of the game core::Cvar::set("g_name", server_module->name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly); @@ -190,6 +194,8 @@ GameServer::~GameServer() server_network = 0; } + save_config(); + if (server_module) { if (server_module->running() && !Cvar::sv_dedicated->value()) player_disconnect(localplayer()); @@ -583,5 +589,54 @@ void GameServer::frame(float seconds) server_previoustime = server_time; } +void GameServer::save_config() +{ + std::string filename(filesystem::writedir()); + filename.append("game.cfg"); + std::ofstream ofs(filename.c_str()); + + if (!ofs.is_open()) { + con_warn << "Could not write " << filename << std::endl; + return; + } + + con_print << " writing configuration to " << filename << std::endl; + + ofs << "# game.cfg - " << server_module->name() << " configuration" << std::endl; + ofs << "# this file is automaticly generated" << std::endl; + ofs << std::endl; + + for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) { + if ((((*it).second->flags() & Cvar::Archive) == Cvar::Archive) && (((*it).second->flags() & Cvar::Game) == Cvar::Game)){ + ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl; + ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; + ofs << std::endl; + } + } + ofs.close(); +} + +void GameServer::load_config() +{ + std::string filename(filesystem::writedir()); + filename.append("game.cfg"); + std::ifstream ifs(filename.c_str(), std::ifstream::in); + + if (!ifs.is_open()) { + con_warn << "Could not read " << filename << std::endl; + return; + } + + con_print << " reading configuration from " << filename << std::endl; + + char line[MAXCMDSIZE]; + while (ifs.getline(line, MAXCMDSIZE-1)) { + if (line[0] && line[0] != '#' && line[0] != ';') + cmd() << line << '\n'; + } + + // execute commands in the buffer + CommandBuffer::exec(); +} } |