Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <signal.h>
00036
00037 #include "cmdline/cmdline.h"
00038 #include "aesop-srv/aesop-srv.h"
00039 #include "datahash/datahash_text.h"
00040 #include "mapzone/mapzone.h"
00041 #include "perf/perf.h"
00042 #include "physics-loader/physics-loader.h"
00043 #include "srv-game-logic/srv-game-logic.h"
00044
00045
00046
00060
00063 static smart_ptr<aesop::Server> s_server;
00064
00065
00067
00068
00069
00071
00072 static void
00073 signalHandlerHUP
00074 (
00075 IN int signal
00076 )
00077 {
00078 if (s_server) {
00079 int retval = 3;
00080 s_server->requestStopTS(retval);
00081 }
00082 }
00083
00084
00085
00086 static void
00087 initializeServer
00088 (
00089 IN const char * config_file
00090 )
00091 {
00092 perf::Timer timer("initializeServer");
00093 ASSERT(config_file, "null");
00094
00095
00096
00097 smart_ptr<aesop::MapFormatReader> reader =
00098 mapzone::getMapFormatReader();
00099 ASSERT(reader, "failed to create basic map reader");
00100 aesop::registerMapFormatReader(reader);
00101
00102
00103 smart_ptr<aesop::TypeComponentLoader> physics =
00104 aesop::getPhysicsLoader();
00105 ASSERT(physics, "failed to create physics loader");
00106 aesop::registerTypeComponentLoader(physics);
00107 DPRINTF("Just registered physics loader!");
00108
00109
00110 smart_ptr<Datahash> server_params =
00111 readHashFromTextFile(config_file);
00112 ASSERT(server_params, "Failed to read server parameters");
00113
00114
00115 smart_ptr<aesop::ServerGameLogic> gameLogic =
00116 aesop::createServerGameLogic();
00117 ASSERT(gameLogic, "Failed to create game logic object");
00118
00119
00120 s_server = aesop::Server::create(server_params, gameLogic);
00121 ASSERT(s_server, "failed to create server?");
00122 }
00123
00124
00125
00127
00128
00129
00131
00132 int
00133 main
00134 (
00135 IN int argc,
00136 IN const char * argv[]
00137 )
00138 {
00139 smart_ptr<CommandLine> cmd = CommandLine::create(argc, argv);
00140 ASSERT(cmd, "failed to create command-line parser");
00141
00142 const char * srv_config_file = getSingleKeyValue(cmd, "config-file",
00143 true, "file that contains aesop server operational config");
00144 ASSERT(srv_config_file, "null");
00145
00146
00147 struct sigaction sigact;
00148 sigact.sa_handler = signalHandlerHUP;
00149 sigact.sa_flags = 0;
00150 ASSERT(!sigaction(SIGHUP, &sigact, NULL),
00151 "Failed to register handler for SIGHUP");
00152 ASSERT(!sigaction(SIGINT, &sigact, NULL),
00153 "Failed to register handler for SIGINT");
00154 ASSERT(!sigaction(SIGTERM, &sigact, NULL),
00155 "Failed to register handler for SIGTERM");
00156
00157 int retval = 0;
00158 try {
00159 perf::Timer timer("aesop-server-main");
00160
00161
00162 initializeServer(srv_config_file);
00163 ASSERT(s_server, "should have server now!");
00164
00165
00166 retval = s_server->exec();
00167
00168 } catch (std::exception& e) {
00169 DPRINTF("Caught exception: %s", e.what());
00170 retval = 1;
00171 } catch (...) {
00172 DPRINTF("Caught unknown exception!");
00173 retval = 2;
00174 }
00175
00176 std::string summary;
00177 perf::getTimingSummary(summary);
00178 DPRINTF("Timers:\n%s", summary.c_str());
00179
00180 return retval;
00181 }
00182