void MessageDispatch::registerSessionlessDispatchClient(uint32 accountId) { // Verify not allready registred. AccountClientMap::iterator iter = mAccountClientMap.find(accountId); if (iter == mAccountClientMap.end()) { DispatchClient* dispatchClient = new DispatchClient(); dispatchClient->setAccountId(accountId); mAccountClientMap.insert(std::make_pair(accountId,dispatchClient)); } }
void ChatMessageLib::sendChatRoomMessage(Channel* channel, BString galaxy, BString sender, BString message) const { ChatAvatarIdList::iterator iter = channel->getUserList()->begin(); #ifdef DISP_REAL_FIRST_NAME #else sender.toLower(); #endif // Check ignore list. BString loweredName = sender; loweredName.toLower(); uint32 loweredNameCrc = loweredName.getCrc(); while (iter != channel->getUserList()->end()) { // If sender present at recievers ignore list, don't send. if ((*iter)->getPlayer()->checkIgnore(loweredNameCrc)) { // Ignore player } else { DispatchClient* client = (*iter)->getPlayer()->getClient(); if (client == NULL) { LOG(warning) << "sendChatRoomMessage: Client not found for channel " << channel->getId(); } else { gMessageFactory->StartMessage(); gMessageFactory->addUint32(opChatRoomMessage); gMessageFactory->addString(SWG); gMessageFactory->addString(galaxy); gMessageFactory->addString(sender); gMessageFactory->addUint32(channel->getId()); gMessageFactory->addString(message); gMessageFactory->addUint32(0); Message* response = gMessageFactory->EndMessage(); client->SendChannelA(response, client->getAccountId(), CR_Client, 5); } } ++iter; } }
void ZoneServer::_connectToConnectionServer(void) { ProcessAddress processAddress; memset(&processAddress, 0, sizeof(ProcessAddress)); // Query the DB to find out who this is. // setup our databinding parameters. DataBinding* binding = mDatabase->CreateDataBinding(5); binding->addField(DFT_uint32, offsetof(ProcessAddress, mType), 4); binding->addField(DFT_string, offsetof(ProcessAddress, mAddress), 16); binding->addField(DFT_uint16, offsetof(ProcessAddress, mPort), 2); binding->addField(DFT_uint32, offsetof(ProcessAddress, mStatus), 4); binding->addField(DFT_uint32, offsetof(ProcessAddress, mActive), 4); // Execute our statement DatabaseResult* result = mDatabase->ExecuteSynchSql("SELECT id, address, port, status, active FROM config_process_list WHERE name='connection';"); uint32 count = static_cast<uint32>(result->getRowCount()); // If we found them if (count == 1) { // Retrieve our routes and add them to the map. result->GetNextRow(binding, &processAddress); } // Delete our DB objects. mDatabase->DestroyDataBinding(binding); mDatabase->DestroyResult(result); // Now connect to the ConnectionServer DispatchClient* client = new DispatchClient(); mRouterService->Connect(client, processAddress.mAddress, processAddress.mPort); // Send our registration message gMessageFactory->StartMessage(); gMessageFactory->addUint32(opClusterRegisterServer); gMessageFactory->addString(mZoneName); Message* message = gMessageFactory->EndMessage(); client->SendChannelA(message, 0, CR_Connection, 1); }
void MessageDispatch::handleSessionMessage(NetworkClient* client, Message* message) { DispatchClient* dispatchClient = 0; bool deleteClient = false; //boost::recursive_mutex::scoped_lock lk(mSessionMutex); message->ResetIndex(); // What kind of message is it? uint32 opcode; message->getUint32(opcode); // We want to intercept the opClusterClientConnect and opClusterClientDisconnect messages // so we can create account specific clients for use in async calls. if (opcode == opClusterClientConnect) { dispatchClient = new DispatchClient(); dispatchClient->setAccountId(message->getAccountId()); dispatchClient->setSession(client->getSession()); mAccountClientMap.insert(std::make_pair(message->getAccountId(),dispatchClient)); } else if (opcode == opClusterClientDisconnect) { // First find our DispatchClient. AccountClientMap::iterator iter = mAccountClientMap.find(message->getAccountId()); if(iter != mAccountClientMap.end()) { dispatchClient = (*iter).second; mAccountClientMap.erase(iter); DLOG(INFO) << "Destroying Dispatch Client for account " << message->getAccountId(); // Mark it for deletion deleteClient = true; } else { LOG(INFO) << "Could not find DispatchClient for account " << message->getAccountId() << " to be deleted."; client->getSession()->DestroyIncomingMessage(message); //lk.unlock(); return; } } else { AccountClientMap::iterator iter = mAccountClientMap.find(message->getAccountId()); if(iter != mAccountClientMap.end()) { dispatchClient = (*iter).second; } else { client->getSession()->DestroyIncomingMessage(message); //lk.unlock(); return; } /* else { dispatchClient = new DispatchClient(); dispatchClient->setAccountId(message->getAccountId()); dispatchClient->setSession(client->getSession()); mAccountClientMap.insert(message->getAccountId(), dispatchClient); } */ } //lk.unlock(); MessageCallbackMap::iterator iter = mMessageCallbackMap.find(opcode); if(iter != mMessageCallbackMap.end()) { // Reset our message index to just after the opcode. message->setIndex(4); // Call our handler (*iter).second(message, dispatchClient); } else { LOG(INFO) << "Unhandled opcode in MessageDispatch - " << opcode ; } // Delete the client here if we got a disconnect. if(deleteClient) { // We will delete the client when we delete the player or reconnect again. //delete dispatchClient; dispatchClient = NULL; } // We need to destroy the incoming message for the session here // We want the application to decide whether the message is needed further or not. // This is mainly used in the ConnectionServer since routing messages need a longer life than normal message->setPendingDelete(true); }