diff --git a/engine/server/application/CommoditiesServer/src/shared/CommodityServer.cpp b/engine/server/application/CommoditiesServer/src/shared/CommodityServer.cpp index 3c2019cd..6e00a019 100755 --- a/engine/server/application/CommoditiesServer/src/shared/CommodityServer.cpp +++ b/engine/server/application/CommoditiesServer/src/shared/CommodityServer.cpp @@ -29,6 +29,9 @@ #include "sharedNetworkMessages/GenericValueTypeMessage.h" #include "sharedLog/Log.h" #include "sharedLog/SetupSharedLog.h" + +#include "sharedFoundation/CrcConstexpr.hpp" + #include //----------------------------------------------------------------------- @@ -68,7 +71,9 @@ CommodityServer::~CommodityServer() void CommodityServer::receiveMessage(const MessageDispatch::Emitter & source, const MessageDispatch::MessageBase & message) { - if(message.isType("CommoditiesLoadDone")) + const uint32 messageType = message.getType(); + + if(messageType == constcrc("CommoditiesLoadDone")) { m_commoditiesServerLoadDone = 1; @@ -76,7 +81,7 @@ void CommodityServer::receiveMessage(const MessageDispatch::Emitter & source, co if (m_commoditiesServerLoadTime == -1) m_commoditiesServerLoadTime = (time(0) - m_timeCommoditiesServerStarted) / 60; } - else if (message.isType("DatabaseServerConnectionClosed")) + else if (messageType == constcrc("DatabaseServerConnectionClosed")) { WARNING(true, ("[Commodities Server] : No connection to the database server. Shutting down.\n")); exit(0); diff --git a/engine/server/application/CommoditiesServer/src/shared/DatabaseServerConnection.cpp b/engine/server/application/CommoditiesServer/src/shared/DatabaseServerConnection.cpp index 25b6029e..20b9a9cd 100755 --- a/engine/server/application/CommoditiesServer/src/shared/DatabaseServerConnection.cpp +++ b/engine/server/application/CommoditiesServer/src/shared/DatabaseServerConnection.cpp @@ -21,6 +21,8 @@ #include "serverNetworkMessages/GetMarketAuctionBidsMessage.h" #include "UnicodeUtils.h" +#include "sharedFoundation/CrcConstexpr.hpp" + //----------------------------------------------------------------------- DatabaseServerConnection::DatabaseServerConnection(const std::string & a, const unsigned short p) : @@ -65,151 +67,161 @@ void DatabaseServerConnection::onReceive(const Archive::ByteStream & message) Archive::ReadIterator ri = message.begin(); GameNetworkMessage msg(ri); ri = message.begin(); + + const uint32 messageType = msg.getType(); - if (msg.isType("CommoditiesLoadDone")) - { - if (currentLocationCount != lastLocationCount) + switch(messageType) { + case constcrc("CommoditiesLoadDone") : { - DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); - LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); - lastLocationCount = currentLocationCount; - } - if (currentAuctionCount != lastAuctionCount) - { - DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); - LOG("CommoditiesServer", ("%d MarketAuctions record received\n", currentAuctionCount)); - lastAuctionCount = currentAuctionCount; - } - if (currentAuctionAttributeCount != lastAuctionAttributeCount) - { - DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); - LOG("CommoditiesServer", ("%d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); - lastAuctionAttributeCount = currentAuctionAttributeCount; - } - if (currentBidCount != lastBidCount) - { - DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionBids record received\n", currentBidCount)); - LOG("CommoditiesServer", ("%d MarketAuctionBids record received", currentBidCount)); - lastBidCount = currentBidCount; - } - REPORT_LOG("DatabaseServerConnection", ("CommoditiesLoadDone Message received on connection with the database server\n")); - CommoditiesLoadDoneMessage m(ri); - REPORT_LOG("DatabaseServerConnection", ("%d rows received on Auction_Locations\n", m.getAuctionLocationsCount())); - REPORT_LOG("DatabaseServerConnection", ("%d rows received on Market_Auctions\n", m.getMarketAuctionsCount())); - REPORT_LOG("DatabaseServerConnection", ("%d rows received on Market_Auction_Attributes\n", m.getMarketAuctionAttributesCount())); - REPORT_LOG("DatabaseServerConnection", ("%d rows received on Market_Auction_Bids\n", m.getMarketAuctionBidsCount())); - LOG("CommoditiesServer", ("CommoditiesLoadDone Message received, %d rows Auction_Locations, %d rows Market_Auctions, %d rows Market_Auction_Attributes, %d rows Market_Auction_Bids", m.getAuctionLocationsCount(), m.getMarketAuctionsCount(), m.getMarketAuctionAttributesCount(), m.getMarketAuctionBidsCount())); - - LOG("CommoditiesServer", ("Start build index for attribute search")); - AuctionMarket::getInstance().BuildAuctionsSearchableAttributeList(); - LOG("CommoditiesServer", ("End build index for attribute search")); - - emitMessage(m); - } - else if (msg.isType("GetAuctionLocationsMessage")) - { - GetAuctionLocationsMessage m(ri); - const std::list & auctionLocations = m.getAuctionLocations(); - for (std::list::const_iterator iter = auctionLocations.begin(); iter != auctionLocations.end(); ++iter) - { - AuctionMarket::getInstance().onReceiveAuctionLocations(iter->locationId, iter->locationName, iter->ownerId, iter->salesTax, iter->salesTaxBankId, iter->emptyDate, iter->lastAccessDate, iter->inactiveDate, iter->status, iter->searchEnabled, iter->entranceCharge); - currentLocationCount++; - if (currentLocationCount - lastLocationCount >= 1000) + if (currentLocationCount != lastLocationCount) { DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); - LOG("CommoditiesServer", ("%d AuctionLocations record received", currentLocationCount)); + LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); lastLocationCount = currentLocationCount; } - } - } - else if (msg.isType("GetMarketAuctionsMessage")) - { - if (currentLocationCount != lastLocationCount) - { - DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); - LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); - lastLocationCount = currentLocationCount; - } - GetMarketAuctionsMessage m(ri); - const std::list & auctions = m.getAuctions(); - for (std::list::const_iterator iter = auctions.begin(); iter != auctions.end(); ++iter) - { - AuctionMarket::getInstance().onReceiveMarketAuctions(iter->itemId, iter->ownerId, iter->creatorId, iter->locationId, iter->minBid, iter->buyNowPrice, iter->auctionTimer, iter->oob, iter->userDescription, iter->category, iter->itemTemplateId, iter->itemName, iter->itemTimer, iter->active, iter->itemSize); - currentAuctionCount++; - if (currentAuctionCount - lastAuctionCount >= 10000) + if (currentAuctionCount != lastAuctionCount) { DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); - LOG("CommoditiesServer", ("%d MarketAuctions record received", currentAuctionCount)); + LOG("CommoditiesServer", ("%d MarketAuctions record received\n", currentAuctionCount)); lastAuctionCount = currentAuctionCount; } - } - } - else if (msg.isType("GetMarketAuctionAttributesMessage")) - { - if (currentLocationCount != lastLocationCount) - { - DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); - LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); - lastLocationCount = currentLocationCount; - } - if (currentAuctionCount != lastAuctionCount) - { - DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); - LOG("CommoditiesServer", ("%d MarketAuctions record received\n", currentAuctionCount)); - lastAuctionCount = currentAuctionCount; - } - GetMarketAuctionAttributesMessage m(ri); - const std::list & attributes = m.getAttributes(); - for (std::list::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) - { - AuctionMarket::getInstance().onReceiveMarketAuctionAttributes(iter->itemId, iter->attributeName, iter->attributeValue); - currentAuctionAttributeCount++; - if (currentAuctionAttributeCount - lastAuctionAttributeCount >= 10000) + if (currentAuctionAttributeCount != lastAuctionAttributeCount) { DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); - LOG("CommoditiesServer", ("%d MarketAuctionAttributes record received", currentAuctionAttributeCount)); + LOG("CommoditiesServer", ("%d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); lastAuctionAttributeCount = currentAuctionAttributeCount; } - } - } - else if (msg.isType("GetMarketAuctionBidsMessage")) - { - if (currentLocationCount != lastLocationCount) - { - DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); - LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); - lastLocationCount = currentLocationCount; - } - if (currentAuctionCount != lastAuctionCount) - { - DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); - LOG("CommoditiesServer", ("%d MarketAuctions record received\n", currentAuctionCount)); - lastAuctionCount = currentAuctionCount; - } - if (currentAuctionAttributeCount != lastAuctionAttributeCount) - { - DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); - LOG("CommoditiesServer", ("%d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); - lastAuctionAttributeCount = currentAuctionAttributeCount; - } - GetMarketAuctionBidsMessage m(ri); - const std::list & bids = m.getMarketAuctionBids(); - for (std::list::const_iterator iter = bids.begin(); iter != bids.end(); ++iter) - { - AuctionMarket::getInstance().onReceiveMarketAuctionBids(iter->itemId, iter->bidderId, iter->bid, iter->maxProxyBid); - currentBidCount++; - if (currentBidCount - lastBidCount >= 1000) + if (currentBidCount != lastBidCount) { DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionBids record received\n", currentBidCount)); - LOG("CommoditiesServer", ("%d MarketAuctionBids record received\n", currentBidCount)); + LOG("CommoditiesServer", ("%d MarketAuctionBids record received", currentBidCount)); lastBidCount = currentBidCount; } + REPORT_LOG("DatabaseServerConnection", ("CommoditiesLoadDone Message received on connection with the database server\n")); + CommoditiesLoadDoneMessage m(ri); + REPORT_LOG("DatabaseServerConnection", ("%d rows received on Auction_Locations\n", m.getAuctionLocationsCount())); + REPORT_LOG("DatabaseServerConnection", ("%d rows received on Market_Auctions\n", m.getMarketAuctionsCount())); + REPORT_LOG("DatabaseServerConnection", ("%d rows received on Market_Auction_Attributes\n", m.getMarketAuctionAttributesCount())); + REPORT_LOG("DatabaseServerConnection", ("%d rows received on Market_Auction_Bids\n", m.getMarketAuctionBidsCount())); + LOG("CommoditiesServer", ("CommoditiesLoadDone Message received, %d rows Auction_Locations, %d rows Market_Auctions, %d rows Market_Auction_Attributes, %d rows Market_Auction_Bids", m.getAuctionLocationsCount(), m.getMarketAuctionsCount(), m.getMarketAuctionAttributesCount(), m.getMarketAuctionBidsCount())); + + LOG("CommoditiesServer", ("Start build index for attribute search")); + AuctionMarket::getInstance().BuildAuctionsSearchableAttributeList(); + LOG("CommoditiesServer", ("End build index for attribute search")); + + emitMessage(m); + break; + } + case constcrc("GetAuctionLocationsMessage") : + { + GetAuctionLocationsMessage m(ri); + const std::list & auctionLocations = m.getAuctionLocations(); + for (std::list::const_iterator iter = auctionLocations.begin(); iter != auctionLocations.end(); ++iter) + { + AuctionMarket::getInstance().onReceiveAuctionLocations(iter->locationId, iter->locationName, iter->ownerId, iter->salesTax, iter->salesTaxBankId, iter->emptyDate, iter->lastAccessDate, iter->inactiveDate, iter->status, iter->searchEnabled, iter->entranceCharge); + currentLocationCount++; + if (currentLocationCount - lastLocationCount >= 1000) + { + DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); + LOG("CommoditiesServer", ("%d AuctionLocations record received", currentLocationCount)); + lastLocationCount = currentLocationCount; + } + } + break; + } + case constcrc("GetMarketAuctionsMessage") : + { + if (currentLocationCount != lastLocationCount) + { + DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); + LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); + lastLocationCount = currentLocationCount; + } + GetMarketAuctionsMessage m(ri); + const std::list & auctions = m.getAuctions(); + for (std::list::const_iterator iter = auctions.begin(); iter != auctions.end(); ++iter) + { + AuctionMarket::getInstance().onReceiveMarketAuctions(iter->itemId, iter->ownerId, iter->creatorId, iter->locationId, iter->minBid, iter->buyNowPrice, iter->auctionTimer, iter->oob, iter->userDescription, iter->category, iter->itemTemplateId, iter->itemName, iter->itemTimer, iter->active, iter->itemSize); + currentAuctionCount++; + if (currentAuctionCount - lastAuctionCount >= 10000) + { + DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); + LOG("CommoditiesServer", ("%d MarketAuctions record received", currentAuctionCount)); + lastAuctionCount = currentAuctionCount; + } + } + break; + } + case constcrc("GetMarketAuctionAttributesMessage") : + { + if (currentLocationCount != lastLocationCount) + { + DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); + LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); + lastLocationCount = currentLocationCount; + } + if (currentAuctionCount != lastAuctionCount) + { + DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); + LOG("CommoditiesServer", ("%d MarketAuctions record received\n", currentAuctionCount)); + lastAuctionCount = currentAuctionCount; + } + GetMarketAuctionAttributesMessage m(ri); + const std::list & attributes = m.getAttributes(); + for (std::list::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) + { + AuctionMarket::getInstance().onReceiveMarketAuctionAttributes(iter->itemId, iter->attributeName, iter->attributeValue); + currentAuctionAttributeCount++; + if (currentAuctionAttributeCount - lastAuctionAttributeCount >= 10000) + { + DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); + LOG("CommoditiesServer", ("%d MarketAuctionAttributes record received", currentAuctionAttributeCount)); + lastAuctionAttributeCount = currentAuctionAttributeCount; + } + } + break; + } + case constcrc("GetMarketAuctionBidsMessage") : + { + if (currentLocationCount != lastLocationCount) + { + DEBUG_REPORT_LOG(true, (" -- %d AuctionLocations record received\n", currentLocationCount)); + LOG("CommoditiesServer", ("%d AuctionLocations record received\n", currentLocationCount)); + lastLocationCount = currentLocationCount; + } + if (currentAuctionCount != lastAuctionCount) + { + DEBUG_REPORT_LOG(true, (" -- %d MarketAuctions record received\n", currentAuctionCount)); + LOG("CommoditiesServer", ("%d MarketAuctions record received\n", currentAuctionCount)); + lastAuctionCount = currentAuctionCount; + } + if (currentAuctionAttributeCount != lastAuctionAttributeCount) + { + DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); + LOG("CommoditiesServer", ("%d MarketAuctionAttributes record received\n", currentAuctionAttributeCount)); + lastAuctionAttributeCount = currentAuctionAttributeCount; + } + GetMarketAuctionBidsMessage m(ri); + const std::list & bids = m.getMarketAuctionBids(); + for (std::list::const_iterator iter = bids.begin(); iter != bids.end(); ++iter) + { + AuctionMarket::getInstance().onReceiveMarketAuctionBids(iter->itemId, iter->bidderId, iter->bid, iter->maxProxyBid); + currentBidCount++; + if (currentBidCount - lastBidCount >= 1000) + { + DEBUG_REPORT_LOG(true, (" -- %d MarketAuctionBids record received\n", currentBidCount)); + LOG("CommoditiesServer", ("%d MarketAuctionBids record received\n", currentBidCount)); + lastBidCount = currentBidCount; + } + } + break; + } + case constcrc("DeleteCharacterMessage") : + { + DeleteCharacterMessage message(ri); + AuctionMarket::getInstance().DeleteCharacter(message); + break; } - } - else if(msg.isType("DeleteCharacterMessage")) - { - DeleteCharacterMessage message(ri); - AuctionMarket::getInstance().DeleteCharacter(message); } } diff --git a/engine/server/application/CommoditiesServer/src/shared/GameServerConnection.cpp b/engine/server/application/CommoditiesServer/src/shared/GameServerConnection.cpp index 21b13a20..ab4ea76e 100755 --- a/engine/server/application/CommoditiesServer/src/shared/GameServerConnection.cpp +++ b/engine/server/application/CommoditiesServer/src/shared/GameServerConnection.cpp @@ -36,6 +36,8 @@ #include "serverNetworkMessages/QueryVendorItemCountMessage.h" #include "serverNetworkMessages/UpdateVendorStatusMessage.h" +#include "sharedFoundation/CrcConstexpr.hpp" + //----------------------------------------------------------------------- namespace GameServerConnectionNamespace @@ -88,201 +90,235 @@ void GameServerConnection::onReceive(const Archive::ByteStream & message) Archive::ReadIterator ri = message.begin(); GameNetworkMessage msg(ri); ri = message.begin(); + + const uint32 messageType = msg.getType(); - if(msg.isType("AcceptHighBidMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AcceptHighBidMessage from game server id: %d.\n", m_gameServerId )); - AcceptHighBidMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().AcceptHighBid(message); - } - else if(msg.isType("AddAuctionMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AddAuctionMessage from game server id: %d.\n", m_gameServerId )); - AddAuctionMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().AddAuction(message); - } - else if(msg.isType("AddBidMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AddBidMessage from game server id: %d.\n", m_gameServerId )); - AddBidMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().AddBid(message); - } - else if(msg.isType("AddImmediateAuctionMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AddImmediateAuctionMessage from game server id: %d.\n", m_gameServerId )); - AddImmediateAuctionMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().AddImmediateAuction(message); - } - else if(msg.isType("CancelAuctionMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message CancelAuctionMessage from game server id: %d.\n", m_gameServerId )); - CancelAuctionMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().CancelAuction(message); - } - else if(msg.isType("CreateVendorMarketMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message CreateVendorMarketMessage from game server id: %d.\n", m_gameServerId )); - CreateVendorMarketMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().CreateVendorMarket(message); - } - else if(msg.isType("DestroyVendorMarketMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message DestroyVendorMarketMessage from game server id: %d.\n", m_gameServerId )); - DestroyVendorMarketMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().DestroyVendorMarket(message); - } - else if(msg.isType("DeleteAuctionLocationMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message DeleteAuctionLocationMessage from game server id: %d.\n", m_gameServerId )); - DeleteAuctionLocationMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().DeleteAuctionLocation(message); - } - else if(msg.isType("GetItemDetailsMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetItemDetailsMessage from game server id: %d.\n", m_gameServerId )); - GetItemDetailsMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().GetItemDetails(message); - } - else if(msg.isType("GetItemMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetItemMessage from game server id: %d.\n", m_gameServerId )); - GetItemMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().GetItem(message); - } - else if(msg.isType("SetSalesTaxMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message SetSalesTaxMessage from game server id: %d.\n", m_gameServerId )); - SetSalesTaxMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().SetSalesTax(message); - } - else if(msg.isType("GetVendorOwnerMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetVendorOwnerMessage from game server id: %d.\n", m_gameServerId )); - GetVendorOwnerMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().GetVendorOwner(message); - } - else if(msg.isType("GetVendorValueMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetVendorValueMessage from game server id: %d.\n", m_gameServerId )); - GetVendorValueMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().GetVendorValue(message); - } - else if(msg.isType("QueryAuctionHeadersMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message QueryAuctionHeadersMessage from game server id: %d.\n", m_gameServerId )); - QueryAuctionHeadersMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().QueryAuctionHeaders(message); - } - else if(msg.isType("SetGameTimeMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message SetGameTimeMessage from game server id: %d.\n", m_gameServerId )); - SetGameTimeMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().SetGameTime(message); - } - else if(msg.isType("CleanupInvalidItemRetrievalMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message CleanupInvalidItemRetrievalMessage from game server id: %d.\n", m_gameServerId )); - CleanupInvalidItemRetrievalMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().CleanupInvalidItemRetrieval(message); - } - else if(msg.isType("QueryVendorItemCountMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message QueryVendorItemCountMessage from game server id: %d.\n", m_gameServerId )); - QueryVendorItemCountMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().QueryVendorItemCount(message); - } - else if(msg.isType("GetPlayerVendorCountMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetPlayerVendorCountMessage from game server id: %d.\n", m_gameServerId )); - GetPlayerVendorCountMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().GetPlayerVendorCount(message); - } - else if(msg.isType("UpdateVendorSearchOptionMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message UpdateVendorSearchOptionMessage from game server id: %d.\n", m_gameServerId )); - UpdateVendorSearchOptionMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().UpdateVendorSearchOption(message); - } - else if(msg.isType("SetEntranceChargeMessage")) - { - DEBUG_REPORT_LOG(/*m_showAllDebugInfo*/ true, ("[Commodities Server] : Received message SetEntranceChargeMessage from game server id: %d.\n", m_gameServerId )); - SetEntranceChargeMessage message(ri); - message.SetTrackId(m_gameServerId); - AuctionMarket::getInstance().SetEntranceCharge(message); - } - else if(msg.isType("ResponseCommoditiesExcludedGotTypes")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message ResponseCommoditiesExcludedGotTypes from game server id: %d.\n", m_gameServerId )); - GenericValueTypeMessage > message(ri); - AuctionMarket::getInstance().VerifyExcludedGotTypes(message.getValue()); - } - else if(msg.isType("ResponseCommoditiesExcludedResourceClasses")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message ResponseCommoditiesExcludedResourceClasses from game server id: %d.\n", m_gameServerId )); - GenericValueTypeMessage > message(ri); - AuctionMarket::getInstance().VerifyExcludedResourceClasses(message.getValue()); - } - else if(msg.isType("ResponseResourceTreeHierarchy")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message ResponseResourceTreeHierarchy from game server id: %d.\n", m_gameServerId )); - GenericValueTypeMessage > > message(ri); - AuctionMarket::getInstance().SetResourceTreeHierarchy(message.getValue()); - } - else if(msg.isType("UpdateVendorStatusMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message UpdateVendorStatusMessage from game server id: %d.\n", m_gameServerId)); - UpdateVendorStatusMessage message(ri); - AuctionMarket::getInstance().UpdateVendorStatus(message); - } - else if(msg.isType("UpdateVendorLocationMessage")) - { - DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message UpdateVendorLocationMessage from game server id: %d.\n", m_gameServerId)); - GenericValueTypeMessage > const message(ri); - AuctionMarket::getInstance().UpdateVendorLocation(message.getValue().first, message.getValue().second); - } - else if(msg.isType("GetItemAttributeData")) - { - GenericValueTypeMessage, std::pair, std::pair > > > const message(ri); - AuctionMarket::getInstance().getItemAttributeData(m_gameServerId, message.getValue().first.first, message.getValue().first.second, message.getValue().second.first.first, message.getValue().second.first.second, message.getValue().second.second.first, message.getValue().second.second.second); - } - else if(msg.isType("GetItemAttributeDataValues")) - { - GenericValueTypeMessage >, std::pair > > const message(ri); - AuctionMarket::getInstance().getItemAttributeDataValues(m_gameServerId, message.getValue().first.first, message.getValue().first.second.first, message.getValue().first.second.second, message.getValue().second.first, message.getValue().second.second); - } - else if(msg.isType("GetItemAttribute")) - { - GenericValueTypeMessage > const message(ri); - AuctionMarket::getInstance().getItemAttribute(m_gameServerId, message.getValue().first, message.getValue().second); - } - else if(msg.isType("GetVendorInfoForPlayer")) - { - GenericValueTypeMessage, bool> > const message(ri); - AuctionMarket::getInstance().getVendorInfoForPlayer(m_gameServerId, message.getValue().first.first, message.getValue().first.second, message.getValue().second); - } - else if(msg.isType("GetALPQ")) - { - GenericValueTypeMessage > const message(ri); - AuctionMarket::getInstance().getAuctionLocationPriorityQueue(m_gameServerId, message.getValue().first, message.getValue().second); + switch(messageType) { + case constcrc("AcceptHighBidMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AcceptHighBidMessage from game server id: %d.\n", m_gameServerId )); + AcceptHighBidMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().AcceptHighBid(message); + break; + } + case constcrc("AddAuctionMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AddAuctionMessage from game server id: %d.\n", m_gameServerId )); + AddAuctionMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().AddAuction(message); + break; + } + case constcrc("AddBidMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AddBidMessage from game server id: %d.\n", m_gameServerId )); + AddBidMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().AddBid(message); + break; + } + case constcrc("AddImmediateAuctionMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message AddImmediateAuctionMessage from game server id: %d.\n", m_gameServerId )); + AddImmediateAuctionMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().AddImmediateAuction(message); + break; + } + case constcrc("CancelAuctionMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message CancelAuctionMessage from game server id: %d.\n", m_gameServerId )); + CancelAuctionMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().CancelAuction(message); + break; + } + case constcrc("CreateVendorMarketMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message CreateVendorMarketMessage from game server id: %d.\n", m_gameServerId )); + CreateVendorMarketMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().CreateVendorMarket(message); + break; + } + case constcrc("DestroyVendorMarketMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message DestroyVendorMarketMessage from game server id: %d.\n", m_gameServerId )); + DestroyVendorMarketMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().DestroyVendorMarket(message); + break; + } + case constcrc("DeleteAuctionLocationMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message DeleteAuctionLocationMessage from game server id: %d.\n", m_gameServerId )); + DeleteAuctionLocationMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().DeleteAuctionLocation(message); + break; + } + case constcrc("GetItemDetailsMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetItemDetailsMessage from game server id: %d.\n", m_gameServerId )); + GetItemDetailsMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().GetItemDetails(message); + break; + } + case constcrc("GetItemMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetItemMessage from game server id: %d.\n", m_gameServerId )); + GetItemMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().GetItem(message); + break; + } + case constcrc("SetSalesTaxMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message SetSalesTaxMessage from game server id: %d.\n", m_gameServerId )); + SetSalesTaxMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().SetSalesTax(message); + break; + } + case constcrc("GetVendorOwnerMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetVendorOwnerMessage from game server id: %d.\n", m_gameServerId )); + GetVendorOwnerMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().GetVendorOwner(message); + break; + } + case constcrc("GetVendorValueMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetVendorValueMessage from game server id: %d.\n", m_gameServerId )); + GetVendorValueMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().GetVendorValue(message); + break; + } + case constcrc("QueryAuctionHeadersMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message QueryAuctionHeadersMessage from game server id: %d.\n", m_gameServerId )); + QueryAuctionHeadersMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().QueryAuctionHeaders(message); + break; + } + case constcrc("SetGameTimeMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message SetGameTimeMessage from game server id: %d.\n", m_gameServerId )); + SetGameTimeMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().SetGameTime(message); + break; + } + case constcrc("CleanupInvalidItemRetrievalMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message CleanupInvalidItemRetrievalMessage from game server id: %d.\n", m_gameServerId )); + CleanupInvalidItemRetrievalMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().CleanupInvalidItemRetrieval(message); + break; + } + case constcrc("QueryVendorItemCountMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message QueryVendorItemCountMessage from game server id: %d.\n", m_gameServerId )); + QueryVendorItemCountMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().QueryVendorItemCount(message); + break; + } + case constcrc("GetPlayerVendorCountMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message GetPlayerVendorCountMessage from game server id: %d.\n", m_gameServerId )); + GetPlayerVendorCountMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().GetPlayerVendorCount(message); + break; + } + case constcrc("UpdateVendorSearchOptionMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message UpdateVendorSearchOptionMessage from game server id: %d.\n", m_gameServerId )); + UpdateVendorSearchOptionMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().UpdateVendorSearchOption(message); + break; + } + case constcrc("SetEntranceChargeMessage") : + { + DEBUG_REPORT_LOG(/*m_showAllDebugInfo*/ true, ("[Commodities Server] : Received message SetEntranceChargeMessage from game server id: %d.\n", m_gameServerId )); + SetEntranceChargeMessage message(ri); + message.SetTrackId(m_gameServerId); + AuctionMarket::getInstance().SetEntranceCharge(message); + break; + } + case constcrc("ResponseCommoditiesExcludedGotTypes") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message ResponseCommoditiesExcludedGotTypes from game server id: %d.\n", m_gameServerId )); + GenericValueTypeMessage > message(ri); + AuctionMarket::getInstance().VerifyExcludedGotTypes(message.getValue()); + break; + } + case constcrc("ResponseCommoditiesExcludedResourceClasses") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message ResponseCommoditiesExcludedResourceClasses from game server id: %d.\n", m_gameServerId )); + GenericValueTypeMessage > message(ri); + AuctionMarket::getInstance().VerifyExcludedResourceClasses(message.getValue()); + break; + } + case constcrc("ResponseResourceTreeHierarchy") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message ResponseResourceTreeHierarchy from game server id: %d.\n", m_gameServerId )); + GenericValueTypeMessage > > message(ri); + AuctionMarket::getInstance().SetResourceTreeHierarchy(message.getValue()); + break; + } + case constcrc("UpdateVendorStatusMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message UpdateVendorStatusMessage from game server id: %d.\n", m_gameServerId)); + UpdateVendorStatusMessage message(ri); + AuctionMarket::getInstance().UpdateVendorStatus(message); + break; + } + case constcrc("UpdateVendorLocationMessage") : + { + DEBUG_REPORT_LOG(m_showAllDebugInfo, ("[Commodities Server] : Received message UpdateVendorLocationMessage from game server id: %d.\n", m_gameServerId)); + GenericValueTypeMessage > const message(ri); + AuctionMarket::getInstance().UpdateVendorLocation(message.getValue().first, message.getValue().second); + break; + } + case constcrc("GetItemAttributeData") : + { + GenericValueTypeMessage, std::pair, std::pair > > > const message(ri); + AuctionMarket::getInstance().getItemAttributeData(m_gameServerId, message.getValue().first.first, message.getValue().first.second, message.getValue().second.first.first, message.getValue().second.first.second, message.getValue().second.second.first, message.getValue().second.second.second); + break; + } + case constcrc("GetItemAttributeDataValues") : + { + GenericValueTypeMessage >, std::pair > > const message(ri); + AuctionMarket::getInstance().getItemAttributeDataValues(m_gameServerId, message.getValue().first.first, message.getValue().first.second.first, message.getValue().first.second.second, message.getValue().second.first, message.getValue().second.second); + break; + } + case constcrc("GetItemAttribute") : + { + GenericValueTypeMessage > const message(ri); + AuctionMarket::getInstance().getItemAttribute(m_gameServerId, message.getValue().first, message.getValue().second); + break; + } + case constcrc("GetVendorInfoForPlayer") : + { + GenericValueTypeMessage, bool> > const message(ri); + AuctionMarket::getInstance().getVendorInfoForPlayer(m_gameServerId, message.getValue().first.first, message.getValue().first.second, message.getValue().second); + break; + } + case constcrc("GetALPQ") : + { + GenericValueTypeMessage > const message(ri); + AuctionMarket::getInstance().getAuctionLocationPriorityQueue(m_gameServerId, message.getValue().first, message.getValue().second); + break; + } } } diff --git a/engine/server/application/ConnectionServer/src/shared/ChatServerConnection.cpp b/engine/server/application/ConnectionServer/src/shared/ChatServerConnection.cpp index 76cdc21c..ed53c023 100755 --- a/engine/server/application/ConnectionServer/src/shared/ChatServerConnection.cpp +++ b/engine/server/application/ConnectionServer/src/shared/ChatServerConnection.cpp @@ -17,38 +17,7 @@ #include "sharedNetworkMessages/ChatOnLeaveRoom.h" #include "sharedNetworkMessages/GenericValueTypeMessage.h" -//----------------------------------------------------------------------- -/* -void putClientsInRoom(const unsigned int roomId, const std::vector & clients) -{ - std::vector::const_iterator i; - for(i = clients.begin(); i != clients.end(); ++i) - { - - Client* client = ConnectionServer::getClient((*i)); - DEBUG_REPORT_LOG(!client, ("Error, could not map %s to a client\n", (*i).getValueString().c_str())); - if (client) - client->enterRoom(roomId); - } -} -*/ - -//----------------------------------------------------------------------- -/* -void removeClientsFromRoom(const unsigned int roomId, const std::vector & clients) -{ - std::vector::const_iterator i; - for(i = clients.begin(); i != clients.end(); ++i) - { - - Client* client = ConnectionServer::getClient((*i)); - DEBUG_REPORT_LOG(!client, ("Error, could not map %s to a client\n", (*i).getValueString().c_str())); - if (client) - client->leaveRoom(roomId); - } -} -*/ -//----------------------------------------------------------------------- +#include "sharedFoundation/CrcConstexpr.hpp" ChatServerConnection::ChatServerConnection(UdpConnectionMT * u, TcpClient * t) : ServerConnection(u, t), @@ -104,41 +73,16 @@ void ChatServerConnection::onReceive(const Archive::ByteStream & message) Archive::ReadIterator ri = message.begin(); GameNetworkMessage m(ri); ri = message.begin(); - - if (m.isType("GameClientMessage")) - { - //we're receiving a message to forward to the client. - //it is prefixed with NetworkId and reliable. + + if (message.getType() == constcrc("GameClientMessage")) { + //we're receiving a message to forward to the client. + //it is prefixed with NetworkId and reliable. const GameClientMessage msg(ri); Archive::ReadIterator mri(msg.getByteStream()); GameNetworkMessage gnm(mri); mri = msg.getByteStream().begin(); - - // The connection server wants to trap room - // enter/leave messages to cache clients - // in particular rooms for autorecovery when - // a chat server process is stopped then later - // restarted - // - // ************ THIS CODE DOES NOT WORK *********** - // The following code has been commented out since - // everyone in the group is sent these messages but - // the logic assumes that only the person entering - // or leaving a chat room is sent the message. - /* - if(gnm.isType("ChatOnEnteredRoom")) - { - Archive::ReadIterator cri(msg.getByteStream()); - ChatOnEnteredRoom chat(cri); - putClientsInRoom(chat.getRoomId(), msg.getDistributionList()); - } - else if(gnm.isType("ChatOnLeaveRoom")) - { - Archive::ReadIterator cri(msg.getByteStream()); - ChatOnLeaveRoom chat(cri); - removeClientsFromRoom(chat.getRoomId(), msg.getDistributionList()); - } - */ + + const uint32 messageType = gnm.getType(); const std::vector & d = msg.getDistributionList(); std::vector::const_iterator i; @@ -167,46 +111,55 @@ void ChatServerConnection::onReceive(const Archive::ByteStream & message) DEBUG_REPORT_LOG(!client, ("Error, could not map %s to a client\n", (*i).getValueString().c_str())); if (client) { - if (!gnm.isType("ChatStatisticsCS")) + if (messageType !== constcrc("ChatStatisticsCS")) { client->getClientConnection()->sendByteStream(msg.getByteStream(), msg.getReliable()); - + } + GameConnection *gc = client->getGameConnection(); + if (gc) { - if (gnm.isType("ChatOnGetFriendsList")) - { - Archive::ReadIterator cri(msg.getByteStream()); - ChatOnGetFriendsList c(cri); - gc->send(c, true); - //DEBUG_REPORT_LOG(true, ("Sending a ChatOnGetFriendsList msg to game server\n")); - } - else if (gnm.isType("ChatOnChangeIgnoreStatus")) - { - Archive::ReadIterator cri(msg.getByteStream()); - ChatOnChangeIgnoreStatus c(cri); - gc->send(c, true); - //DEBUG_REPORT_LOG(true, ("Sending a ChatOnChangeIgnoreStatus msg to game server\n")); - } - else if (gnm.isType("ChatOnChangeFriendStatus")) - { - Archive::ReadIterator cri(msg.getByteStream()); - ChatOnChangeFriendStatus c(cri); - gc->send(c, true); - //DEBUG_REPORT_LOG(true, ("Sending a ChatOnChangeFriendStatus msg to game server\n")); - } - else if (gnm.isType("ChatOnGetIgnoreList")) - { - Archive::ReadIterator cri(msg.getByteStream()); - ChatOnGetIgnoreList c(cri); - gc->send(c, true); - //DEBUG_REPORT_LOG(true, ("Sending a ChatOnGetIgnoreList msg to game server\n")); - } - else if (gnm.isType("ChatStatisticsCS")) - { - Archive::ReadIterator cri(msg.getByteStream()); - GenericValueTypeMessage, std::pair > > chatStatistics(cri); - gc->send(chatStatistics, true); - //DEBUG_REPORT_LOG(true, ("Sending a ChatStatisticsCS msg to game server\n")); + switch(messageType) { + case constcrc("ChatOnGetFriendsList") : + { + Archive::ReadIterator cri(msg.getByteStream()); + ChatOnGetFriendsList c(cri); + gc->send(c, true); + //DEBUG_REPORT_LOG(true, ("Sending a ChatOnGetFriendsList msg to game server\n")); + break; + } + case constcrc("ChatOnChangeIgnoreStatus") : + { + Archive::ReadIterator cri(msg.getByteStream()); + ChatOnChangeIgnoreStatus c(cri); + gc->send(c, true); + //DEBUG_REPORT_LOG(true, ("Sending a ChatOnChangeIgnoreStatus msg to game server\n")); + break; + } + case constcrc("ChatOnChangeFriendStatus") : + { + Archive::ReadIterator cri(msg.getByteStream()); + ChatOnChangeFriendStatus c(cri); + gc->send(c, true); + //DEBUG_REPORT_LOG(true, ("Sending a ChatOnChangeFriendStatus msg to game server\n")); + break; + } + case constcrc("ChatOnGetIgnoreList") : + { + Archive::ReadIterator cri(msg.getByteStream()); + ChatOnGetIgnoreList c(cri); + gc->send(c, true); + //DEBUG_REPORT_LOG(true, ("Sending a ChatOnGetIgnoreList msg to game server\n")); + break; + } + case constcrc("ChatStatisticsCS") : + { + Archive::ReadIterator cri(msg.getByteStream()); + GenericValueTypeMessage, std::pair > > chatStatistics(cri); + gc->send(chatStatistics, true); + //DEBUG_REPORT_LOG(true, ("Sending a ChatStatisticsCS msg to game server\n")); + break; + } } } } diff --git a/engine/server/application/ConnectionServer/src/shared/Client.cpp b/engine/server/application/ConnectionServer/src/shared/Client.cpp index 5809bfde..f7dadc0c 100755 --- a/engine/server/application/ConnectionServer/src/shared/Client.cpp +++ b/engine/server/application/ConnectionServer/src/shared/Client.cpp @@ -20,6 +20,8 @@ #include "sharedNetworkMessages/DisconnectPlayerMessage.h" #include "sharedNetworkMessages/GenericValueTypeMessage.h" +#include "sharedFoundation/CrcConstexpr.hpp" + //---------------------------------------------------------------------- Client::Client(ClientConnection * cconn, const NetworkId& oid) : @@ -157,7 +159,9 @@ void Client::leaveRoom(const unsigned int roomId) void Client::receiveMessage(const MessageDispatch::Emitter & source, const MessageDispatch::MessageBase & message) { - if(message.isType("GameConnectionClosed")) + const uint32 messageType = message.getType(); + + if(messageType == constcrc("GameConnectionClosed")) { // Game server has crashed. With luck, we'll get transferred to a new server shortly // So, clear our connection and put us on a queue. If we don't get transferred in a @@ -166,12 +170,12 @@ void Client::receiveMessage(const MessageDispatch::Emitter & source, const Messa m_gameConnection = 0; ConnectionServer::addRecoveringClient(getNetworkId()); } - else if(message.isType("ChatServerConnectionOpened")) + else if(messageType == constcrc("ChatServerConnectionOpened")) { const ChatServerConnection & chatConnection = static_cast(source); setChatConnection(const_cast(&chatConnection)); } - else if(message.isType("CustomerServiceConnectionOpened")) + else if(messageType == constcrc("CustomerServiceConnectionOpened")) { const CustomerServiceConnection & customerServiceConnection = static_cast(source); setCustomerServiceConnection(const_cast(&customerServiceConnection)); diff --git a/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp b/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp index 32b3811c..9399110d 100755 --- a/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp @@ -628,205 +628,47 @@ void ClientConnection::onReceive(const Archive::ByteStream & message) Archive::ReadIterator ri = message.begin(); GameNetworkMessage m(ri); ri = message.begin(); + + const uint32 messageType = message.getType(); //Clients with a selected character get routed to a game server. //@todo check for filtering out bad messages. if (m_hasSelectedCharacter) { // if it is a chat message, send it directly to the chat server - if( - m.isType("ChatAddFriend") || - m.isType("ChatAddModeratorToRoom") || - m.isType("ChatBanAvatarFromRoom") || - m.isType("ChatCreateRoom") || - m.isType("ChatDeletePersistentMessage") || - m.isType("ChatDeleteAllPersistentMessages") || - m.isType("ChatDestroyRoom") || - m.isType("ChatInstantMessageToCharacter") || - m.isType("ChatInviteAvatarToRoom") || - m.isType("ChatKickAvatarFromRoom") || - m.isType("ChatRemoveAvatarFromRoom") || - m.isType("ChatRemoveFriend") || - m.isType("ChatRemoveModeratorFromRoom") || - m.isType("ChatRequestPersistentMessage") || - m.isType("ChatRequestRoomList") || - m.isType("ChatSendToRoom") || - m.isType("ChatUninviteFromRoom") || - m.isType("ChatUnbanAvatarFromRoom") || - m.isType("VerifyPlayerNameMessage") || - m.isType("VoiceChatRequestPersonalChannel") || - m.isType("VoiceChatInvite") || - m.isType("VoiceChatKick") || - m.isType("VoiceChatRequestChannelInfo") - ) - { - DEBUG_REPORT_LOG(true, ("ConnServ: ClientConnection::onReceive()\n")); - - NOT_NULL(m_client); - if(m_client) + switch(messageType) { + case constcrc("ChatAddFriend") : + case constcrc("ChatAddModeratorToRoom") : + case constcrc("ChatBanAvatarFromRoom") : + case constcrc("ChatCreateRoom") : + case constcrc("ChatDeletePersistentMessage") : + case constcrc("ChatDeleteAllPersistentMessages") : + case constcrc("ChatDestroyRoom") : + case constcrc("ChatInstantMessageToCharacter") : + case constcrc("ChatInviteAvatarToRoom") : + case constcrc("ChatKickAvatarFromRoom") : + case constcrc("ChatRemoveAvatarFromRoom") : + case constcrc("ChatRemoveFriend") : + case constcrc("ChatRemoveModeratorFromRoom") : + case constcrc("ChatRequestPersistentMessage") : + case constcrc("ChatRequestRoomList") : + case constcrc("ChatSendToRoom") : + case constcrc("ChatUninviteFromRoom") : + case constcrc("ChatUnbanAvatarFromRoom") : + case constcrc("VerifyPlayerNameMessage") : { - static std::vector v; - v.clear(); - v.push_back(m_client->getNetworkId()); - GameClientMessage gcm(v, true, ri); - if(m_client->getChatConnection()) - { - m_client->getChatConnection()->send(gcm , true); - } - else - { - // defer chat messages until a server is back online - Archive::ByteStream bs; - m.pack(bs); - m_client->deferChatMessage(bs); - } - } - else - { - ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); - disconnect(); - } - } - // ChatEnterRoom and ChatEnterRoomById needs to go to the game server to determine - // if the character is not allowed to enter the room because of game rule restrictions; - // only if that test pass do we forward the message on to the chat server to request - // to enter the room - else if (m.isType("ChatEnterRoom") || - m.isType("ChatEnterRoomById") - ) - { - NOT_NULL(m_client); + DEBUG_REPORT_LOG(true, ("ConnServ: ClientConnection::onReceive()\n")); - unsigned int sequence; - std::string roomName; - - Archive::ReadIterator cri = message.begin(); - if (m.isType("ChatEnterRoom")) - { - ChatEnterRoom const cer(cri); - sequence = cer.getSequence(); - roomName = cer.getRoomName(); - } - else - { - ChatEnterRoomById const cerbi(cri); - sequence = cerbi.getSequence(); - roomName = cerbi.getRoomName(); - } - - if(m_client && m_client->getGameConnection()) - { - if (m_pendingChatEnterRoomRequests.count(sequence) == 0) - { - GenericValueTypeMessage, unsigned int> > const cervr( - "ChatEnterRoomValidationRequest", - std::make_pair( - std::make_pair(m_client->getNetworkId(), roomName), - sequence)); - - m_client->getGameConnection()->send(cervr, true); - - // queue up request until game server responds - static std::vector v; - v.clear(); - v.push_back(m_client->getNetworkId()); - m_pendingChatEnterRoomRequests[sequence] = new GameClientMessage(v, true, ri); - } - } - else - { - // send back response to client saying game server not available - - // the client only cares about sequence and result when it's a failure - ChatOnEnteredRoom fail(sequence, SWG_CHAT_ERR_NO_GAME_SERVER, 0, ChatAvatarId()); - send(fail, true); - } - } - // ChatQueryRoom needs to go to the game server to determine if the character is - // not allowed to query the room because of game rule restrictions; only if that - // test pass do we forward the message on to the chat server for completion - else if (m.isType("ChatQueryRoom")) - { - NOT_NULL(m_client); - - Archive::ReadIterator cri = message.begin(); - ChatQueryRoom cqr(cri); - - if(m_client && m_client->getGameConnection()) - { - if (m_pendingChatQueryRoomRequests.count(cqr.getSequence()) == 0) - { - GenericValueTypeMessage, unsigned int> > const cqrvr( - "ChatQueryRoomValidationRequest", - std::make_pair( - std::make_pair(m_client->getNetworkId(), cqr.getRoomName()), - cqr.getSequence())); - - m_client->getGameConnection()->send(cqrvr, true); - - // queue up request until game server responds - static std::vector v; - v.clear(); - v.push_back(m_client->getNetworkId()); - m_pendingChatQueryRoomRequests[cqr.getSequence()] = new GameClientMessage(v, true, ri); - } - } - } - // ChatInviteGroupToRoom needs to go to the game server to get group information - else if (m.isType("ChatInviteGroupToRoom")) - { - NOT_NULL(m_client); - if(m_client) - { - if (m_client->getGameConnection()) + NOT_NULL(m_client); + if(m_client) { static std::vector v; v.clear(); v.push_back(m_client->getNetworkId()); GameClientMessage gcm(v, true, ri); - m_client->getGameConnection()->send(gcm, true); - } - else - { - // defer chat messages until a server is back online - Archive::ByteStream bs; - m.pack(bs); - m_client->deferChatMessage(bs); - } - } - else - { - ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); - disconnect(); - } - } - // ChatPersistentMessageToServer may need to be passed off to the game server for guild or citizens messages - else if (m.isType("ChatPersistentMessageToServer")) - { - NOT_NULL(m_client); - if(m_client) - { - static std::vector v; - v.clear(); - v.push_back(m_client->getNetworkId()); - - Archive::ReadIterator cri = message.begin(); - ChatPersistentMessageToServer chat(cri); - std::string const &toName = chat.getToCharacterName().name; - if (!_stricmp(toName.c_str(), "guild") || !_strnicmp(toName.c_str(), "guild ", 6) || !_stricmp(toName.c_str(), "citizens")) - { - if (m_client->getGameConnection()) + if(m_client->getChatConnection()) { - GameClientMessage gcm(v, true, ri); - m_client->getGameConnection()->send(gcm, true); - } - } - else - { - if (m_client->getChatConnection()) - { - GameClientMessage gcm(v, true, ri); - m_client->getChatConnection()->send(gcm, true); + m_client->getChatConnection()->send(gcm , true); } else { @@ -836,350 +678,498 @@ void ClientConnection::onReceive(const Archive::ByteStream & message) m_client->deferChatMessage(bs); } } + else + { + ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); + disconnect(); + } + break; } - else + // ChatEnterRoom and ChatEnterRoomById needs to go to the game server to determine + // if the character is not allowed to enter the room because of game rule restrictions; + // only if that test pass do we forward the message on to the chat server to request + // to enter the room + case constcrc("ChatEnterRoom") : + case constcrc(("ChatEnterRoomById") : + { + NOT_NULL(m_client); + + unsigned int sequence; + std::string roomName; + + Archive::ReadIterator cri = message.begin(); + if (msgType == constcrc(("ChatEnterRoom")) + { + ChatEnterRoom const cer(cri); + sequence = cer.getSequence(); + roomName = cer.getRoomName(); + } + else + { + ChatEnterRoomById const cerbi(cri); + sequence = cerbi.getSequence(); + roomName = cerbi.getRoomName(); + } + + if(m_client && m_client->getGameConnection()) + { + if (m_pendingChatEnterRoomRequests.count(sequence) == 0) + { + GenericValueTypeMessage, unsigned int> > const cervr( + "ChatEnterRoomValidationRequest", + std::make_pair( + std::make_pair(m_client->getNetworkId(), roomName), + sequence)); + + m_client->getGameConnection()->send(cervr, true); + + // queue up request until game server responds + static std::vector v; + v.clear(); + v.push_back(m_client->getNetworkId()); + m_pendingChatEnterRoomRequests[sequence] = new GameClientMessage(v, true, ri); + } + } + else + { + // send back response to client saying game server not available + + // the client only cares about sequence and result when it's a failure + ChatOnEnteredRoom fail(sequence, SWG_CHAT_ERR_NO_GAME_SERVER, 0, ChatAvatarId()); + send(fail, true); + } + + break; + } + // ChatQueryRoom needs to go to the game server to determine if the character is + // not allowed to query the room because of game rule restrictions; only if that + // test pass do we forward the message on to the chat server for completion + case constcrc("ChatQueryRoom") : { - ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); - disconnect(); + NOT_NULL(m_client); + + Archive::ReadIterator cri = message.begin(); + ChatQueryRoom cqr(cri); + + if(m_client && m_client->getGameConnection()) + { + if (m_pendingChatQueryRoomRequests.count(cqr.getSequence()) == 0) + { + GenericValueTypeMessage, unsigned int> > const cqrvr( + "ChatQueryRoomValidationRequest", + std::make_pair( + std::make_pair(m_client->getNetworkId(), cqr.getRoomName()), + cqr.getSequence())); + + m_client->getGameConnection()->send(cqrvr, true); + + // queue up request until game server responds + static std::vector v; + v.clear(); + v.push_back(m_client->getNetworkId()); + m_pendingChatQueryRoomRequests[cqr.getSequence()] = new GameClientMessage(v, true, ri); + } + } + break; } - } - // if it is a cs message, send it directly to the cs server - else if ( - m.isType("ConnectPlayerMessage") || - m.isType("DisconnectPlayerMessage") || - m.isType("CreateTicketMessage") || - m.isType("AppendCommentMessage") || - m.isType("CancelTicketMessage") || - m.isType("GetTicketsMessage") || - m.isType("GetCommentsMessage") || - m.isType("SearchKnowledgeBaseMessage") || - m.isType("GetArticleMessage") || - m.isType("RequestCategoriesMessage") || - m.isType("NewTicketActivityMessage") - ) - { - NOT_NULL(m_client); - if(m_client) + // ChatInviteGroupToRoom needs to go to the game server to get group information + case constcrc("ChatInviteGroupToRoom") : { - CustomerServiceConnection *customerServiceConnection = m_client->getCustomerServiceConnection(); - - //DEBUG_REPORT_LOG(true, ("CONSRV::CS - suid: %i\n", getSUID())); - - if (customerServiceConnection != nullptr) + NOT_NULL(m_client); + if(m_client) + { + if (m_client->getGameConnection()) + { + static std::vector v; + v.clear(); + v.push_back(m_client->getNetworkId()); + GameClientMessage gcm(v, true, ri); + m_client->getGameConnection()->send(gcm, true); + } + else + { + // defer chat messages until a server is back online + Archive::ByteStream bs; + m.pack(bs); + m_client->deferChatMessage(bs); + } + } + else + { + ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); + disconnect(); + } + break; + } + // ChatPersistentMessageToServer may need to be passed off to the game server for guild or citizens messages + case constcrc("ChatPersistentMessageToServer") : + { + NOT_NULL(m_client); + if(m_client) { static std::vector v; v.clear(); v.push_back(m_client->getNetworkId()); - if (m.isType("ConnectPlayerMessage")) - { - ConnectPlayerMessage message(ri); - message.setStationId(getSUID()); - GameClientMessage gcm(v, true, message); - customerServiceConnection->send(gcm , true); - } - else if (m.isType("CreateTicketMessage")) + Archive::ReadIterator cri = message.begin(); + ChatPersistentMessageToServer chat(cri); + std::string const &toName = chat.getToCharacterName().name; + if (!_stricmp(toName.c_str(), "guild") || !_strnicmp(toName.c_str(), "guild ", 6) || !_stricmp(toName.c_str(), "citizens")) { - CreateTicketMessage message(ri); - message.setStationId(getSUID()); - - GameClientMessage gcm(v, true, message); - customerServiceConnection->send(gcm , true); - } - else if (m.isType("AppendCommentMessage")) - { - AppendCommentMessage message(ri); - message.setStationId(getSUID()); - - GameClientMessage gcm(v, true, message); - customerServiceConnection->send(gcm , true); - } - else if (m.isType("CancelTicketMessage")) - { - CancelTicketMessage message(ri); - message.setStationId(getSUID()); - - GameClientMessage gcm(v, true, message); - customerServiceConnection->send(gcm , true); - } - else if (m.isType("GetTicketsMessage")) - { - GetTicketsMessage message(ri); - message.setStationId(getSUID()); - - GameClientMessage gcm(v, true, message); - customerServiceConnection->send(gcm , true); - } - else if (m.isType("NewTicketActivityMessage")) - { - NewTicketActivityMessage message(ri); - message.setStationId(getSUID()); - - GameClientMessage gcm(v, true, message); - customerServiceConnection->send(gcm , true); + if (m_client->getGameConnection()) + { + GameClientMessage gcm(v, true, ri); + m_client->getGameConnection()->send(gcm, true); + } } else { - GameClientMessage gcm(v, true, ri); - customerServiceConnection->send(gcm , true); - } - //else - //{ - // /*// defer chat messages until a server is back online - // Archive::ByteStream bs; - // m.pack(bs); - // m_client->deferChatMessage(bs); - // */ - //} - } - } - else - { - ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); - disconnect(); - } - } - else if (m.isType("28afefcc187a11dc888b001")) // obfuscation for ClientInactivityMessage message - { - GenericValueTypeMessage msg(ri); - - if (m_hasBeenValidated && m_sessionValidated) - { - // client went inactive - if (msg.getValue()) - { - if (m_lastActiveTime > 0) - { - // record the amount of active time - m_activePlayTimeDuration += static_cast(::time(nullptr) - m_lastActiveTime); - - // tell Session to stop recording play time for the character - if (ConnectionServer::getSessionApiClient() && ConfigConnectionServer::getSessionRecordPlayTime()) + if (m_client->getChatConnection()) { - LOG("CustomerService", ("Login:%s calling SessionStopPlay() for %s/%s/%s (%s). Active play time: %s", ClientConnection::describeAccount(this).c_str(), this->getSessionId().c_str(), ConfigConnectionServer::getClusterName(), this->getCharacterName().c_str(), this->getCharacterId().getValueString().c_str(), this->getCurrentActivePlayTimeDuration().c_str())); - ConnectionServer::getSessionApiClient()->stopPlay(*this); + GameClientMessage gcm(v, true, ri); + m_client->getChatConnection()->send(gcm, true); } - - // client is no longer active; this needs to be set after the LOG() statement - // above because getCurrentActivePlayTimeDuration() uses m_lastActiveTime - m_lastActiveTime = 0; - - // update the play time info on the game server - sendPlayTimeInfoToGameServer(); - - // drop inactive character - if (ConfigConnectionServer::getDisconnectOnInactive()) + else { - LOG("ClientDisconnect", ("Disconnecting %u because the player was inactive for too long.",getSUID())); - ConnectionServer::dropClient(this, "Client inactivity"); - disconnect(); - } - else if (ConfigConnectionServer::getDisconnectFreeTrialOnInactive() && ((m_featureBitsSubscription & ClientSubscriptionFeature::Base) == 0)) - { - LOG("ClientDisconnect", ("Disconnecting (free trial) %u because the player was inactive for too long.",getSUID())); - ConnectionServer::dropClient(this, "Client inactivity (free trial)"); - disconnect(); + // defer chat messages until a server is back online + Archive::ByteStream bs; + m.pack(bs); + m_client->deferChatMessage(bs); } } } - // client went active else { - if (m_lastActiveTime == 0) + ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); + disconnect(); + } + break; + } + // if it is a cs message, send it directly to the cs server + case constcrc("ConnectPlayerMessage") : + case constcrc("DisconnectPlayerMessage") : + case constcrc("CreateTicketMessage") : + case constcrc("AppendCommentMessage") : + case constcrc("CancelTicketMessage") : + case constcrc("GetTicketsMessage") : + case constcrc("GetCommentsMessage") : + case constcrc("SearchKnowledgeBaseMessage") : + case constcrc("GetArticleMessage") : + case constcrc("RequestCategoriesMessage") : + case constcrc("NewTicketActivityMessage") : + { + NOT_NULL(m_client); + if(m_client) + { + CustomerServiceConnection *customerServiceConnection = m_client->getCustomerServiceConnection(); + + //DEBUG_REPORT_LOG(true, ("CONSRV::CS - suid: %i\n", getSUID())); + + if (customerServiceConnection != nullptr) { - // record the time client went active - m_lastActiveTime = ::time(nullptr); + static std::vector v; + v.clear(); + v.push_back(m_client->getNetworkId()); - // tell Session to start recording play time for the character - if (ConnectionServer::getSessionApiClient() && ConfigConnectionServer::getSessionRecordPlayTime()) - { - LOG("CustomerService", ("Login:%s calling SessionStartPlay() for %s/%s/%s (%s)", ClientConnection::describeAccount(this).c_str(), this->getSessionId().c_str(), ConfigConnectionServer::getClusterName(), this->getCharacterName().c_str(), this->getCharacterId().getValueString().c_str())); - ConnectionServer::getSessionApiClient()->startPlay(*this); + // TODO: this shit could be made into a template + switch (messageType) { + case constcrc("ConnectPlayerMessage") : + { + ConnectPlayerMessage message(ri); + break; + } + case constcrc("CreateTicketMessage") : + { + CreateTicketMessage message(ri); + break; + } + case constcrc("AppendCommentMessage") : + { + AppendCommentMessage message(ri); + break; + } + case constcrc("CancelTicketMessage") : + { + CancelTicketMessage message(ri); + break; + } + case constcrc("GetTicketsMessage") : + { + GetTicketsMessage message(ri); + break; + } + case constcrc("NewTicketActivityMessage") : + { + NewTicketActivityMessage message(ri); + break; + } } - - // update the play time info on the game server - sendPlayTimeInfoToGameServer(); + + GameClientMessage gcm(v, true, ri); + message.setStationId(getSUID()); + customerServiceConnection->send(gcm , true); + } } - } - } - else - { - //Forward on to Game Server - DEBUG_REPORT_LOG((!m_client || !m_client->getGameConnection()), ("Warn, received game message with no game connection. This may happen for a short time after a GameServer crashes. If it continues to happen, it indicates a bug.\n")); - - if (m_client && m_client->getGameConnection()) - { - static std::vector v; - v.clear(); - v.push_back(m_client->getNetworkId()); - GameClientMessage gcm(v, true, ri); - m_client->getGameConnection()->send(gcm, true); - } - } - } - - else if(m.isType("ClientIdMsg")) - { - DEBUG_REPORT_LOG(true,("Recieved ClientIdMsg\n")); - ClientIdMsg k(ri); - - handleClientIdMessage(k); - } - else if(m.isType("SelectCharacter")) - { - SelectCharacter s(ri); - DEBUG_REPORT_LOG(true,("Recvd SelectCharacter message for %s.\n", s.getId().getValueString().c_str())); - - handleSelectCharacterMessage(s); - } - else if(m.isType("ClientCreateCharacter")) - { - if (m_hasBeenValidated && !m_hasSelectedCharacter) //lint !e774 no this doesn't always eval to true - { - ClientCreateCharacter clientCreate(ri); - DEBUG_REPORT_LOG(true,("Got ClientCreateCharacter message for %lu with name %s\n", m_suid, Unicode::wideToNarrow(clientCreate.getCharacterName()).c_str())); - LOG("TraceCharacterCreation", ("%d sent ClientCreateCharacter(charaterName=%s, templateName=%s, scaleFactor=%f, startingLocation=%s, hairTemplateName=%s, profession=%s, jedi=%d, useNewbieTutorial=%d, skillTemplate=%s, workingSkill=%s)", - getSUID(), - Unicode::wideToNarrow(clientCreate.getCharacterName()).c_str(), - clientCreate.getTemplateName().c_str(), - clientCreate.getScaleFactor(), - clientCreate.getStartingLocation().c_str(), - clientCreate.getHairTemplateName().c_str(), - clientCreate.getProfession().c_str(), - static_cast(clientCreate.getJedi()), - static_cast(clientCreate.getUseNewbieTutorial()), - clientCreate.getSkillTemplate().c_str(), - clientCreate.getWorkingSkill().c_str())); - - if (!clientCreate.getUseNewbieTutorial() && !m_canSkipTutorial) - { - LOG("TraceCharacterCreation", ("%d failed character creation. The client is not allowed to skip the tutorial", getSUID())); - // This is probably a hack attempt, because the Client was already told they couldn't skip the tutorial - LOG("ClientDisconnect", ("Disconnecting %u because they tried to skip the tutorial without permission.\n",getSUID())); - disconnect(); - } - else if (clientCreate.getJedi() && !m_canCreateJediCharacter) - { - LOG("TraceCharacterCreation", ("%d failed character creation. The request character type was Jedi, but this client cannot create a Jedi character", getSUID())); - // This is probably a hack attempt, because the Client was already told they couldn't create a character - LOG("ClientDisconnect", ("Disconnecting %u because they tried to create a Jedi character without permission.\n",getSUID())); - disconnect(); - } - else if (!clientCreate.getJedi() && !m_canCreateRegularCharacter) - { - LOG("TraceCharacterCreation", ("%d failed character creation. The client is not allowed to create any characters", getSUID())); - // This is probably a hack attempt, because the Client was already told they couldn't create a character - LOG("ClientDisconnect", ("Disconnecting %u because they tried to create a regular character without permission.\n",getSUID())); - disconnect(); - } - else if (m_hasRequestedCharacterCreate) - { - LOG("TraceCharacterCreation", ("%d failed character creation. The client has already requested character creation on this connection", getSUID())); - LOG("ClientDisconnect", ("Disconnecting %u because the client has already requested character creation on this connection.\n",getSUID())); - disconnect(); - } - else if (m_hasCreatedCharacter) - { - LOG("TraceCharacterCreation", ("%d failed character creation. A character has been created on this or another galaxy for this account while this connection was up", getSUID())); - LOG("ClientDisconnect", ("Disconnecting %u because a character has been created on this or another galaxy for this account while this connection was up.\n",getSUID())); - disconnect(); - } - else if (clientCreate.getCharacterName().length()==0) - { - LOG("TraceCharacterCreation", ("%d failed character creation. The character's name is empty", getSUID())); - LOG("ClientDisconnect",("Disconnecting %u because they tried to create a character with no name.\n",getSUID())); - disconnect(); - } - else - { - Unicode::String biography(clientCreate.getBiography()); - if (biography.length() > 1024) + else { - IGNORE_RETURN( biography.erase(1024) ); - DEBUG_REPORT_LOG(true,("Biography shortened to 1024 characters.\n")); + ConnectionServer::dropClient(this, "m_client is nullptr while receiving a message!"); + disconnect(); + } + break; + } + case constcrc("28afefcc187a11dc888b001") : // obfuscation for ClientInactivityMessage message + { + GenericValueTypeMessage msg(ri); + + if (m_hasBeenValidated && m_sessionValidated) + { + // client went inactive + if (msg.getValue()) + { + if (m_lastActiveTime > 0) + { + // record the amount of active time + m_activePlayTimeDuration += static_cast(::time(nullptr) - m_lastActiveTime); + + // tell Session to stop recording play time for the character + if (ConnectionServer::getSessionApiClient() && ConfigConnectionServer::getSessionRecordPlayTime()) + { + LOG("CustomerService", ("Login:%s calling SessionStopPlay() for %s/%s/%s (%s). Active play time: %s", ClientConnection::describeAccount(this).c_str(), this->getSessionId().c_str(), ConfigConnectionServer::getClusterName(), this->getCharacterName().c_str(), this->getCharacterId().getValueString().c_str(), this->getCurrentActivePlayTimeDuration().c_str())); + ConnectionServer::getSessionApiClient()->stopPlay(*this); + } + + // client is no longer active; this needs to be set after the LOG() statement + // above because getCurrentActivePlayTimeDuration() uses m_lastActiveTime + m_lastActiveTime = 0; + + // update the play time info on the game server + sendPlayTimeInfoToGameServer(); + + // drop inactive character + if (ConfigConnectionServer::getDisconnectOnInactive()) + { + LOG("ClientDisconnect", ("Disconnecting %u because the player was inactive for too long.",getSUID())); + ConnectionServer::dropClient(this, "Client inactivity"); + disconnect(); + } + else if (ConfigConnectionServer::getDisconnectFreeTrialOnInactive() && ((m_featureBitsSubscription & ClientSubscriptionFeature::Base) == 0)) + { + LOG("ClientDisconnect", ("Disconnecting (free trial) %u because the player was inactive for too long.",getSUID())); + ConnectionServer::dropClient(this, "Client inactivity (free trial)"); + disconnect(); + } + } + } + // client went active + else + { + if (m_lastActiveTime == 0) + { + // record the time client went active + m_lastActiveTime = ::time(nullptr); + + // tell Session to start recording play time for the character + if (ConnectionServer::getSessionApiClient() && ConfigConnectionServer::getSessionRecordPlayTime()) + { + LOG("CustomerService", ("Login:%s calling SessionStartPlay() for %s/%s/%s (%s)", ClientConnection::describeAccount(this).c_str(), this->getSessionId().c_str(), ConfigConnectionServer::getClusterName(), this->getCharacterName().c_str(), this->getCharacterId().getValueString().c_str())); + ConnectionServer::getSessionApiClient()->startPlay(*this); + } + + // update the play time info on the game server + sendPlayTimeInfoToGameServer(); + } + } + } + break; + } + default : + { + //Forward on to Game Server + DEBUG_REPORT_LOG((!m_client || !m_client->getGameConnection()), ("Warn, received game message with no game connection. This may happen for a short time after a GameServer crashes. If it continues to happen, it indicates a bug.\n")); + + if (m_client && m_client->getGameConnection()) + { + static std::vector v; + v.clear(); + v.push_back(m_client->getNetworkId()); + GameClientMessage gcm(v, true, ri); + m_client->getGameConnection()->send(gcm, true); } - if (m_isAdminAccount) - { - ConnectionCreateCharacter connectionCreate( - m_suid, - clientCreate.getCharacterName(), - clientCreate.getTemplateName(), - clientCreate.getScaleFactor(), - clientCreate.getStartingLocation(), - clientCreate.getAppearanceData(), - clientCreate.getHairTemplateName(), - clientCreate.getHairAppearanceData(), - clientCreate.getProfession(), - clientCreate.getJedi(), - biography, - clientCreate.getUseNewbieTutorial(), - clientCreate.getSkillTemplate(), - clientCreate.getWorkingSkill(), - m_isAdminAccount, - false, - m_featureBitsGame); - - ConnectionServer::sendToCentralProcess(connectionCreate); - LOG("TraceCharacterCreation", ("%d character creation request sent to CentralServer", getSUID())); - } - else - { - // for regular players, do one final check with the LoginServer - // to make sure the character can be created (i.e. that character - // limits have not been exceeded) - delete m_pendingCharacterCreate; - m_pendingCharacterCreate = new ConnectionCreateCharacter( - m_suid, - clientCreate.getCharacterName(), - clientCreate.getTemplateName(), - clientCreate.getScaleFactor(), - clientCreate.getStartingLocation(), - clientCreate.getAppearanceData(), - clientCreate.getHairTemplateName(), - clientCreate.getHairAppearanceData(), - clientCreate.getProfession(), - clientCreate.getJedi(), - biography, - clientCreate.getUseNewbieTutorial(), - clientCreate.getSkillTemplate(), - clientCreate.getWorkingSkill(), - m_isAdminAccount, - false, - m_featureBitsGame); - - LOG("TraceCharacterCreation", ("%d character creation request awaiting final verification from LoginServer", getSUID())); - - ValidateAccountMessage vcm(m_suid, 0, m_featureBitsSubscription); - ConnectionServer::sendToCentralProcess(vcm); - } - - m_hasRequestedCharacterCreate = true; + break; } } - } - else if(m.isType("ClientRandomNameRequest")) - { - ClientRandomNameRequest clientRandomName(ri); + } else { + switch (messageType) { + case constcrc("ClientIdMsg") : + { + DEBUG_REPORT_LOG(true,("Recieved ClientIdMsg\n")); + ClientIdMsg k(ri); - RandomNameRequest randomNameRequest(m_suid, clientRandomName.getCreatureTemplate()); - ConnectionServer::sendToCentralProcess(randomNameRequest); - LOG("TraceCharacterCreation", ("%d requested a random name. Request sent to CentralServer", getSUID())); - } - else if(m.isType("ClientVerifyAndLockNameRequest")) - { - ClientVerifyAndLockNameRequest clientVerifyAndLockNameRequest(ri); + handleClientIdMessage(k); + break; + } + case constcrc("SelectCharacter") : + { + SelectCharacter s(ri); + DEBUG_REPORT_LOG(true,("Recvd SelectCharacter message for %s.\n", s.getId().getValueString().c_str())); - VerifyAndLockNameRequest verifyAndLockNameRequest(m_suid, NetworkId::cms_invalid, clientVerifyAndLockNameRequest.getTemplateName(), clientVerifyAndLockNameRequest.getCharacterName(), m_featureBitsGame); - ConnectionServer::sendToCentralProcess(verifyAndLockNameRequest); - LOG("TraceCharacterCreation", ("%d requested a verify and lock of name: %s. Request sent to CentralServer", getSUID(), Unicode::wideToNarrow(verifyAndLockNameRequest.getCharacterName()).c_str())); - } - else if(m.isType("LagRequest")) - { - /* - handleLagRequest(); - */ + handleSelectCharacterMessage(s); + break; + } + case constcrc("ClientCreateCharacter") : + { + if (m_hasBeenValidated && !m_hasSelectedCharacter) //lint !e774 no this doesn't always eval to true + { + ClientCreateCharacter clientCreate(ri); + DEBUG_REPORT_LOG(true,("Got ClientCreateCharacter message for %lu with name %s\n", m_suid, Unicode::wideToNarrow(clientCreate.getCharacterName()).c_str())); + LOG("TraceCharacterCreation", ("%d sent ClientCreateCharacter(charaterName=%s, templateName=%s, scaleFactor=%f, startingLocation=%s, hairTemplateName=%s, profession=%s, jedi=%d, useNewbieTutorial=%d, skillTemplate=%s, workingSkill=%s)", + getSUID(), + Unicode::wideToNarrow(clientCreate.getCharacterName()).c_str(), + clientCreate.getTemplateName().c_str(), + clientCreate.getScaleFactor(), + clientCreate.getStartingLocation().c_str(), + clientCreate.getHairTemplateName().c_str(), + clientCreate.getProfession().c_str(), + static_cast(clientCreate.getJedi()), + static_cast(clientCreate.getUseNewbieTutorial()), + clientCreate.getSkillTemplate().c_str(), + clientCreate.getWorkingSkill().c_str())); + + if (!clientCreate.getUseNewbieTutorial() && !m_canSkipTutorial) + { + LOG("TraceCharacterCreation", ("%d failed character creation. The client is not allowed to skip the tutorial", getSUID())); + // This is probably a hack attempt, because the Client was already told they couldn't skip the tutorial + LOG("ClientDisconnect", ("Disconnecting %u because they tried to skip the tutorial without permission.\n",getSUID())); + disconnect(); + } + else if (clientCreate.getJedi() && !m_canCreateJediCharacter) + { + LOG("TraceCharacterCreation", ("%d failed character creation. The request character type was Jedi, but this client cannot create a Jedi character", getSUID())); + // This is probably a hack attempt, because the Client was already told they couldn't create a character + LOG("ClientDisconnect", ("Disconnecting %u because they tried to create a Jedi character without permission.\n",getSUID())); + disconnect(); + } + else if (!clientCreate.getJedi() && !m_canCreateRegularCharacter) + { + LOG("TraceCharacterCreation", ("%d failed character creation. The client is not allowed to create any characters", getSUID())); + // This is probably a hack attempt, because the Client was already told they couldn't create a character + LOG("ClientDisconnect", ("Disconnecting %u because they tried to create a regular character without permission.\n",getSUID())); + disconnect(); + } + else if (m_hasRequestedCharacterCreate) + { + LOG("TraceCharacterCreation", ("%d failed character creation. The client has already requested character creation on this connection", getSUID())); + LOG("ClientDisconnect", ("Disconnecting %u because the client has already requested character creation on this connection.\n",getSUID())); + disconnect(); + } + else if (m_hasCreatedCharacter) + { + LOG("TraceCharacterCreation", ("%d failed character creation. A character has been created on this or another galaxy for this account while this connection was up", getSUID())); + LOG("ClientDisconnect", ("Disconnecting %u because a character has been created on this or another galaxy for this account while this connection was up.\n",getSUID())); + disconnect(); + } + else if (clientCreate.getCharacterName().length()==0) + { + LOG("TraceCharacterCreation", ("%d failed character creation. The character's name is empty", getSUID())); + LOG("ClientDisconnect",("Disconnecting %u because they tried to create a character with no name.\n",getSUID())); + disconnect(); + } + else + { + Unicode::String biography(clientCreate.getBiography()); + if (biography.length() > 1024) + { + IGNORE_RETURN( biography.erase(1024) ); + DEBUG_REPORT_LOG(true,("Biography shortened to 1024 characters.\n")); + } + + if (m_isAdminAccount) + { + ConnectionCreateCharacter connectionCreate( + m_suid, + clientCreate.getCharacterName(), + clientCreate.getTemplateName(), + clientCreate.getScaleFactor(), + clientCreate.getStartingLocation(), + clientCreate.getAppearanceData(), + clientCreate.getHairTemplateName(), + clientCreate.getHairAppearanceData(), + clientCreate.getProfession(), + clientCreate.getJedi(), + biography, + clientCreate.getUseNewbieTutorial(), + clientCreate.getSkillTemplate(), + clientCreate.getWorkingSkill(), + m_isAdminAccount, + false, + m_featureBitsGame); + + ConnectionServer::sendToCentralProcess(connectionCreate); + LOG("TraceCharacterCreation", ("%d character creation request sent to CentralServer", getSUID())); + } + else + { + // for regular players, do one final check with the LoginServer + // to make sure the character can be created (i.e. that character + // limits have not been exceeded) + delete m_pendingCharacterCreate; + m_pendingCharacterCreate = new ConnectionCreateCharacter( + m_suid, + clientCreate.getCharacterName(), + clientCreate.getTemplateName(), + clientCreate.getScaleFactor(), + clientCreate.getStartingLocation(), + clientCreate.getAppearanceData(), + clientCreate.getHairTemplateName(), + clientCreate.getHairAppearanceData(), + clientCreate.getProfession(), + clientCreate.getJedi(), + biography, + clientCreate.getUseNewbieTutorial(), + clientCreate.getSkillTemplate(), + clientCreate.getWorkingSkill(), + m_isAdminAccount, + false, + m_featureBitsGame); + + LOG("TraceCharacterCreation", ("%d character creation request awaiting final verification from LoginServer", getSUID())); + + ValidateAccountMessage vcm(m_suid, 0, m_featureBitsSubscription); + ConnectionServer::sendToCentralProcess(vcm); + } + + m_hasRequestedCharacterCreate = true; + } + } + break; + } + case constcrc("ClientRandomNameRequest") : + { + ClientRandomNameRequest clientRandomName(ri); + + RandomNameRequest randomNameRequest(m_suid, clientRandomName.getCreatureTemplate()); + ConnectionServer::sendToCentralProcess(randomNameRequest); + LOG("TraceCharacterCreation", ("%d requested a random name. Request sent to CentralServer", getSUID())); + break; + } + case constcrc("ClientVerifyAndLockNameRequest") : + { + ClientVerifyAndLockNameRequest clientVerifyAndLockNameRequest(ri); + + VerifyAndLockNameRequest verifyAndLockNameRequest(m_suid, NetworkId::cms_invalid, clientVerifyAndLockNameRequest.getTemplateName(), clientVerifyAndLockNameRequest.getCharacterName(), m_featureBitsGame); + ConnectionServer::sendToCentralProcess(verifyAndLockNameRequest); + LOG("TraceCharacterCreation", ("%d requested a verify and lock of name: %s. Request sent to CentralServer", getSUID(), Unicode::wideToNarrow(verifyAndLockNameRequest.getCharacterName()).c_str())); + break; + } + case constcrc("LagRequest") : + { + // TODO: why is this commented out? + // handleLagRequest(); + break; + } + } } } catch(const Archive::ReadException & readException) @@ -1413,7 +1403,6 @@ void ClientConnection::onCharacterValidated(bool isValid, const NetworkId &chara if (isValid) { - LOG("TraceCharacterSelection", ("%d received a validation response. The character (%s: %s) at (%s,%f,%f,%f,%s) selected is valid", getSUID(), character.getValueString().c_str(), characterName.c_str(), scene.c_str(), coordinates.x, coordinates.y, coordinates.z, container.getValueString().c_str())); LOG("CustomerService", ("Login:%s received a validation response. The character (%s: %s) at (%s,%f,%f,%f,%s) selected is valid", describeAccount(this).c_str(), character.getValueString().c_str(), characterName.c_str(), scene.c_str(), coordinates.x, coordinates.y, coordinates.z, container.getValueString().c_str())); m_targetScene = scene; @@ -1424,33 +1413,6 @@ void ClientConnection::onCharacterValidated(bool isValid, const NetworkId &chara m_hasSelectedCharacter = true; - - - // If they don't have access to mustafar but are on the planet, move them to a safe spot - uint32 features = getGameFeatures(); - if ( (strncmp(scene.c_str(), "mustafar", strlen("mustafar")) == 0 ) && - ( (features & ClientGameFeature::TrialsOfObiwanRetail) == 0 ) ) - { - // mos eisley starport - m_sendToStarport = true; - m_targetScene = "tatooine"; - m_targetCoordinates.x = 3528; - m_targetCoordinates.y = 4; - m_targetCoordinates.z = -4804; - - // Make sure Central knows the right sceneId for the player - GenericValueTypeMessage > > const msg( - "SetSceneForPlayer", - std::make_pair( - m_characterId, - std::make_pair("tatooine", false))); - ConnectionServer::sendToCentralProcess(msg); - - - LOG("TraceCharacterSelection", ("Character didn't have Mustafar feature bit, moving to Tattoine.")); - } - - // ask CentralServer to suggest a game server for this character // (Central will forward the request to a Planet Server) @@ -1582,10 +1544,6 @@ void ClientConnection::onValidateClient (uint32 suid, const std::string & userna m_featureBitsGame &= ~ClientGameFeature::HousePackupReward; m_featureBitsGame &= ~ClientGameFeature::BuddyProgramReward; } - - //hack to prevent non-jtl users from using jtl assets. In this hack, clients who didn't patch through jtl patcher will send us information requesting we clear their jtl bit since they are supposed to go through the jtl patcher. We can remove this hack once the launch pad takes care of this for us. - m_featureBitsGame &= ~m_gameBitsToClear; - //end hack ValidateAccountMessage vcm(m_suid, 0, m_featureBitsSubscription); ConnectionServer::sendToCentralProcess(vcm);