diff --git a/engine/server/application/ChatServer/src/shared/CentralServerConnection.cpp b/engine/server/application/ChatServer/src/shared/CentralServerConnection.cpp index decda6cf..fa2dcd93 100755 --- a/engine/server/application/ChatServer/src/shared/CentralServerConnection.cpp +++ b/engine/server/application/ChatServer/src/shared/CentralServerConnection.cpp @@ -23,6 +23,8 @@ #include "sharedNetwork/Service.h" #include "UnicodeUtils.h" +#include "sharedFoundation/CrcConstexpr.hpp" + //----------------------------------------------------------------------- CentralServerConnection::CentralServerConnection(const std::string & a, const unsigned short p) : @@ -62,63 +64,73 @@ void CentralServerConnection::onReceive(const Archive::ByteStream & message) GameNetworkMessage m(ri); ri = message.begin(); + + const uint32 messageType = message.getType(); - if(m.isType("EnumerateServers")) - { - static MessageDispatch::Transceiver emitter; - - EnumerateServers e(ri); - emitter.emitMessage(e); - } - else if (m.isType("CustomerServiceServerChatServerServiceAddress")) - { - GenericValueTypeMessage > msg(ri); - - ChatServer::instance().connectToCustomerServiceServer(msg.getValue().first, msg.getValue().second); - } - else if(m.isType("RequestChatTransferAvatar")) - { - GenericValueTypeMessage request(ri); - LOG("CustomerService", ("CharacterTransfer: Received RequestChatTransferAvatar from CentralServer. Forwarding request to ChatAPI. %s", request.getValue().toString().c_str())); - ChatServer::requestTransferAvatar(request.getValue()); - } - else if (m.isType("RenameCharacterMessageEx")) - { - RenameCharacterMessageEx const msg(ri); - - // if the player requested the rename, also rename the chat - // avatar, so mail, friends list, and ignore list will migrate - if ((msg.getRenameCharacterMessageSource() == RenameCharacterMessageEx::RCMS_player_request) && !msg.getLastNameChangeOnly() && !ConfigFile::getKeyBool("CharacterRename", "disableRenameChatAvatar", false)) + switch(messageType) { + case constcrc("EnumerateServers") : { - std::string const oldName(Unicode::toLower(Unicode::wideToNarrow(msg.getOldName()))); - std::string const oldNameNormalized(oldName, 0, oldName.find(' ')); - ChatAvatarId const oldAvatar("SWG", ConfigChatServer::getClusterName(), oldNameNormalized); + static MessageDispatch::Transceiver emitter; - std::string const newName(Unicode::toLower(Unicode::wideToNarrow(msg.getNewName()))); - std::string const newNameNormalized(newName, 0, newName.find(' ')); - ChatAvatarId const newAvatar("SWG", ConfigChatServer::getClusterName(), newNameNormalized); - - IGNORE_RETURN(ChatServer::getChatInterface()->RequestTransferAvatar(msg.getStationId(), oldAvatar.getName(), oldAvatar.getAPIAddress(), msg.getStationId(), newAvatar.getName(), newAvatar.getAPIAddress(), true, nullptr)); + EnumerateServers e(ri); + emitter.emitMessage(e); + break; } - } - else if (m.isType("ChatDestroyAvatar")) - { - GenericValueTypeMessage const msg(ri); - ChatServer::getChatInterface()->DestroyAvatar(msg.getValue()); - } - else if(m.isType("AllCluserGlobalChannel")) - { - typedef std::pair, bool> PayloadType; - GenericValueTypeMessage msg(ri); + case constcrc("CustomerServiceServerChatServerServiceAddress") : + { + GenericValueTypeMessage > msg(ri); - PayloadType const & payload = msg.getValue(); - std::string const & channelName = payload.first.first; - std::string const & messageText = payload.first.second; - bool const & isRemove = payload.second; + ChatServer::instance().connectToCustomerServiceServer(msg.getValue().first, msg.getValue().second); + break; + } + else if(m.isType("RequestChatTransferAvatar")) + { + GenericValueTypeMessage request(ri); + LOG("CustomerService", ("CharacterTransfer: Received RequestChatTransferAvatar from CentralServer. Forwarding request to ChatAPI. %s", request.getValue().toString().c_str())); + ChatServer::requestTransferAvatar(request.getValue()); + break; + } + case constcrc("RenameCharacterMessageEx") : + { + RenameCharacterMessageEx const msg(ri); - LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer got AllCluserGlobalChannel on CentralServerConnection chan(%s) text(%s) remove(%d)", - channelName.c_str(), messageText.c_str(), (isRemove?1:0))); - ChatServer::requestBroadcastChannelMessage(channelName, messageText, isRemove); + // if the player requested the rename, also rename the chat + // avatar, so mail, friends list, and ignore list will migrate + if ((msg.getRenameCharacterMessageSource() == RenameCharacterMessageEx::RCMS_player_request) && !msg.getLastNameChangeOnly() && !ConfigFile::getKeyBool("CharacterRename", "disableRenameChatAvatar", false)) + { + std::string const oldName(Unicode::toLower(Unicode::wideToNarrow(msg.getOldName()))); + std::string const oldNameNormalized(oldName, 0, oldName.find(' ')); + ChatAvatarId const oldAvatar("SWG", ConfigChatServer::getClusterName(), oldNameNormalized); + + std::string const newName(Unicode::toLower(Unicode::wideToNarrow(msg.getNewName()))); + std::string const newNameNormalized(newName, 0, newName.find(' ')); + ChatAvatarId const newAvatar("SWG", ConfigChatServer::getClusterName(), newNameNormalized); + + IGNORE_RETURN(ChatServer::getChatInterface()->RequestTransferAvatar(msg.getStationId(), oldAvatar.getName(), oldAvatar.getAPIAddress(), msg.getStationId(), newAvatar.getName(), newAvatar.getAPIAddress(), true, nullptr)); + } + break; + } + case constcrc("ChatDestroyAvatar") : + { + GenericValueTypeMessage const msg(ri); + ChatServer::getChatInterface()->DestroyAvatar(msg.getValue()); + break; + } + case constcrc("AllCluserGlobalChannel") : + { + typedef std::pair, bool> PayloadType; + GenericValueTypeMessage msg(ri); + + PayloadType const & payload = msg.getValue(); + std::string const & channelName = payload.first.first; + std::string const & messageText = payload.first.second; + bool const & isRemove = payload.second; + + LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer got AllCluserGlobalChannel on CentralServerConnection chan(%s) text(%s) remove(%d)", + channelName.c_str(), messageText.c_str(), (isRemove?1:0))); + ChatServer::requestBroadcastChannelMessage(channelName, messageText, isRemove); + break; + } } }