#include "Main.h" void DecrementPlayerCount(); void NotifyLsOfPlayerDisconnect(unsigned long ASNetID); void ProcessStreams(); hash_map GameServInfo; //************************************ // Name: PacketChop // // Cuts a packet out of the data. Leaving the remaining data to be processed. // // Parameters: // pDataArray - Pointer to the array of byte data // pData - Network data // size - Size of the packet. // // Notes: // o Cuts the leading [size] bytes off of the data. Packaging the remainder for processing. // // Return: // //************************************ void PacketChop3(unsigned char* pDataArray, NetMessage* pData, int size) { assert(pDataArray!=NULL); if (size==-1){return;} if (size==pData->dataSize){return;} NetMessage s; s.pData=pDataArray+size; s.dataSize=pData->dataSize-size; s.networkId=pData->networkId; gpGameServer->AddIncomingFront(&s); } //Processes the packets from the game server int ProcessPackets() { //process the streams, this is a not a packet reply processing method ProcessStreams(); //Cycle through all the packets on queue NetMessage pckData(0, 0, 0); while(gpGameServer->GetNextNetMessage(&pckData)==0) { assert(pckData.networkId>0); NetMessage s; s.networkId=pckData.networkId; PLAYER_DATA* lir; switch(pckData.dataSize) { case CLIENT_DISCONNECTED: lir=AccessLocalData(pckData.networkId); //------------------------------------------------------ //If the server has sent us a delete local client data //then delete it by id. //------------------------------------------------------ if (lir->instanceId>0) { Instance *instance=AccessInstance(lir->instanceId); if (instance!=NULL) { instance->RemovePlayer(pckData.networkId); } } //If this player is authorized with the login server //We must tell the login server to remove it as in-game and decrement the player count. if (lir->authorized) { PLAYER_DATA *ld=AccessLocalData(pckData.networkId); if (ld!=NULL && !ld->flags.test(LD_CHANGING_MAP)) { NotifyLsOfPlayerDisconnect(ld->lsnetworkId); } DecrementPlayerCount(); } DeleteLoginById(pckData.networkId); break; //------------------------------------------------------ //If a new client has connected. Ask the login server if //this IP has logged in. //------------------------------------------------------ case CLIENT_CONNECTED: if (true) { PLAYER_DATA l; l.networkId=pckData.networkId; l.establishedEncryptedConnection=false; typedef pair lpair; GameServInfo.insert(lpair(pckData.networkId, l)); lir=AccessLocalData(pckData.networkId); } break; //-------------------------------------------------------- //A packet we sent requested the exact time it was sent //be returned to me. //-------------------------------------------------------- case EVENT_TIME_SENT: //------------------------------------------------ //We have received the time a ping packet was sent //------------------------------------------------ if (pckData.extra2==1) { lir=AccessLocalData(pckData.networkId); lir->pingTimer=pckData.extra1; } break; default: //Make sure a login info exists for this id PLAYER_DATA* pLir=AccessLocalData(pckData.networkId); if (pLir!=NULL && pckData.dataSize>=2) { unsigned short opcode=Read_uShort(pckData.pData); hash_map::iterator itr; //Check the login server hash map itr=gClientOpcodesTable.find(opcode); if (itr!=gClientOpcodesTable.end()) { //No handler for this opcode if (itr->second.handler==NULL) { gCoreLog.debug("No handler found for %s", itr->second.name); gCoreLog.LogUnknownPacket(pckData.pData, pckData.dataSize); } else { gCoreLog.debug("Game Server Pck: %s", itr->second.name); //gCoreLog.LogUnknownPacket(pckData.pData,pckData.dataSize); int packet_size=itr->second.handler(&pckData, pLir); PacketChop3(pckData.pData, &pckData, packet_size); } } //Unknown packet else { if (pckData.pData!=NULL) { gCoreLog.LogUnknownPacket(pckData.pData, pckData.dataSize); //gpGameServer->Kick(pckData.networkId); } } } } //---------------------------------------------------------------- //free the memory used by the NetMessage //---------------------------------------------------------------- if (pckData.pData!=0 && pckData.dataSize>0){delete [] pckData.pData;} } return 0; } //************************************ // Name: AccessLocalData // // Accesses the player's local data. // // Parameters: // id - Player's network id // // Return: // NOT NULL - Pointer to player's data // NULL - No data for network id //************************************ PLAYER_DATA* AccessLocalData(int id) { hash_map::iterator itr=GameServInfo.find(id); if (itr!=GameServInfo.end()) { return &itr->second; } return NULL; } //************************************ // Name: DeleteLoginById // // Removes any local data for the network id // // Parameters: // id - Document // // Return: // //************************************ void DeleteLoginById(int id) { GameServInfo.erase(id); }