From 780c9b06e27f2a4410b1bff1d86724b0ce85afcf Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Fri, 30 Sep 2016 17:22:18 -0500 Subject: [PATCH] planet and metrics --- .../src/shared/MetricsGatheringConnection.cpp | 62 +- .../PlanetServer/src/shared/PlanetServer.cpp | 1069 +++++++++-------- .../PlanetServer/src/shared/Scene.cpp | 157 +-- 3 files changed, 675 insertions(+), 613 deletions(-) diff --git a/engine/server/application/MetricsServer/src/shared/MetricsGatheringConnection.cpp b/engine/server/application/MetricsServer/src/shared/MetricsGatheringConnection.cpp index dd398ff2..0f0c735d 100755 --- a/engine/server/application/MetricsServer/src/shared/MetricsGatheringConnection.cpp +++ b/engine/server/application/MetricsServer/src/shared/MetricsGatheringConnection.cpp @@ -10,6 +10,8 @@ #include "MonAPI2/MonitorAPI.h" #include "serverNetworkMessages/MetricsInitiationMessage.h" +#include "sharedFoundation/CrcConstexpr.hpp" + #include //----------------------------------------------------------------------- @@ -79,34 +81,42 @@ void MetricsGatheringConnection::onReceive(const Archive::ByteStream & message) GameNetworkMessage m(ri); ri = message.begin(); - if(m.isType("ConnectionServerMetricsMessage")) - { - DEBUG_FATAL(true, ("This message has been depricated")); - } - else if (m.isType("MetricsInitiationMessage")) - { - WARNING_STRICT_FATAL(m_initialized, ("Received initialize metrics on initialized connection")); - //Get process name and secondary field (i.e. planet) - MetricsInitiationMessage mx(ri); - bool dynamic = mx.getIsDynamic(); - std::string process = mx.getPrimaryName(); - std::string planet = mx.getSecondaryName(); - int index = mx.getIndex(); - initialize(process, planet, dynamic, index); - } - else if (m.isType("MetricsDataMessage")) - { - if (!m_initialized) + const uint32 messageType = m.getType(); + + switch(messageType) { + case constcrc("ConnectionServerMetricsMessage") : { - //Received data on uninitialized connection. - return; + DEBUG_FATAL(true, ("This message has been depricated")); + break; + } + case constcrc("MetricsInitiationMessage") : + { + WARNING_STRICT_FATAL(m_initialized, ("Received initialize metrics on initialized connection")); + //Get process name and secondary field (i.e. planet) + MetricsInitiationMessage mx(ri); + bool dynamic = mx.getIsDynamic(); + std::string process = mx.getPrimaryName(); + std::string planet = mx.getSecondaryName(); + int index = mx.getIndex(); + initialize(process, planet, dynamic, index); + break; + } + case constcrc("MetricsDataMessage") : + { + if (!m_initialized) + { + //Received data on uninitialized connection. + return; + } + MetricsDataMessage metricsData(ri); + update(metricsData.getData()); + break; + } + default : + { + ServerConnection::onReceive(message); + break; } - MetricsDataMessage metricsData(ri); - update(metricsData.getData()); - } - else - { - ServerConnection::onReceive(message); } } diff --git a/engine/server/application/PlanetServer/src/shared/PlanetServer.cpp b/engine/server/application/PlanetServer/src/shared/PlanetServer.cpp index a76929ce..a472d8e1 100755 --- a/engine/server/application/PlanetServer/src/shared/PlanetServer.cpp +++ b/engine/server/application/PlanetServer/src/shared/PlanetServer.cpp @@ -70,6 +70,8 @@ #include "sharedUtility/LocationManager.h" #include "unicodeArchive/UnicodeArchive.h" +#include "sharedFoundation/CrcConstexpr.hpp" + #include #include #include @@ -408,544 +410,583 @@ void PlanetServer::mainLoop(void) void PlanetServer::receiveMessage(const MessageDispatch::Emitter & source, const MessageDispatch::MessageBase & message) { - if(message.isType("CentralConnectionOpened")) - { - DEBUG_REPORT_LOG(true,("Connected to Central.\n")); - - //handle preloading cities -- the preload list will determine how many servers we spawn - PreloadManager::getInstance().handlePreloadList(); - } - else if (message.isType("ShutdownMessage")) - { - REPORT_LOG(true, ("Instructed to shutdown the server\n")); - setDone("Received ShutdownMessage"); - } - else if(message.isType("CentralConnectionClosed")) - { - DEBUG_REPORT_LOG(true, ("Central server closed connection. Exiting.\n")); - ServerConnection const *serverConnection = dynamic_cast(&source); - setDone("CentralConnectionClosed : %s", serverConnection ? serverConnection->getDisconnectReason().c_str() : ""); - m_centralServerConnection = 0; //lint !e423 // object is deleted elsewhere - m_pendingCentralServerConnection = 0; //lint !e423 // object is deleted elsewhere - } - else if (message.isType("GameConnectionClosed")) - { - GameServerConnection *gameServer=const_cast(dynamic_cast(&source)); - std::set::iterator f = m_pendingGameServerDisconnects.find(gameServer); - - WARNING_DEBUG_FATAL(gameServer==0,("Source was nullptr or source was not a GameServerConnection.")); - DEBUG_REPORT_LOG(true, ("removing crashed gameserver\n")); - uint32 id = gameServer->getProcessId(); - GameServerMapType::iterator i=m_gameServers.find(id); - if (i!=m_gameServers.end()) + const uint32 messageType = message.getType(); + + switch(messageType) { + case constcrc("CentralConnectionOpened") : { - delete i->second; - m_gameServers.erase(i); + DEBUG_REPORT_LOG(true,("Connected to Central.\n")); + + //handle preloading cities -- the preload list will determine how many servers we spawn + PreloadManager::getInstance().handlePreloadList(); + + break; } - - // must call this before removeGameServer() to get the preload number - // for the dead game server; we'll need that in order to start a replacement - PreloadServerId preloadServerId = PreloadManager::getInstance().getPreloadServerId(id); - - // if the game server hadn't gotten far enough to be assigned a preload - // number, use the preload number that was assigned to it when it was started - if (preloadServerId == 0) - preloadServerId = gameServer->getPreloadNumber(); - - PreloadManager::getInstance().removeGameServer(id); - if(f == m_pendingGameServerDisconnects.end()) + case constcrc("ShutdownMessage") : { - std::set startGameServerList; - IGNORE_RETURN(startGameServerList.insert(preloadServerId)); - - startGameServer(startGameServerList, ConfigPlanetServer::getGameServerRestartDelayTimeSeconds()); + REPORT_LOG(true, ("Instructed to shutdown the server\n")); + setDone("Received ShutdownMessage"); + break; } - else + case constcrc("CentralConnectionClosed") : { - m_pendingGameServerDisconnects.erase(f); + DEBUG_REPORT_LOG(true, ("Central server closed connection. Exiting.\n")); + ServerConnection const *serverConnection = dynamic_cast(&source); + setDone("CentralConnectionClosed : %s", serverConnection ? serverConnection->getDisconnectReason().c_str() : ""); + m_centralServerConnection = 0; //lint !e423 // object is deleted elsewhere + m_pendingCentralServerConnection = 0; //lint !e423 // object is deleted elsewhere + break; } - // advise watchers that the game server has closed its connection - ServerInfo info; - info.ipAddress = gameServer->getRemoteAddress(); - info.serverId = id; - info.systemPid = gameServer->getOsProcessId(); - GameServerStatus statusMsg(false, info); - std::vector::iterator w; - std::vector::iterator begin = m_watchers.begin(); - std::vector::iterator end = m_watchers.end(); - - for(w = begin; w != end; ++w) + case constcrc("GameConnectionClosed") : { - (*w)->send(statusMsg, true); - } + GameServerConnection *gameServer=const_cast(dynamic_cast(&source)); + std::set::iterator f = m_pendingGameServerDisconnects.find(gameServer); - if (m_firstGameServer == id) - { - if (m_gameServers.size() == 0) - m_firstGameServer = 0; + WARNING_DEBUG_FATAL(gameServer==0,("Source was nullptr or source was not a GameServerConnection.")); + DEBUG_REPORT_LOG(true, ("removing crashed gameserver\n")); + uint32 id = gameServer->getProcessId(); + GameServerMapType::iterator i=m_gameServers.find(id); + if (i!=m_gameServers.end()) + { + delete i->second; + m_gameServers.erase(i); + } + + // must call this before removeGameServer() to get the preload number + // for the dead game server; we'll need that in order to start a replacement + PreloadServerId preloadServerId = PreloadManager::getInstance().getPreloadServerId(id); + + // if the game server hadn't gotten far enough to be assigned a preload + // number, use the preload number that was assigned to it when it was started + if (preloadServerId == 0) + preloadServerId = gameServer->getPreloadNumber(); + + PreloadManager::getInstance().removeGameServer(id); + if(f == m_pendingGameServerDisconnects.end()) + { + std::set startGameServerList; + IGNORE_RETURN(startGameServerList.insert(preloadServerId)); + + startGameServer(startGameServerList, ConfigPlanetServer::getGameServerRestartDelayTimeSeconds()); + } else { - GameServerMapType::const_iterator j=m_gameServers.begin(); - m_firstGameServer = j->first; - FirstPlanetGameServerIdMessage const msg(m_firstGameServer); - for (; j!=m_gameServers.end(); ++j) - j->second->getConnection()->send(msg, true); + m_pendingGameServerDisconnects.erase(f); } - } - PreloadFinishedMessage const preloadFinishedMessage(PreloadManager::getInstance().isPreloadComplete()); - sendToCentral(preloadFinishedMessage, true); - } + // advise watchers that the game server has closed its connection + ServerInfo info; + info.ipAddress = gameServer->getRemoteAddress(); + info.serverId = id; + info.systemPid = gameServer->getOsProcessId(); + GameServerStatus statusMsg(false, info); + std::vector::iterator w; + std::vector::iterator begin = m_watchers.begin(); + std::vector::iterator end = m_watchers.end(); - else if(message.isType("GameGameServerConnect")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GameGameServerConnect msg(ri); - GameServerConnection * conn = const_cast(safe_cast(&source)); - - std::map >::iterator f = m_startingGameServers->find(msg.getSpawnCookie()); - if(f != m_startingGameServers->end()) - m_startingGameServers->erase(f); - - uint32 id = msg.getProcessId(); - m_gameServers[id]=new GameServerData(conn); - conn->setProcessId(id); - conn->setPreloadNumber(msg.getPreloadNumber()); - LOG("PlanetServerConnections",("Game Server %lu (preload %d) connected on scene %s. m_startingGameServers is now %i", id, msg.getPreloadNumber(), ConfigPlanetServer::getSceneID(),m_startingGameServers->size())); - - DEBUG_REPORT_LOG(true,("Game Server %lu (preload %d) connected on scene %s.\n", id, msg.getPreloadNumber(), ConfigPlanetServer::getSceneID())); - - ServerInfo info; - info.ipAddress = conn->getRemoteAddress(); - info.serverId = id; - info.systemPid = conn->getOsProcessId(); - GameServerStatus statusMsg(true, info); - std::vector::iterator i; - std::vector::iterator begin = m_watchers.begin(); - std::vector::iterator end = m_watchers.end(); - - for(i = begin; i != end; ++i) - { - (*i)->send(statusMsg, true); - } - - if (m_firstGameServer == 0) - { - WARNING_STRICT_FATAL(m_gameServers.size() > 1, ("m_firstGameServer was not set but there were Game Server connections in the list.")); - m_firstGameServer = id; - } - - FirstPlanetGameServerIdMessage const fpgsim(m_firstGameServer); - conn->send(fpgsim, true); - } - else if(message.isType("GameServerReadyMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - const GameServerReadyMessage msg(ri); - - GameServerConnection * conn = const_cast(dynamic_cast(&source)); - if (conn) - { - uint32 id = conn->getProcessId(); - GameServerMapType::iterator mapIter = m_gameServers.find(id); - if (mapIter==m_gameServers.end()) + for(w = begin; w != end; ++w) { - WARNING_STRICT_FATAL(true,("GameServer %lu wasn't in the map, but we got GameServerReadyMessage from it.",id)); - return; - } - Scene::getInstance().setMapSize(msg.getMapWidth()); - mapIter->second->ready(); - } - } - else if(message.isType("GameServerUniverseLoadedMessage")) - { - GameServerConnection * conn = const_cast(dynamic_cast(&source)); - if (conn) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - const GameServerUniverseLoadedMessage msg(ri); - - uint32 id = conn->getProcessId(); - LOG("PlanetServerConnections", ("Game Server %lu (preload %d) has loaded the universe objects.", conn->getProcessId(), conn->getPreloadNumber())); - - GameServerMapType::iterator mapIter = m_gameServers.find(id); - WARNING_STRICT_FATAL(mapIter==m_gameServers.end(),("GameServer %s wasn't in the map, but we got UniverseLoadedMessage from it.",id)); - if (mapIter==m_gameServers.end()) - return; - mapIter->second->universeLoaded(); - if(! PreloadManager::getInstance().onGameServerReady(id, static_cast(conn->getPreloadNumber()))) - { - m_pendingGameServerDisconnects.insert(conn); - conn->disconnect(); - } - } - flushWaitingMessages(); - } - else if (message.isType("PreloadRequestCompleteMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - const PreloadRequestCompleteMessage msg(ri); - - PreloadManager::getInstance().preloadCompleteOnServer(msg.getGameServerId()); - GameServerData *data = getGameServerData(msg.getGameServerId()); - if (data) - data->preloadComplete(); - } - else if (message.isType("RequestGameServerForLoginMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - const RequestGameServerForLoginMessage *msg = new RequestGameServerForLoginMessage(ri); - - handleRequestGameServerForLoginMessage(msg); //this function handles memory management for msg. msg is INVALID after this call. - msg = 0; - } - else if (message.isType("RequestSceneTransfer")) - { - //This message comes from Central in response to a GameServer sending central a request scene transfer message. - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - RequestSceneTransfer const *msg = new RequestSceneTransfer(ri); - - handleRequestSceneTransfer(msg); //this function handles memory management for msg. msg is INVALID after this call. - msg = 0; - } - else if (message.isType("ChunkCompleteMessage")) - { - GameServerConnection * conn = const_cast(dynamic_cast(&source)); - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - ChunkCompleteMessage msg(ri); - handleChunkComplete(msg, conn); - } - else if (message.isType("WatcherConnectionOpened")) - { - WatcherConnection *newConn = const_cast(dynamic_cast(&source)); - if (newConn) - { - // advertise status of all game servers to new watcher - GameServerMapType::iterator i; - GameServerMapType::iterator begin = m_gameServers.begin(); - GameServerMapType::iterator end = m_gameServers.end(); - for(i = begin; i != end; ++i) - { - ServerInfo info; - info.ipAddress = (*i).second->getConnection()->getRemoteAddress(); - info.serverId = (*i).second->getConnection()->getProcessId(); - info.systemPid = (*i).second->getConnection()->getOsProcessId(); - info.sceneId = ConfigPlanetServer::getSceneID(); - GameServerStatus const status(true, info); - newConn->send(status, true); + (*w)->send(statusMsg, true); } - if (static_cast(m_watchers.size() + 1) > ConfigPlanetServer::getMaxWatcherConnections()) + if (m_firstGameServer == id) { - DEBUG_REPORT_LOG(true,("Dropping previous watcher connection.\n")); - WARNING_DEBUG_FATAL(m_watchers.size()==0,("MaxWatcherConnections must be at least 1.")); - m_watchers[0]->disconnect(); - } - m_watchers.push_back(newConn); - m_watcherIsPresent=true; - Scene::getInstance().outputStatus(*newConn); - } - else - WARNING_STRICT_FATAL(true,("Got WatcherConnectionOpened from something that wasn't a WatcherConnection.")); - } - else if (message.isType("WatcherConnectionClosed")) - { - for (WatcherList::iterator i=m_watchers.begin(); i!= m_watchers.end(); ) - { - if ((*i)==&source) - i=m_watchers.erase(i); - else - ++i; - } - if (m_watchers.empty()) - { - m_watcherIsPresent=false; - DEBUG_REPORT_LOG(true,("No more watchers connected.\n")); - } - } - else if (message.isType("TaskConnectionOpened")) - { - std::set startGameServerList; - startGameServer(startGameServerList, 0); // flush any pending game server start requests - } - else if(message.isType("ProfilerOperationMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - ProfilerOperationMessage msg(ri); - unsigned int processId = msg.getProcessId(); - if (!processId) - Profiler::handleOperation(msg.getOperation().c_str()); - } - else if(message.isType("FrameEndMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - FrameEndMessage const msg(ri); - for (WatcherList::const_iterator i = m_watchers.begin(); i != m_watchers.end(); ++i) - (*i)->send(msg, true); - } - else if (message.isType("UnloadedPlayerMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - UnloadedPlayerMessage msg(ri); - - GameServerConnection *gameServer=const_cast(dynamic_cast(&source)); - WARNING_DEBUG_FATAL(gameServer==0,("Source was nullptr or source was not a GameServerConnection.")); - uint32 gameServerId = gameServer->getProcessId(); - - (*m_pendingCharacterSaves)[msg.getPlayerId()]=gameServerId; - } - else if (message.isType("PersistedPlayerMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - PersistedPlayerMessage msg(ri); - - m_pendingCharacterSaves->erase(msg.getPlayerId()); - } - else if (message.isType("ExcommunicateGameServerMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - ExcommunicateGameServerMessage msg(ri); - - LOG("GameGameConnect",("Planet Server %s was told to drop connection to %lu by Central",Scene::getInstance().getSceneId().c_str(),msg.getServerId())); - - GameServerConnection *conn =getGameServerConnection(msg.getServerId()); - if (conn) - conn->disconnect(); - } - else if (message.isType("FactionalSystemMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - FactionalSystemMessage msg(ri); - - // forward message to all game servers on this planet for processing - for (GameServerMapType::iterator i = m_gameServers.begin(); i != m_gameServers.end(); ++i) - (*i).second->getConnection()->send(msg, true); - } - else if (message.isType("MessageToPlayersOnPlanet")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage >, std::pair >, std::pair > > const msg(ri); - - // forward message to all game servers on this planet for processing - for (GameServerMapType::iterator i = m_gameServers.begin(); i != m_gameServers.end(); ++i) - (*i).second->getConnection()->send(msg, true); - } - else if (message.isType("RequestSameServer")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage > msg(ri); - - bool result=Scene::getInstance().requestSameServer(msg.getValue().first, msg.getValue().second); - - GameServerConnection * const gameServer = const_cast(dynamic_cast(&source)); - - if (gameServer) - { - GenericValueTypeMessage const rssReply("RequestSameServerReply", result); - gameServer->send(rssReply, true); - } - } - else if (message.isType("RequestAuthTransfer")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage > msg(ri); - - bool result=Scene::getInstance().requestAuthTransfer(msg.getValue().first, msg.getValue().second); - - GameServerConnection * const gameServer = const_cast(dynamic_cast(&source)); - - if (gameServer) - { - GenericValueTypeMessage const ratReply("RequestAuthTransferReply", result); - gameServer->send(ratReply, true); - } - } - else if (message.isType("GameServerForceChangeAuthorityMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GameServerForceChangeAuthorityMessage msg(ri); - GameServerData * fromServer = PlanetServer::getGameServerData(msg.getFromProcess()); - GameServerData * toServer = PlanetServer::getGameServerData(msg.getToProcess()); - PlanetProxyObject * object = Scene::getInstance().findObjectByID(msg.getId()); - if (fromServer == nullptr || toServer == nullptr || object == nullptr) - { - if (fromServer == nullptr) - { - WARNING(true, ("Message GameServerForceChangeAuthorityMessage: no " - "from server %lu", msg.getFromProcess())); - } - if (toServer == nullptr) - { - WARNING(true, ("Message GameServerForceChangeAuthorityMessage: no " - "to server %lu", msg.getToProcess())); - } - if (object == nullptr) - { - WARNING(true, ("Message GameServerForceChangeAuthorityMessage: no " - "object for id %s", msg.getId().getValueString().c_str())); - } - } - else if (Scene::getInstance().getGameServerForObject(msg.getId()) != msg.getFromProcess()) - { - WARNING(true, ("Message GameServerForceChangeAuthorityMessage: object " - "%s was supposed to be on process %lu, but we think it is on %lu", - msg.getId().getValueString().c_str(), msg.getFromProcess(), - Scene::getInstance().getGameServerForObject(msg.getId()))); - } - else - { - object->changeAuthority(msg.getToProcess(), false, true); - } - } - else if (message.isType("FindAuthObjectResponse")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage, bool> > msg(ri); - GameServerConnection const *gameServer = dynamic_cast(&source); - NOT_NULL(gameServer); - handleFindAuthObjectResponse(msg.getValue().first.first, msg.getValue().first.second, msg.getValue().second, gameServer->getProcessId()); - } - else if (message.isType("TaskProcessDiedMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - TaskProcessDiedMessage died(ri); - // verify it was a game server - const std::string & proc = died.getProcessName(); - if(proc.find("SwgGameServer") != proc.npos) - { - // pull cookie and preload server id from the command line of the process that died - size_t start = proc.find("spawnCookie"); - size_t preloadServerIdIndex = proc.find("preloadNumber"); - if ((start != proc.npos) && (preloadServerIdIndex != proc.npos)) - { - start += std::string("spawnCookie=").length(); - size_t end = proc.find(' ', start); - std::string cookieName = proc.substr(start, end); - int i = atoi(cookieName.c_str()); - std::map >::iterator f = m_startingGameServers->find(i); - if(f != m_startingGameServers->end()) - { - m_startingGameServers->erase(f); - - preloadServerIdIndex += std::string("preloadNumber=").length(); - end = proc.find(' ', preloadServerIdIndex); - std::string preloadServerIdStr = proc.substr(preloadServerIdIndex, end); - PreloadServerId preloadServerId = static_cast(atoi(preloadServerIdStr.c_str())); - - std::set startGameServerList; - IGNORE_RETURN(startGameServerList.insert(preloadServerId)); - - startGameServer(startGameServerList, ConfigPlanetServer::getGameServerRestartDelayTimeSeconds()); - - LOG("TaskProcessDied", ("TaskManager advises the PlanetServer that a GameServer %u for scene %s started with cookie %i is no longer running", preloadServerId, ConfigPlanetServer::getSceneID(), i)); - } - } - } - } - else if (message.isType ("LocationRequest")) - { - Archive::ReadIterator readIterator = static_cast (message).getByteStream ().begin (); - - //-- received a location request message - LocationRequest const locationRequest (readIterator); - - //-- ask the location manager if the location is valid - float x = locationRequest.getSearchX (); - float z = locationRequest.getSearchZ (); - bool const valid = LocationManager::requestLocation (x, z, locationRequest.getSearchRadius (), locationRequest.getLocationReservationRadius (), locationRequest.getCheckWater (), locationRequest.getCheckSlope (), x, z); - - //-- sent result back to gameserver that requested it - LocationResponse const locationResponse (locationRequest.getNetworkId (), valid, locationRequest.getLocationId (), x, z, locationRequest.getLocationReservationRadius ()); - PlanetServer::getInstance ().sendToGameServer (locationRequest.getProcessId (), locationResponse); - } - else if (message.isType ("DatabaseSaveComplete")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage msg(ri); - handleDatabaseSaveComplete(msg.getValue()); - } - else if (message.isType("LocateStructureMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - LocateStructureMessage msg(ri); - LoadStructureMessage lsm(msg.getStructureId(), msg.getWhoRequested()); - - uint32 gameServerId = Scene::getInstance().findNodeByPosition(msg.getX(), msg.getZ())->getPreferredServer(); - PlanetServer::getInstance().sendToGameServer(gameServerId, lsm); - } - else if (message.isType("DenySetAuthoritativeMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage > const msg(ri); - - // restore the authority of the object - PlanetProxyObject *object = Scene::getInstance().findObjectByID(msg.getValue().first); - if (object) - { - if (ConfigPlanetServer::getLogObjectLoading()) - LOG("ObjectLoading", - ("Set authoritative denied by game server: restoring authority for object %s to server %lu", - msg.getValue().first.getValueString().c_str(),msg.getValue().second)); - - object->restoreAuthority(msg.getValue().second); - } - } - else if (message.isType("RestartServerMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - RestartServerMessage const msg(ri); - - Node const * const node = Scene::getInstance().findNodeByPositionConst(msg.getX(), msg.getZ()); - uint32 const serverId = NON_NULL(node)->getPreferredServer(); - - if (serverId != 0) - { - ExcommunicateGameServerMessage exmsg(serverId, 0, ""); - sendToCentral(exmsg, true); - } - } - else if (message.isType("SAMGS")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage const startAnyMissingGameServer(ri); - UNREF(startAnyMissingGameServer); - - LOG("PlanetServer", ("startanymissinggameserver:Planet %s checking for any game servers that are not started, and starting them.", Scene::getInstance().getSceneId().c_str())); - if (m_centralServerConnection) - { - // if it's been "awhile" since we requested to restart the GameServer, - // then assume that something has gone wrong, and try the restart again - time_t const timeNow = ::time(nullptr); - - for (std::map >::iterator iter = m_startingGameServers->begin(); iter != m_startingGameServers->end(); ++iter) - { - if ((iter->second.second + static_cast(ConfigPlanetServer::getMaxTimeToWaitForGameServerStartSeconds())) < timeNow) - { - LOG("CentralServer", ("startanymissinggameserver:Starting missing game server (%s) because it has been %s since we requested it to be started, which has exceeded the %s limit.", iter->second.first.c_str(), CalendarTime::convertSecondsToMS(static_cast(timeNow - iter->second.second)).c_str(), CalendarTime::convertSecondsToMS(static_cast(ConfigPlanetServer::getMaxTimeToWaitForGameServerStartSeconds())).c_str())); - iter->second.second = timeNow; - TaskSpawnProcess spawn("any", "SwgGameServer", iter->second.first); - m_centralServerConnection->send(spawn,true); - } + if (m_gameServers.size() == 0) + m_firstGameServer = 0; else { - LOG("PlanetServer", ("startanymissinggameserver:It's only been %s since we requested for game server (%s) to be started, and we must wait %s before we can start it again.", CalendarTime::convertSecondsToMS(static_cast(timeNow - iter->second.second)).c_str(), iter->second.first.c_str(), CalendarTime::convertSecondsToMS(static_cast(ConfigPlanetServer::getMaxTimeToWaitForGameServerStartSeconds())).c_str())); + GameServerMapType::const_iterator j=m_gameServers.begin(); + m_firstGameServer = j->first; + FirstPlanetGameServerIdMessage const msg(m_firstGameServer); + for (; j!=m_gameServers.end(); ++j) + j->second->getConnection()->send(msg, true); } } + PreloadFinishedMessage const preloadFinishedMessage(PreloadManager::getInstance().isPreloadComplete()); + sendToCentral(preloadFinishedMessage, true); + break; } - else + case constcrc("GameGameServerConnect") : { - LOG("PlanetServer", ("startanymissinggameserver:Planet %s ignoring request because there is no central server connection.", Scene::getInstance().getSceneId().c_str())); - } - } - else if (message.isType("RestartServerByRoleMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage > msg(ri); + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GameGameServerConnect msg(ri); + GameServerConnection * conn = const_cast(safe_cast(&source)); - uint32 serverId = PreloadManager::getInstance().getRealServerId(msg.getValue().second); - if (serverId != 0) + std::map >::iterator f = m_startingGameServers->find(msg.getSpawnCookie()); + if(f != m_startingGameServers->end()) + m_startingGameServers->erase(f); + + uint32 id = msg.getProcessId(); + m_gameServers[id]=new GameServerData(conn); + conn->setProcessId(id); + conn->setPreloadNumber(msg.getPreloadNumber()); + LOG("PlanetServerConnections",("Game Server %lu (preload %d) connected on scene %s. m_startingGameServers is now %i", id, msg.getPreloadNumber(), ConfigPlanetServer::getSceneID(),m_startingGameServers->size())); + + DEBUG_REPORT_LOG(true,("Game Server %lu (preload %d) connected on scene %s.\n", id, msg.getPreloadNumber(), ConfigPlanetServer::getSceneID())); + + ServerInfo info; + info.ipAddress = conn->getRemoteAddress(); + info.serverId = id; + info.systemPid = conn->getOsProcessId(); + GameServerStatus statusMsg(true, info); + std::vector::iterator i; + std::vector::iterator begin = m_watchers.begin(); + std::vector::iterator end = m_watchers.end(); + + for(i = begin; i != end; ++i) + { + (*i)->send(statusMsg, true); + } + + if (m_firstGameServer == 0) + { + WARNING_STRICT_FATAL(m_gameServers.size() > 1, ("m_firstGameServer was not set but there were Game Server connections in the list.")); + m_firstGameServer = id; + } + + FirstPlanetGameServerIdMessage const fpgsim(m_firstGameServer); + conn->send(fpgsim, true); + break; + } + case constcrc("GameServerReadyMessage") : { - ExcommunicateGameServerMessage exmsg(serverId, 0, ""); - sendToCentral(exmsg, true); + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + const GameServerReadyMessage msg(ri); + + GameServerConnection * conn = const_cast(dynamic_cast(&source)); + if (conn) + { + uint32 id = conn->getProcessId(); + GameServerMapType::iterator mapIter = m_gameServers.find(id); + if (mapIter==m_gameServers.end()) + { + WARNING_STRICT_FATAL(true,("GameServer %lu wasn't in the map, but we got GameServerReadyMessage from it.",id)); + return; + } + Scene::getInstance().setMapSize(msg.getMapWidth()); + mapIter->second->ready(); + } + break; + } + case constcrc("GameServerUniverseLoadedMessage") : + { + GameServerConnection * conn = const_cast(dynamic_cast(&source)); + if (conn) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + const GameServerUniverseLoadedMessage msg(ri); + + uint32 id = conn->getProcessId(); + LOG("PlanetServerConnections", ("Game Server %lu (preload %d) has loaded the universe objects.", conn->getProcessId(), conn->getPreloadNumber())); + + GameServerMapType::iterator mapIter = m_gameServers.find(id); + WARNING_STRICT_FATAL(mapIter==m_gameServers.end(),("GameServer %s wasn't in the map, but we got UniverseLoadedMessage from it.",id)); + if (mapIter==m_gameServers.end()) + return; + mapIter->second->universeLoaded(); + if(! PreloadManager::getInstance().onGameServerReady(id, static_cast(conn->getPreloadNumber()))) + { + m_pendingGameServerDisconnects.insert(conn); + conn->disconnect(); + } + } + flushWaitingMessages(); + break; + } + case constcrc("PreloadRequestCompleteMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + const PreloadRequestCompleteMessage msg(ri); + + PreloadManager::getInstance().preloadCompleteOnServer(msg.getGameServerId()); + GameServerData *data = getGameServerData(msg.getGameServerId()); + if (data) + data->preloadComplete(); + break; + } + case constcrc("RequestGameServerForLoginMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + const RequestGameServerForLoginMessage *msg = new RequestGameServerForLoginMessage(ri); + + handleRequestGameServerForLoginMessage(msg); //this function handles memory management for msg. msg is INVALID after this call. + msg = 0; + break; + } + case constcrc("RequestSceneTransfer") : + { + //This message comes from Central in response to a GameServer sending central a request scene transfer message. + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + RequestSceneTransfer const *msg = new RequestSceneTransfer(ri); + + handleRequestSceneTransfer(msg); //this function handles memory management for msg. msg is INVALID after this call. + msg = 0; + break; + } + case constcrc("ChunkCompleteMessage") : + { + GameServerConnection * conn = const_cast(dynamic_cast(&source)); + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + ChunkCompleteMessage msg(ri); + handleChunkComplete(msg, conn); + break; + } + case constcrc("WatcherConnectionOpened") : + { + WatcherConnection *newConn = const_cast(dynamic_cast(&source)); + if (newConn) + { + // advertise status of all game servers to new watcher + GameServerMapType::iterator i; + GameServerMapType::iterator begin = m_gameServers.begin(); + GameServerMapType::iterator end = m_gameServers.end(); + for(i = begin; i != end; ++i) + { + ServerInfo info; + info.ipAddress = (*i).second->getConnection()->getRemoteAddress(); + info.serverId = (*i).second->getConnection()->getProcessId(); + info.systemPid = (*i).second->getConnection()->getOsProcessId(); + info.sceneId = ConfigPlanetServer::getSceneID(); + GameServerStatus const status(true, info); + newConn->send(status, true); + } + + if (static_cast(m_watchers.size() + 1) > ConfigPlanetServer::getMaxWatcherConnections()) + { + DEBUG_REPORT_LOG(true,("Dropping previous watcher connection.\n")); + WARNING_DEBUG_FATAL(m_watchers.size()==0,("MaxWatcherConnections must be at least 1.")); + m_watchers[0]->disconnect(); + } + m_watchers.push_back(newConn); + m_watcherIsPresent=true; + Scene::getInstance().outputStatus(*newConn); + } + else + WARNING_STRICT_FATAL(true,("Got WatcherConnectionOpened from something that wasn't a WatcherConnection.")); + + break; + } + case constcrc("WatcherConnectionClosed") : + { + for (WatcherList::iterator i=m_watchers.begin(); i!= m_watchers.end(); ) + { + if ((*i)==&source) + i=m_watchers.erase(i); + else + ++i; + } + if (m_watchers.empty()) + { + m_watcherIsPresent=false; + DEBUG_REPORT_LOG(true,("No more watchers connected.\n")); + } + break; + } + case constcrc("TaskConnectionOpened") : + { + std::set startGameServerList; + startGameServer(startGameServerList, 0); // flush any pending game server start requests + break; + } + case constcrc("ProfilerOperationMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + ProfilerOperationMessage msg(ri); + unsigned int processId = msg.getProcessId(); + if (!processId) + Profiler::handleOperation(msg.getOperation().c_str()); + + break; + } + case constcrc("FrameEndMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + FrameEndMessage const msg(ri); + for (WatcherList::const_iterator i = m_watchers.begin(); i != m_watchers.end(); ++i) + (*i)->send(msg, true); + break; + } + case constcrc("UnloadedPlayerMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + UnloadedPlayerMessage msg(ri); + + GameServerConnection *gameServer=const_cast(dynamic_cast(&source)); + WARNING_DEBUG_FATAL(gameServer==0,("Source was nullptr or source was not a GameServerConnection.")); + uint32 gameServerId = gameServer->getProcessId(); + + (*m_pendingCharacterSaves)[msg.getPlayerId()]=gameServerId; + break; + } + case constcrc("PersistedPlayerMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + PersistedPlayerMessage msg(ri); + + m_pendingCharacterSaves->erase(msg.getPlayerId()); + break; + } + case constcrc("ExcommunicateGameServerMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + ExcommunicateGameServerMessage msg(ri); + + LOG("GameGameConnect",("Planet Server %s was told to drop connection to %lu by Central",Scene::getInstance().getSceneId().c_str(),msg.getServerId())); + + GameServerConnection *conn =getGameServerConnection(msg.getServerId()); + if (conn) + conn->disconnect(); + break; + } + case constcrc("FactionalSystemMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + FactionalSystemMessage msg(ri); + + // forward message to all game servers on this planet for processing + for (GameServerMapType::iterator i = m_gameServers.begin(); i != m_gameServers.end(); ++i) + (*i).second->getConnection()->send(msg, true); + break; + } + case constcrc("MessageToPlayersOnPlanet") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage >, std::pair >, std::pair > > const msg(ri); + + // forward message to all game servers on this planet for processing + for (GameServerMapType::iterator i = m_gameServers.begin(); i != m_gameServers.end(); ++i) + (*i).second->getConnection()->send(msg, true); + break; + } + case constcrc("RequestSameServer") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage > msg(ri); + + bool result=Scene::getInstance().requestSameServer(msg.getValue().first, msg.getValue().second); + + GameServerConnection * const gameServer = const_cast(dynamic_cast(&source)); + + if (gameServer) + { + GenericValueTypeMessage const rssReply("RequestSameServerReply", result); + gameServer->send(rssReply, true); + } + break; + } + case constcrc("RequestAuthTransfer") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage > msg(ri); + + bool result=Scene::getInstance().requestAuthTransfer(msg.getValue().first, msg.getValue().second); + + GameServerConnection * const gameServer = const_cast(dynamic_cast(&source)); + + if (gameServer) + { + GenericValueTypeMessage const ratReply("RequestAuthTransferReply", result); + gameServer->send(ratReply, true); + } + break; + } + case constcrc("GameServerForceChangeAuthorityMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GameServerForceChangeAuthorityMessage msg(ri); + GameServerData * fromServer = PlanetServer::getGameServerData(msg.getFromProcess()); + GameServerData * toServer = PlanetServer::getGameServerData(msg.getToProcess()); + PlanetProxyObject * object = Scene::getInstance().findObjectByID(msg.getId()); + if (fromServer == nullptr || toServer == nullptr || object == nullptr) + { + if (fromServer == nullptr) + { + WARNING(true, ("Message GameServerForceChangeAuthorityMessage: no " + "from server %lu", msg.getFromProcess())); + } + if (toServer == nullptr) + { + WARNING(true, ("Message GameServerForceChangeAuthorityMessage: no " + "to server %lu", msg.getToProcess())); + } + if (object == nullptr) + { + WARNING(true, ("Message GameServerForceChangeAuthorityMessage: no " + "object for id %s", msg.getId().getValueString().c_str())); + } + } + else if (Scene::getInstance().getGameServerForObject(msg.getId()) != msg.getFromProcess()) + { + WARNING(true, ("Message GameServerForceChangeAuthorityMessage: object " + "%s was supposed to be on process %lu, but we think it is on %lu", + msg.getId().getValueString().c_str(), msg.getFromProcess(), + Scene::getInstance().getGameServerForObject(msg.getId()))); + } + else + { + object->changeAuthority(msg.getToProcess(), false, true); + } + break; + } + case constcrc("FindAuthObjectResponse") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage, bool> > msg(ri); + GameServerConnection const *gameServer = dynamic_cast(&source); + NOT_NULL(gameServer); + handleFindAuthObjectResponse(msg.getValue().first.first, msg.getValue().first.second, msg.getValue().second, gameServer->getProcessId()); + break; + } + case constcrc("TaskProcessDiedMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + TaskProcessDiedMessage died(ri); + // verify it was a game server + const std::string & proc = died.getProcessName(); + if(proc.find("SwgGameServer") != proc.npos) + { + // pull cookie and preload server id from the command line of the process that died + size_t start = proc.find("spawnCookie"); + size_t preloadServerIdIndex = proc.find("preloadNumber"); + if ((start != proc.npos) && (preloadServerIdIndex != proc.npos)) + { + start += std::string("spawnCookie=").length(); + size_t end = proc.find(' ', start); + std::string cookieName = proc.substr(start, end); + int i = atoi(cookieName.c_str()); + std::map >::iterator f = m_startingGameServers->find(i); + if(f != m_startingGameServers->end()) + { + m_startingGameServers->erase(f); + + preloadServerIdIndex += std::string("preloadNumber=").length(); + end = proc.find(' ', preloadServerIdIndex); + std::string preloadServerIdStr = proc.substr(preloadServerIdIndex, end); + PreloadServerId preloadServerId = static_cast(atoi(preloadServerIdStr.c_str())); + + std::set startGameServerList; + IGNORE_RETURN(startGameServerList.insert(preloadServerId)); + + startGameServer(startGameServerList, ConfigPlanetServer::getGameServerRestartDelayTimeSeconds()); + + LOG("TaskProcessDied", ("TaskManager advises the PlanetServer that a GameServer %u for scene %s started with cookie %i is no longer running", preloadServerId, ConfigPlanetServer::getSceneID(), i)); + } + } + } + break; + } + case constcrc("LocationRequest") : + { + Archive::ReadIterator readIterator = static_cast (message).getByteStream ().begin (); + + //-- received a location request message + LocationRequest const locationRequest (readIterator); + + //-- ask the location manager if the location is valid + float x = locationRequest.getSearchX (); + float z = locationRequest.getSearchZ (); + bool const valid = LocationManager::requestLocation (x, z, locationRequest.getSearchRadius (), locationRequest.getLocationReservationRadius (), locationRequest.getCheckWater (), locationRequest.getCheckSlope (), x, z); + + //-- sent result back to gameserver that requested it + LocationResponse const locationResponse (locationRequest.getNetworkId (), valid, locationRequest.getLocationId (), x, z, locationRequest.getLocationReservationRadius ()); + PlanetServer::getInstance ().sendToGameServer (locationRequest.getProcessId (), locationResponse); + break; + } + case constcrc("DatabaseSaveComplete") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage msg(ri); + handleDatabaseSaveComplete(msg.getValue()); + break; + } + case constcrc("LocateStructureMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + LocateStructureMessage msg(ri); + LoadStructureMessage lsm(msg.getStructureId(), msg.getWhoRequested()); + + uint32 gameServerId = Scene::getInstance().findNodeByPosition(msg.getX(), msg.getZ())->getPreferredServer(); + PlanetServer::getInstance().sendToGameServer(gameServerId, lsm); + break; + } + case constcrc("DenySetAuthoritativeMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage > const msg(ri); + + // restore the authority of the object + PlanetProxyObject *object = Scene::getInstance().findObjectByID(msg.getValue().first); + if (object) + { + if (ConfigPlanetServer::getLogObjectLoading()) + LOG("ObjectLoading", + ("Set authoritative denied by game server: restoring authority for object %s to server %lu", + msg.getValue().first.getValueString().c_str(),msg.getValue().second)); + + object->restoreAuthority(msg.getValue().second); + } + break; + } + case constcrc("RestartServerMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + RestartServerMessage const msg(ri); + + Node const * const node = Scene::getInstance().findNodeByPositionConst(msg.getX(), msg.getZ()); + uint32 const serverId = NON_NULL(node)->getPreferredServer(); + + if (serverId != 0) + { + ExcommunicateGameServerMessage exmsg(serverId, 0, ""); + sendToCentral(exmsg, true); + } + break; + } + case constcrc("SAMGS") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage const startAnyMissingGameServer(ri); + UNREF(startAnyMissingGameServer); + + LOG("PlanetServer", ("startanymissinggameserver:Planet %s checking for any game servers that are not started, and starting them.", Scene::getInstance().getSceneId().c_str())); + if (m_centralServerConnection) + { + // if it's been "awhile" since we requested to restart the GameServer, + // then assume that something has gone wrong, and try the restart again + time_t const timeNow = ::time(nullptr); + + for (std::map >::iterator iter = m_startingGameServers->begin(); iter != m_startingGameServers->end(); ++iter) + { + if ((iter->second.second + static_cast(ConfigPlanetServer::getMaxTimeToWaitForGameServerStartSeconds())) < timeNow) + { + LOG("CentralServer", ("startanymissinggameserver:Starting missing game server (%s) because it has been %s since we requested it to be started, which has exceeded the %s limit.", iter->second.first.c_str(), CalendarTime::convertSecondsToMS(static_cast(timeNow - iter->second.second)).c_str(), CalendarTime::convertSecondsToMS(static_cast(ConfigPlanetServer::getMaxTimeToWaitForGameServerStartSeconds())).c_str())); + iter->second.second = timeNow; + TaskSpawnProcess spawn("any", "SwgGameServer", iter->second.first); + m_centralServerConnection->send(spawn,true); + } + else + { + LOG("PlanetServer", ("startanymissinggameserver:It's only been %s since we requested for game server (%s) to be started, and we must wait %s before we can start it again.", CalendarTime::convertSecondsToMS(static_cast(timeNow - iter->second.second)).c_str(), iter->second.first.c_str(), CalendarTime::convertSecondsToMS(static_cast(ConfigPlanetServer::getMaxTimeToWaitForGameServerStartSeconds())).c_str())); + } + } + } + else + { + LOG("PlanetServer", ("startanymissinggameserver:Planet %s ignoring request because there is no central server connection.", Scene::getInstance().getSceneId().c_str())); + } + break; + } + case constcrc("RestartServerByRoleMessage") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage > msg(ri); + + uint32 serverId = PreloadManager::getInstance().getRealServerId(msg.getValue().second); + if (serverId != 0) + { + ExcommunicateGameServerMessage exmsg(serverId, 0, ""); + sendToCentral(exmsg, true); + } + break; } } } diff --git a/engine/server/application/PlanetServer/src/shared/Scene.cpp b/engine/server/application/PlanetServer/src/shared/Scene.cpp index 1744d75e..5295173b 100755 --- a/engine/server/application/PlanetServer/src/shared/Scene.cpp +++ b/engine/server/application/PlanetServer/src/shared/Scene.cpp @@ -23,6 +23,8 @@ #include "sharedNetworkMessages/GenericValueTypeMessage.h" #include "sharedUtility/LocationManager.h" +#include "sharedFoundation/CrcConstexpr.hpp" + // ====================================================================== Scene::Scene() : @@ -96,95 +98,104 @@ void Scene::receiveMessage(const MessageDispatch::Emitter & source, const Messag const GameServerConnection *gameServer=dynamic_cast(&source); WARNING_DEBUG_FATAL(gameServer==0,("Source was nullptr or source was not a GameServerConnection.")); - if (message.isType("GameConnectionClosed")) - { - DEBUG_REPORT_LOG(true, ("Handling a game server crash for server %lu\n", gameServer->getProcessId())); - handleCrash(gameServer->getProcessId()); - } - - else if (message.isType("UpdateObjectOnPlanetMessage")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - UpdateObjectOnPlanetMessage msg(ri); - - int interestRadius = msg.getInterestRadius(); - - if(msg.getWatched() && interestRadius == 0) - interestRadius = 1; - - if (m_deletedObjects.find(msg.getObjectId())!=m_deletedObjects.end()) + const uint32 messageType = message.getType(); + + switch(messageType) { + case constcrc("GameConnectionClosed") : { - DEBUG_REPORT_LOG(true,("Ignoring update for object %s which has been removed.\n",msg.getObjectId().getValueString().c_str())); + DEBUG_REPORT_LOG(true, ("Handling a game server crash for server %lu\n", gameServer->getProcessId())); + handleCrash(gameServer->getProcessId()); + break; } - else + case constcrc("UpdateObjectOnPlanetMessage") : { - NetworkId container(msg.getTopmostContainer()); - if (container==msg.getObjectId()) // game server sends container == objectId if the object is not contained - container=NetworkId::cms_invalid; + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + UpdateObjectOnPlanetMessage msg(ri); - bool processUpdate = true; - if (container != NetworkId::cms_invalid) + int interestRadius = msg.getInterestRadius(); + + if(msg.getWatched() && interestRadius == 0) + interestRadius = 1; + + if (m_deletedObjects.find(msg.getObjectId())!=m_deletedObjects.end()) { - PlanetProxyObject const *const containerObject = findObjectByID(container); - if (containerObject) + DEBUG_REPORT_LOG(true,("Ignoring update for object %s which has been removed.\n",msg.getObjectId().getValueString().c_str())); + } + else + { + NetworkId container(msg.getTopmostContainer()); + if (container==msg.getObjectId()) // game server sends container == objectId if the object is not contained + container=NetworkId::cms_invalid; + + bool processUpdate = true; + if (container != NetworkId::cms_invalid) { - if (containerObject->getAuthoritativeServer() != gameServer->getProcessId()) + PlanetProxyObject const *const containerObject = findObjectByID(container); + if (containerObject) { - // This update message came from a server that is not - // authoritative for the container of this object. This - // can happen when the planet server is in control of - // switching the container's authority but is not in - // charge of changing the container content's authority. - // This happens to the rider of a mount when the mount - // switches authority. - processUpdate = false; + if (containerObject->getAuthoritativeServer() != gameServer->getProcessId()) + { + // This update message came from a server that is not + // authoritative for the container of this object. This + // can happen when the planet server is in control of + // switching the container's authority but is not in + // charge of changing the container content's authority. + // This happens to the rider of a mount when the mount + // switches authority. + processUpdate = false; + } } } - } - if (processUpdate) - { - PlanetProxyObject *theObject=findObjectByID(msg.getObjectId()); - if (!theObject) + if (processUpdate) { - // this is a new object - theObject=new PlanetProxyObject(msg.getObjectId()); - addObject(theObject); + PlanetProxyObject *theObject=findObjectByID(msg.getObjectId()); + if (!theObject) + { + // this is a new object + theObject=new PlanetProxyObject(msg.getObjectId()); + addObject(theObject); + } + + theObject->onReceivedMessageFromServer(gameServer->getProcessId()); + theObject->update(msg.getX(), msg.getY(), msg.getZ(), container, gameServer->getProcessId(), interestRadius, msg.getObjectTypeTag(), msg.getLevel(), msg.getHibernating(), msg.getTemplateCrc(), msg.getAiActivity(), msg.getCreationType()); + + //-- handle updating LocationManager + if (msg.getLocationReservationRadius () > 0.f) + LocationManager::updateObject (msg.getObjectId (), msg.getX (), msg.getZ (), msg.getLocationReservationRadius ()); } - - theObject->onReceivedMessageFromServer(gameServer->getProcessId()); - theObject->update(msg.getX(), msg.getY(), msg.getZ(), container, gameServer->getProcessId(), interestRadius, msg.getObjectTypeTag(), msg.getLevel(), msg.getHibernating(), msg.getTemplateCrc(), msg.getAiActivity(), msg.getCreationType()); - - //-- handle updating LocationManager - if (msg.getLocationReservationRadius () > 0.f) - LocationManager::updateObject (msg.getObjectId (), msg.getX (), msg.getZ (), msg.getLocationReservationRadius ()); } + break; } - } - else if (message.isType("PlanetRemoveObject")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - PlanetRemoveObject msg(ri); - handleRemoveObject(msg.getObjectId()); + case constcrc("PlanetRemoveObject") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + PlanetRemoveObject msg(ri); + handleRemoveObject(msg.getObjectId()); - //-- handle updating LocationManager - LocationManager::removeObject (msg.getObjectId ()); - } - else if (message.isType("ForceLoadArea")) - { - Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); - GenericValueTypeMessage, std::pair > > > const msg(ri); + //-- handle updating LocationManager + LocationManager::removeObject (msg.getObjectId ()); + break; + } + case constcrc("ForceLoadArea") : + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + GenericValueTypeMessage, std::pair > > > const msg(ri); - handleForceLoadArea( - msg.getValue().first, - static_cast(msg.getValue().second.first.first), - static_cast(msg.getValue().second.first.second), - static_cast(msg.getValue().second.second.first), - static_cast(msg.getValue().second.second.second)); - } - else - { - DEBUG_REPORT_LOG(true,("Scene.cpp received an unidentified message.\n")); + handleForceLoadArea( + msg.getValue().first, + static_cast(msg.getValue().second.first.first), + static_cast(msg.getValue().second.first.second), + static_cast(msg.getValue().second.second.first), + static_cast(msg.getValue().second.second.second + + break; + } + default : + { + DEBUG_REPORT_LOG(true,("Scene.cpp received an unidentified message.\n")); + break; + } } }