// *************************************************************** // Function: LocalDataMethods.cpp // *************************************************************** #include "Main.h" #include "LocalData.h" #include "GameServerData.h" //************************************ // Name: AccessLocalData // // Access LOCAL_DATA for /id/ // // Parameters: // id - Client's connection network id // // Return: // NOT NULL - LOCAL_DATA for the connection // NULL - No LOCAL_DATA for the connection could be found. //************************************ LOCAL_DATA* AccessLocalData(int id) { hash_map::iterator itr=gLoginInfo.find(id); if (itr!=gLoginInfo.end()) { return &itr->second; } return NULL; } //************************************ // Name: FindLIRByID // // Access LOCAL_DATA for /id/ // // Parameters: // NetworkID - Client's connection network id // // Return: // NOT NULL - LOCAL_DATA for the connection // NULL - No LOCAL_DATA for the connection could be found. //************************************ LOCAL_DATA* FindLIRByID(short NetworkID) { assert(NetworkID>0); hash_map::iterator itr; itr=gLoginInfo.find(NetworkID); if (itr!=gLoginInfo.end()) { return &itr->second; } return NULL; } //************************************ // Name: DeleteLocalInfoById // // Removes LOCAL_DATA for /networkId/ // // Parameters: // networkId - Client's network id // // Return: // //************************************ void DeleteLocalInfoById(short networkId) { assert(networkId>0); if (FindLIRByID(networkId)!=NULL) { gLoginInfo.erase(networkId); return; } } //************************************ // Name: FindAuthenticatedClientWithIP // // Finds an authenticated client that is connected with an ip of /pIp/ // // Parameters: // pIp - Client's ip address in byte form // // Return: // NOT NULL - LOCAL_DATA for the found client // NULL - No client found //************************************ LOCAL_DATA* FindAuthenticatedClientWithIP(unsigned char* pIp) { assert(pIp!=NULL); hash_map::iterator itr; for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED)) { SOCKETINFO s=gpLoginServer->GetClientById(itr->second.networkId); if (memcmp(s.ip, pIp, 4)==0) return &itr->second; } } return NULL; } //************************************ // Name: RevokeAuthentication // // Revokes the authentication status of the specified player. If the player is on a game server. He/she will be kicked. // // Parameters: // networkId - Player's network id // // Return: // //************************************ void RevokeAuthentication(short networkId) { LOCAL_DATA *lir=FindLIRByID(networkId); if (lir!=NULL) { if (BIT_TEST(lir->bitfield, LD_AUTHENTICATED)) { if (lir->gameServerId>0) { KickFromGameServer(lir->gameServerId, lir->accountId); } lir->timesZoned=0; BIT_CLR(lir->bitfield, LD_DISPATCHED); BIT_CLR(lir->bitfield, LD_AUTHENTICATED); } } }