From 4cad4a27677b0490d3ba0018bc3404961f925ed5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 8 Nov 2008 10:17:37 +0000 Subject: docking, bumps network protocol version --- src/core/application.cc | 151 ++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 75 deletions(-) (limited to 'src/core/application.cc') diff --git a/src/core/application.cc b/src/core/application.cc index 09e900d..300aaa6 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -27,69 +27,7 @@ namespace core { -// --------------- engine functions ------------------------------ -void func_help(std::string const &args) -{ - std::istringstream argstream(args); - std::string topic; - if (!(argstream >> topic)) - topic.assign("help"); - - topic.append(".txt"); - CommandBuffer::print_file("help/" + topic); -} - -void func_quit(std::string const &args) -{ - application()->shutdown(); - application()->quit(0); -} - -void func_connect(std::string const &args) -{ - std::istringstream argstream(args); - std::string host; - if (!(argstream >> host)) - host.clear(); - - application()->connect(host); -} - -void func_disconnect(std::string const &args) -{ - application()->disconnect(); -} - -void func_say(std::string const &args) -{ - if (connection()) { - connection()->say(args); - } else if (server()) { - server()->say(localplayer(), args); - } else { - con_print << "Not connected." << std::endl; - } -} - -void func_msg(std::string const &args) -{ - if (connection()) { - connection()->private_message(args); - } else if (server()) { - server()->private_message(localplayer(), args); - } else { - con_print << "Not connected." << std::endl; - } -} - -void func_load(std::string const &args) -{ - std::string name(args); - aux::to_label(name); - application()->load(name); -} - -// --------------- signal_handler ----------------------------------- +/* ---- signal handler --------------------------------------------- */ #ifndef _WIN32 extern "C" void signal_handler(int signum) @@ -101,11 +39,11 @@ extern "C" void signal_handler(int signum) case SIGTERM: if (Application::instance()) { con_warn << "Received signal " << signum << ", shutting down...\n"; - application()->shutdown(); - application()->quit(0); + Application::instance()->shutdown(); + Application::instance()->quit(0); } else { std::cerr << "Received signal " << signum << ", terminated...\n"; - application()->quit(1); + Application::instance()->quit(1); } break; #ifdef HAVE_CURSES @@ -115,13 +53,13 @@ extern "C" void signal_handler(int signum) #endif default: std::cerr << "Received signal " << signum << ", terminated...\n"; - application()->quit(1); + Application::instance()->quit(1); break; } } #endif -// --------------- Application ----------------------------- +/* ---- class Application ------------------------------------------ */ Application *Application::application_instance = 0; @@ -229,25 +167,25 @@ void Application::init(int count, char **arguments) // register our engine functions Func *func = 0; - func = Func::add("help", func_help); + func = Func::add("help", Application::func_help); func->set_info("help function"); - func = Func::add("quit", func_quit); + func = Func::add("quit", Application::func_quit); func->set_info("exit the application"); - func = Func::add("load", func_load); + func = Func::add("load", Application::func_load); func->set_info("[str] load a game module"); - func = Func::add("connect", func_connect); + func = Func::add("connect", Application::func_connect); func->set_info("[ip] without ip, create a game"); - func = Func::add("disconnect", func_disconnect); + func = Func::add("disconnect", Application::func_disconnect); func->set_info("leave the current game"); - func = Func::add("say", func_say); + func = Func::add("say", Application::func_say); func->set_info("say [text] say something on the public chat"); - func = Func::add("msg", func_msg); + func = Func::add("msg", Application::func_msg); func->set_info("msg [player] [text] send a private message to another player"); func = 0; @@ -552,4 +490,67 @@ void Application::notify_remove_sound(size_t source) // Dedicated servers don't need sounds } +/* -- static engine functions -------------------------------------- */ + +void Application::func_help(std::string const &args) +{ + std::istringstream argstream(args); + std::string topic; + if (!(argstream >> topic)) + topic.assign("help"); + + topic.append(".txt"); + CommandBuffer::print_file("help/" + topic); +} + +void Application::func_quit(std::string const &args) +{ + Application::instance()->shutdown(); + Application::instance()->quit(0); +} + +void Application::func_connect(std::string const &args) +{ + std::istringstream argstream(args); + std::string host; + if (!(argstream >> host)) + host.clear(); + + Application::instance()->connect(host); +} + +void Application::func_disconnect(std::string const &args) +{ + Application::instance()->disconnect(); +} + +void Application::func_say(std::string const &args) +{ + if (connection()) { + connection()->say(args); + } else if (server()) { + server()->say(localplayer(), args); + } else { + con_print << "Not connected." << std::endl; + } +} + +void Application::func_msg(std::string const &args) +{ + if (connection()) { + connection()->private_message(args); + } else if (server()) { + server()->private_message(localplayer(), args); + } else { + con_print << "Not connected." << std::endl; + } +} + +void Application::func_load(std::string const &args) +{ + std::string name(args); + aux::to_label(name); + Application::instance()->load(name); +} + } -- cgit v1.2.3