// *************************************************************** // Function: ICProcessing.cpp // *************************************************************** /* Processes messages from the login server. */ #include "Main.h" #include "../../src/IC.h" void CommandProcessing(char* pCommandString, bool adminConsole, void* pLir, Player* pPlayer); void IcProcessAuthPassRequest(NetMessage* pData, NetMessage *s, unsigned char* pDest); void IcProcessIncorrectAuthPass(NetMessage* pData, NetMessage* s, unsigned char* pDest); void IcProcessNoClientWithIp(NetMessage* pData, NetMessage* s, unsigned char* pDest); void IcProcessActiveClientCharCreate(NetMessage* pData, NetMessage* s, unsigned char* pDest); void IcProcessActiveClientInstance(NetMessage* pData, NetMessage* s, unsigned char* pDest); void IcProcessCharacterCreated(NetMessage* pData, NetMessage* s, unsigned char* pDest, bool charCreated); void IcProcessLsPlayerAction(NetMessage* pData, NetMessage* s, unsigned char* pDest); void ProcessMapChange(NetMessage* pData, NetMessage* s, unsigned char* pDest); void DeleteLeftOverById(int id); vector gLeftOverPackets; /* ###--Packet headers and their meanings--### Note: This is only for packets sent from within this function. See the login server icprocess cpp file for the recieved packet header meanings. ID# Size Meaning ----- ------ ------------------------------------------------------------------------------------------------------ 0x01 36 This packet contains our password hash and our ip. Is used in authorization. 0x02 4+4(8) This packet contains an IP of a client who has connected and the client Id. We are asking the server if this IP is logged in and on the active clients list. 0x03 X This packet contains the character creation info. Name and appearance. 0x04 4 This packet tells the game server how many players are on it. 0x05 X This packet contains the game server response to a command used via the admin console. 0x06 X This packet tells the auth server to remove the instance status on a player 0x07 X This packet tells the auth server to kick the specified client 0x08 X This packet tells the */ //************************************ // Name: InternalCommunicationsProcess // // Processes the internal communications messages. // // Parameters: // // Return: // //************************************ void InternalCommunicationsProcess() { //-------------------------------------------------- //Cycle through all the packets on queue //-------------------------------------------------- NetMessage d(0, 0, 0); while(gpInternalComm->GetNextNetMessage(&d)==0) { assert(d.networkId>0); NetMessage s; s.networkId=d.networkId; switch(d.dataSize) { //If this is a delete local client data message. (The clientconnection has been lost) case CLIENT_DISCONNECTED: assert(d.networkId>0); DeleteLeftOverById(d.networkId); gShuttingDown=true; break; default: assert(d.pData!=NULL); //Verify the header and the received packet size switch(CheckHeaderAndSize(&d)) { //First check to see if the received packet size is //smaller than what is specified in the header. case HOLDING_LOWSIZE: ProcessLowSize(&d, &gLeftOverPackets, NULL); gCoreLog.debug("Holding due to low size: "); break; //We have received more data than the packet contains. I.E. We have recieved 1.x packets. Split the data //into two packets and store one as incomplete. Does not need a break because it generates a proper packet. case HOLDING_HIGHSIZE: ProcessHighSize(&d, &gLeftOverPackets, NULL); gCoreLog.debug("Holding due to high size!"); //There are no problems with the data we have recieved. case NOT_HOLDING: unsigned char* pDest=d.pData; //gCoreLog.LogUnknownPacket(dest,d.dataSize); switch(pDest[0]) { //Check to see if the server wants our password and send our password hash. case LS_REQUEST_AUTH_ATTEMPT: IcProcessAuthPassRequest(&d, &s, pDest); break; //Incorrect authorization password. The server must shutdown. case LS_INCORRECT_AUTH_PASS: IcProcessIncorrectAuthPass(&d, &s, pDest); break; //Successfully authorized with the login server case LS_AUTHORIZATION_SUCCESS: gCoreLog.notice("Authorized with the Login Server"); break; //No active client exists with that IP. Terminate the connection with the client ASAP. case LS_X_NOT_AUTHENTICATED: IcProcessNoClientWithIp(&d, &s, pDest); break; //Active client exists with this IP. Extract the account id and store in the proper logininfo. case LS_X_AUTHENTICATED_CHAR_CREATE: IcProcessActiveClientCharCreate(&d, &s, pDest); break; //We are loading into an instance. case LS_X_AUTHENTICATED_INSTANCE: IcProcessActiveClientInstance(&d, &s, pDest); break; //The character has been created! For now this will give the client an error 7 case LS_CHARACTER_CREATED: IcProcessCharacterCreated(&d, &s, pDest, true); break; //We have to perform an action on the player the auth server wants o_O case LS_PLAYER_ACTION: IcProcessLsPlayerAction(&d, &s, pDest); break; case LS_CHANGE_MAP: ProcessMapChange(&d, &s, pDest); break; case LS_ADMIN_CONSOLE_COMMAND: if (true) { short l_net_id=Read_uShort(pDest+2); char aCmdLine[251]; memset(aCmdLine, 0, 251); memcpy(aCmdLine, pDest+4, d.dataSize-4); CommandProcessing(aCmdLine, true, &l_net_id, NULL); } break; //We have received an invalid packet. default: gCoreLog.warning("Unknown IC packet: %X %X", pDest[0], pDest[1]); gCoreLog.LogUnknownPacket(pDest, d.dataSize); } } } //---------------------------------------------------------------- //free the memory used by the NetMessage //---------------------------------------------------------------- if (d.pData!=0){delete [] d.pData;} RepopulatePacketQueue(gpInternalComm, &gLeftOverPackets); } } //************************************ // Name: DeleteLeftOverById // // Deletes partial packet data for specified id. // // Parameters: // id - Client network id // // Return: // //************************************ void DeleteLeftOverById(int id) { assert(id>0); vector::iterator itr; for (itr=gLeftOverPackets.begin(); itr!=gLeftOverPackets.end(); itr++) { if (itr->networkId==id) { delete [] itr->pData; gLeftOverPackets.erase(itr); break; } } } //************************************ // Name: Icc_CleanUp // // Cleans up any allocations made for partial packets. // // Parameters: // // Return: // //************************************ void Icc_CleanUp() { vector::iterator itr; for (itr=gLeftOverPackets.begin(); itr!=gLeftOverPackets.end(); itr++) { if (itr->pData!=NULL){delete [] itr->pData;} } if (gLeftOverPackets.size()>0){gLeftOverPackets.clear();} } //************************************ // Name: NotifyLsOfPlayerDisconnect // // Notifies login server that a player has disconnected. // // Parameters: // lsNetId - Player's login server network id // // Return: // //************************************ void NotifyLsOfPlayerDisconnect(unsigned long lsNetId) { unsigned char pck[6]; PreparePacket(GS_PLAYER_DISCONNECTED, &lsNetId, sizeof(long), pck); NetMessage s; s.networkId=gpInternalComm->GetClientModeId(); s.pData=pck; s.dataSize=6; gpInternalComm->SendData(&s); }