From 004c170f05058438536698c9cf850416b4b43906 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Fri, 30 Sep 2016 10:05:32 -0500 Subject: [PATCH] . . . another one bites the dust --- .../src/shared/ConnectionServerConnection.cpp | 417 +++++++++--------- 1 file changed, 217 insertions(+), 200 deletions(-) diff --git a/engine/server/application/CentralServer/src/shared/ConnectionServerConnection.cpp b/engine/server/application/CentralServer/src/shared/ConnectionServerConnection.cpp index 1c31b191..b059e5cc 100755 --- a/engine/server/application/CentralServer/src/shared/ConnectionServerConnection.cpp +++ b/engine/server/application/CentralServer/src/shared/ConnectionServerConnection.cpp @@ -167,238 +167,255 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message) Archive::ReadIterator ri = message.begin(); GameNetworkMessage m(ri); ri = message.begin(); + + const uint32 messageType = m.getType(); - if (m.isType("NewCentralConnectionServer")) - { - const NewCentralConnectionServer ncs(ri); - - m_chatServicePort = ncs.getChatServicePort(); - m_csServicePort = ncs.getCustomerServicePort(); - - m_clientServicePortPrivate = ncs.getClientServicePortPrivate(); - m_clientServicePortPublic = ncs.getClientServicePortPublic(); - m_gameServicePort = ncs.getGameServicePort(); - m_pingPort = ncs.getPingPort(); - m_connectionServerNumber = ncs.getConnectionServerNumber(); - m_gameServiceAddress = ncs.getGameServiceAddress(); - m_clientServiceAddress = ncs.getClientServiceAddress(); - m_chatServiceAddress = ncs.getChatServiceAddress(); - m_customerServiceAddress = ncs.getCustomerServiceAddress(); - - CentralServer::getInstance().addConnectionServerConnection(this); - - //Now broadcast to gameservers - ConnectionServerAddress const addressMessage(m_gameServiceAddress, m_gameServicePort); - CentralServer::getInstance().broadcastToGameServers(addressMessage); - - //Send to chat server - const int ct = static_cast(EnumerateServers::CONNECTION_SERVER); - EnumerateServers e(true, getChatServiceAddress(), getChatServicePort(), ct); - - if (!getChatServiceAddress().empty() && (getChatServicePort() != 0)) + switch(messageType) { + case constcrc("NewCentralConnectionServer") : { - CentralServer::getInstance().broadcastToChatServers(e); + const NewCentralConnectionServer ncs(ri); + + m_chatServicePort = ncs.getChatServicePort(); + m_csServicePort = ncs.getCustomerServicePort(); + + m_clientServicePortPrivate = ncs.getClientServicePortPrivate(); + m_clientServicePortPublic = ncs.getClientServicePortPublic(); + m_gameServicePort = ncs.getGameServicePort(); + m_pingPort = ncs.getPingPort(); + m_connectionServerNumber = ncs.getConnectionServerNumber(); + m_gameServiceAddress = ncs.getGameServiceAddress(); + m_clientServiceAddress = ncs.getClientServiceAddress(); + m_chatServiceAddress = ncs.getChatServiceAddress(); + m_customerServiceAddress = ncs.getCustomerServiceAddress(); + + CentralServer::getInstance().addConnectionServerConnection(this); + + //Now broadcast to gameservers + ConnectionServerAddress const addressMessage(m_gameServiceAddress, m_gameServicePort); + CentralServer::getInstance().broadcastToGameServers(addressMessage); + + //Send to chat server + const int ct = static_cast(EnumerateServers::CONNECTION_SERVER); + EnumerateServers e(true, getChatServiceAddress(), getChatServicePort(), ct); + + if (!getChatServiceAddress().empty() && (getChatServicePort() != 0)) + { + CentralServer::getInstance().broadcastToChatServers(e); + } + else + { + LOG("ChatServ", ("ConnectionServerConnection::onReceive() Chat service address and port are invalid, unable to CentralServer::getInstance().broadcastToChatServers()")); + } + + //Send to CS servers + const EnumerateServers e2(true, getCustomerServiceAddress(), getCustomerServicePort(), ct); + + if (!getCustomerServiceAddress().empty() + && (getCustomerServicePort() != 0)) + { + CentralServer::getInstance().broadcastToCustomerServiceServers(e2); + } + else + { + LOG("ChatServ", ("ConnectionServerConnection::onReceive() Customer service address and port are invalid, unable to CentralServer::getInstance().broadcastToCustomerServiceServers()")); + } + + //Send to login Servers + if ((getClientServicePortPrivate() != 0) || (getClientServicePortPublic() != 0)) + { + const LoginConnectionServerAddress csa(m_id, getClientServiceAddress(), getClientServicePortPrivate(), + getClientServicePortPublic(), getPlayerCount(), getPingPort()); + CentralServer::getInstance().sendToAllLoginServers(csa); + } + break; } - else + case constcrc("UpdateConnectionServerStatus") : { - LOG("ChatServ", ("ConnectionServerConnection::onReceive() Chat service address and port are invalid, unable to CentralServer::getInstance().broadcastToChatServers()")); + DEBUG_REPORT_LOG(true, ("Got update status for connection server\n")); + const UpdateConnectionServerStatus ucs(ri); + m_clientServicePortPublic = ucs.getPublicPort(); + m_clientServicePortPrivate = ucs.getPrivatePort(); + UpdateLoginConnectionServerStatus ulc(getId(), m_clientServicePortPublic, m_clientServicePortPrivate, getPlayerCount()); + CentralServer::getInstance().sendToAllLoginServers(ulc); + break; } - //Send to CS servers - const EnumerateServers e2(true, getCustomerServiceAddress(), getCustomerServicePort(), ct); - - if (!getCustomerServiceAddress().empty() - && (getCustomerServicePort() != 0)) + case constcrc("TaskSpawnProcess") : { - CentralServer::getInstance().broadcastToCustomerServiceServers(e2); + const TaskSpawnProcess spawn(ri); + CentralServer::getInstance().sendTaskMessage(spawn); + break; } - else + case constcrc("NewPseudoClientConnection") : { - LOG("ChatServ", ("ConnectionServerConnection::onReceive() Customer service address and port are invalid, unable to CentralServer::getInstance().broadcastToCustomerServiceServers()")); - } + const GenericValueTypeMessage > info(ri); + s_pseudoClientConnectionMap[info.getValue().first] = std::make_pair(static_cast(info.getValue().second), this); - //Send to login Servers - if ((getClientServicePortPrivate() != 0) || (getClientServicePortPublic() != 0)) + // remove corresponding "non pseudo client connection" + CentralServer::getInstance().removeFromAccountConnectionMap(static_cast(info.getValue().first)); + break; + } + case constcrc("DestroyPseudoClientConnection") : { - const LoginConnectionServerAddress csa(m_id, getClientServiceAddress(), getClientServicePortPrivate(), - getClientServicePortPublic(), getPlayerCount(), getPingPort()); - CentralServer::getInstance().sendToAllLoginServers(csa); + const GenericValueTypeMessage info(ri); + std::map >::iterator f = s_pseudoClientConnectionMap.find(info.getValue()); + if (f != s_pseudoClientConnectionMap.end()) + { + s_pseudoClientConnectionMap.erase(f); + } + break; } - } - else if (m.isType("UpdateConnectionServerStatus")) - { - DEBUG_REPORT_LOG(true, ("Got update status for connection server\n")); - const UpdateConnectionServerStatus ucs(ri); - m_clientServicePortPublic = ucs.getPublicPort(); - m_clientServicePortPrivate = ucs.getPrivatePort(); - UpdateLoginConnectionServerStatus ulc(getId(), m_clientServicePortPublic, m_clientServicePortPrivate, getPlayerCount()); - CentralServer::getInstance().sendToAllLoginServers(ulc); - } - - else if (m.isType("TaskSpawnProcess")) - { - const TaskSpawnProcess spawn(ri); - CentralServer::getInstance().sendTaskMessage(spawn); - } - else if (m.isType("NewPseudoClientConnection")) - { - const GenericValueTypeMessage > info(ri); - s_pseudoClientConnectionMap[info.getValue().first] = std::make_pair(static_cast(info.getValue().second), this); - - // remove corresponding "non pseudo client connection" - CentralServer::getInstance().removeFromAccountConnectionMap(static_cast(info.getValue().first)); - } - else if (m.isType("DestroyPseudoClientConnection")) - { - const GenericValueTypeMessage info(ri); - std::map >::iterator f = s_pseudoClientConnectionMap.find(info.getValue()); - if (f != s_pseudoClientConnectionMap.end()) + case constcrc("TransferReceiveDataFromGameServer") : { - s_pseudoClientConnectionMap.erase(f); - } - } - else if (m.isType("TransferReceiveDataFromGameServer")) - { - const GenericValueTypeMessage transferReply(ri); + const GenericValueTypeMessage transferReply(ri); - if (transferReply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + if (transferReply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + { + CentralServer::getInstance().sendToTransferServer(transferReply); + } + else + { + LOG("CustomerService", ("CharacterTransfer: Got TransferReceiveDataFromGameServer: %s", transferReply.getValue().toString().c_str())); + + // send character to ConnectionServer for creation on the destination server + GenericValueTypeMessage login("TransferLoginCharacterToDestinationServer", transferReply.getValue()); + CentralServer::getInstance().sendToArbitraryLoginServer(login); + LOG("CustomerService", ("CharacterTransfer: Sending TransferLoginCharacterToDestinationServer to CentralServer (via LoginServer) (%s) for (%s)", transferReply.getValue().getDestinationGalaxy().c_str(), login.getValue().toString().c_str())); + } + break; + } + case constcrc("ApplyTransferDataSuccess") : { - CentralServer::getInstance().sendToTransferServer(transferReply); + const GenericValueTypeMessage success(ri); + + // send message to source galaxy (via LoginServer) to mark + // the source character as having been transferred to prevent + // all future login of the character + { + const GenericValueTypeMessage > msg("CtsCompletedForcharacter", std::make_pair(success.getValue().getSourceGalaxy(), success.getValue().getCharacterId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(msg)); + } + + // send the message back to the transfer server, which then + // sends a disable login request to the source central server, + // "removing" the account on the source galaxy. + if (success.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + { + CentralServer::getInstance().sendToTransferServer(success); + } + else + { + LOG("CustomerService", ("CharacterTransfer: Received ApplyTransferDataSuccess from ConnectionServer. %s", success.getValue().toString().c_str())); + LOG("CustomerService", ("CharacterTransfer: Sending ToggleAvatarLoginStatus request to LoginServer")); + + const ToggleAvatarLoginStatus toggleLoginStatus(success.getValue().getSourceGalaxy(), success.getValue().getSourceStationId(), success.getValue().getCharacterId(), false); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(toggleLoginStatus)); + } + break; } - else + case constcrc("ApplyTransferDataFail") : { - LOG("CustomerService", ("CharacterTransfer: Got TransferReceiveDataFromGameServer: %s", transferReply.getValue().toString().c_str())); + const GenericValueTypeMessage fail(ri); - // send character to ConnectionServer for creation on the destination server - GenericValueTypeMessage login("TransferLoginCharacterToDestinationServer", transferReply.getValue()); - CentralServer::getInstance().sendToArbitraryLoginServer(login); - LOG("CustomerService", ("CharacterTransfer: Sending TransferLoginCharacterToDestinationServer to CentralServer (via LoginServer) (%s) for (%s)", transferReply.getValue().getDestinationGalaxy().c_str(), login.getValue().toString().c_str())); + // send the message back to the transfer server, which then + // sends a delete request to the destination central server, + // "removing" the account on the destination galaxy. + if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + { + CentralServer::getInstance().sendToTransferServer(fail); + } + else + { + LOG("CustomerService", ("CharacterTransfer: Received ApplyTransferDataFail from ConnectionServer. %s", fail.getValue().toString().c_str())); + LOG("CustomerService", ("CharacterTransfer: failed to apply transfer data. Deleting character on destination server. %s", fail.getValue().toString().c_str())); + + GenericValueTypeMessage const deleteCharacter("DeleteFailedTransfer", fail.getValue()); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(deleteCharacter)); + + GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getSourceGalaxy(), fail.getValue().getSourceStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); + + GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getDestinationGalaxy(), fail.getValue().getDestinationStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); + } + break; } - } - else if (m.isType("ApplyTransferDataSuccess")) - { - const GenericValueTypeMessage success(ri); - - // send message to source galaxy (via LoginServer) to mark - // the source character as having been transferred to prevent - // all future login of the character + case constcrc("TransferCreateCharacterFailed") : { - const GenericValueTypeMessage > msg("CtsCompletedForcharacter", std::make_pair(success.getValue().getSourceGalaxy(), success.getValue().getCharacterId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(msg)); - } + const GenericValueTypeMessage fail(ri); - // send the message back to the transfer server, which then - // sends a disable login request to the source central server, - // "removing" the account on the source galaxy. - if (success.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + { + CentralServer::getInstance().sendToTransferServer(fail); + } + else + { + LOG("CustomerService", ("CharacterTransfer: Received TransferCreateCharacterFailed. %s", fail.getValue().toString().c_str())); + + GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getSourceGalaxy(), fail.getValue().getSourceStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); + + GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getDestinationGalaxy(), fail.getValue().getDestinationStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); + } + break; + } + case constcrc("ReplyTransferDataFail") : { - CentralServer::getInstance().sendToTransferServer(success); + const GenericValueTypeMessage reply(ri); + + if (reply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + { + CentralServer::getInstance().sendToTransferServer(reply); + } + else + { + LOG("CustomerService", ("CharacterTransfer: Transfer failed: Failed to retrieve character data. %s", reply.getValue().toString().c_str())); + + GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(reply.getValue().getSourceGalaxy(), reply.getValue().getSourceStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); + + GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(reply.getValue().getDestinationGalaxy(), reply.getValue().getDestinationStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); + } + break; } - else + case constcrc("TransferFailGameServerClosedConnectionWithConnectionServer") : { - LOG("CustomerService", ("CharacterTransfer: Received ApplyTransferDataSuccess from ConnectionServer. %s", success.getValue().toString().c_str())); - LOG("CustomerService", ("CharacterTransfer: Sending ToggleAvatarLoginStatus request to LoginServer")); + const GenericValueTypeMessage fail(ri); - const ToggleAvatarLoginStatus toggleLoginStatus(success.getValue().getSourceGalaxy(), success.getValue().getSourceStationId(), success.getValue().getCharacterId(), false); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(toggleLoginStatus)); + if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + { + CentralServer::getInstance().sendToTransferServer(fail); + } + else + { + LOG("CustomerService", ("CharacterTransfer: Transfer failed: GameServer connection closed while transfer was in progress. %s", fail.getValue().toString().c_str())); + + GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getSourceGalaxy(), fail.getValue().getSourceStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); + + GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getDestinationGalaxy(), fail.getValue().getDestinationStationId())); + IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); + } + break; } - } - else if (m.isType("ApplyTransferDataFail")) - { - const GenericValueTypeMessage fail(ri); - - // send the message back to the transfer server, which then - // sends a delete request to the destination central server, - // "removing" the account on the destination galaxy. - if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + case constcrc("AccountFeatureIdRequest") : { - CentralServer::getInstance().sendToTransferServer(fail); + const AccountFeatureIdRequest msg(ri); + CentralServer::getInstance().sendToArbitraryLoginServer(msg); + break; } - else + case constcrc("AdjustAccountFeatureIdRequest") : { - LOG("CustomerService", ("CharacterTransfer: Received ApplyTransferDataFail from ConnectionServer. %s", fail.getValue().toString().c_str())); - LOG("CustomerService", ("CharacterTransfer: failed to apply transfer data. Deleting character on destination server. %s", fail.getValue().toString().c_str())); - - GenericValueTypeMessage const deleteCharacter("DeleteFailedTransfer", fail.getValue()); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(deleteCharacter)); - - GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getSourceGalaxy(), fail.getValue().getSourceStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); - - GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getDestinationGalaxy(), fail.getValue().getDestinationStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); + const AdjustAccountFeatureIdRequest msg(ri); + CentralServer::getInstance().sendToArbitraryLoginServer(msg); + break; } - } - else if (m.isType("TransferCreateCharacterFailed")) - { - const GenericValueTypeMessage fail(ri); - - if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) + default : { - CentralServer::getInstance().sendToTransferServer(fail); + ServerConnection::onReceive(message); } - else - { - LOG("CustomerService", ("CharacterTransfer: Received TransferCreateCharacterFailed. %s", fail.getValue().toString().c_str())); - - GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getSourceGalaxy(), fail.getValue().getSourceStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); - - GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getDestinationGalaxy(), fail.getValue().getDestinationStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); - } - } - else if (m.isType("ReplyTransferDataFail")) - { - const GenericValueTypeMessage reply(ri); - - if (reply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) - { - CentralServer::getInstance().sendToTransferServer(reply); - } - else - { - LOG("CustomerService", ("CharacterTransfer: Transfer failed: Failed to retrieve character data. %s", reply.getValue().toString().c_str())); - - GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(reply.getValue().getSourceGalaxy(), reply.getValue().getSourceStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); - - GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(reply.getValue().getDestinationGalaxy(), reply.getValue().getDestinationStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); - } - } - else if (m.isType("TransferFailGameServerClosedConnectionWithConnectionServer")) - { - const GenericValueTypeMessage fail(ri); - - if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server) - { - CentralServer::getInstance().sendToTransferServer(fail); - } - else - { - LOG("CustomerService", ("CharacterTransfer: Transfer failed: GameServer connection closed while transfer was in progress. %s", fail.getValue().toString().c_str())); - - GenericValueTypeMessage > const closeRequestSource("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getSourceGalaxy(), fail.getValue().getSourceStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestSource)); - - GenericValueTypeMessage > const closeRequestTarget("RequestTransferClosePseudoClientConnection", std::make_pair(fail.getValue().getDestinationGalaxy(), fail.getValue().getDestinationStationId())); - IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget)); - } - } - else if (m.isType("AccountFeatureIdRequest")) - { - const AccountFeatureIdRequest msg(ri); - CentralServer::getInstance().sendToArbitraryLoginServer(msg); - } - else if (m.isType("AdjustAccountFeatureIdRequest")) - { - const AdjustAccountFeatureIdRequest msg(ri); - CentralServer::getInstance().sendToArbitraryLoginServer(msg); - } - else - { - ServerConnection::onReceive(message); } }