From 644479214119760394db18ec2488917ffb3a6c54 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 9 Apr 2008 19:38:25 +0000 Subject: parse command line arguments --- src/core/application.cc | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'src/core/application.cc') diff --git a/src/core/application.cc b/src/core/application.cc index ee0dd76..2ff7bb0 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -113,7 +113,7 @@ Application::~Application() application_instance = 0; } -void Application::init() +void Application::init(int count, char **arguments) { con_debug << "Debug messages enabled\n"; con_print << "Initializing core...\n"; @@ -121,6 +121,7 @@ void Application::init() filesystem::init(); CommandBuffer::init(); + // dedicated server has set this to 1 Cvar::sv_dedicated = Cvar::get("sv_dedicated", "0", Cvar::ReadOnly); Cvar::sv_dedicated->set_info("[bool] indicates this is a dedicated server"); @@ -129,9 +130,12 @@ void Application::init() Cvar::sv_private = Cvar::get("sv_private", "0"); Cvar::sv_private->set_info("[bool] indicates the client runs a networked server"); - // load save cvars + // load configuration load_config(); + // load command line + load_commandline(count, arguments); + // framerate settings Cvar::sv_framerate = Cvar::get("sv_framerate", "25"); Cvar::sv_framerate->set_info("[int] server framerate in frames/sec"); @@ -289,8 +293,15 @@ void Application::save_config() con_warn << "Could not write " << filename << std::endl; return; } - - std::map::iterator it; + + if (!Cvar::sv_dedicated->value()) + ofs << "# client.cfg - osirion client configuration" << std::endl; + else + ofs << "# server.cfg - osiriond dedicated server configuration" << std::endl; + + ofs << "# this file is automaticly generated" << std::endl; + + Cvar::iterator it; for (it = Cvar::registry.begin(); it != Cvar::registry.end(); it++) { if (((*it).second->flags() & Cvar::Archive) == Cvar::Archive) @@ -315,11 +326,34 @@ void Application::load_config() char line[MAXCMDSIZE]; while (ifs.getline(line, MAXCMDSIZE-1)) { - cmd() << line << "\n"; - + if (line[0] && line[0] != '#' && line[0] != ';') + cmd() << line << '\n'; } // execute commands in the buffer CommandBuffer::exec(); } + +void Application::load_commandline(int count, char **arguments) +{ + if (count < 2) + return; + + for (int i=1; i < count; i++) { + if (arguments[i][0] == '+') { + if (i >1) + cmd() << '\n'; + + if (arguments[i][1]) + cmd() << &arguments[i][1]; + } else { + if (i > 1) + cmd() << ' '; + cmd() << arguments[i]; + } + } + + cmd() << '\n'; +} + } -- cgit v1.2.3