// *************************************************************** // Function: PlayCharacter.cpp // *************************************************************** #include "Main.h" #include "LocalData.h" #include "GameServerData.h" void SendError(int errorCode, int numLogins, short NetworkID); GAMESERVER_DATA* GetOptimalGameSrv(); struct CHARACTER_PLAY_TEMP_DATA { unsigned char* pData; NetMessage data; CHARACTER_PLAY_TEMP_DATA(unsigned char *dest2, NetMessage dd) { data=dd; pData=dest2; } }; //************************************ // Name: DispatchToGameServer // // Dispatches the client to the specified game server for character play. // // Parameters: // pPck - Destination byte buffer // loginAttempts - Number of login attempts // zoneID - Zone identification number. Specifies loading screen. // port - Game server port (GW ignores) // pIp - Byte buffer for IP address // TransferId1 - First transfer ID // TransferID2 - Second transfer ID // // Notes: // o Clients loading into the same instance share transfer ID's // // Return: // //************************************ void DispatchToGameServer(CompiledPacket* pPck, unsigned long loginAttempts, unsigned short zoneID, unsigned short port, unsigned char* pIp, unsigned long TransferId1, unsigned long TransferID2) { pPck->AddShort(ServerOpcode(10)); pPck->AddLong(loginAttempts); pPck->AddLong(TransferId1); pPck->AddShort(zoneID);//zone id pPck->AddLong(131072); pPck->AddShort(port); pPck->Add(pIp, 4, false); pPck->Fill(0, 16); pPck->AddLong(TransferID2); } //************************************ // Name: CompleteCharacterPlay // // Processes the database query that contains a player's character info required to play. // // Parameters: // pResult - Database query result // pLir - Player's local data // // Return: // //************************************ int CompleteCharacterPlay(QUERY_RESULT* pResult, LOCAL_DATA* pLir) { //Oh shiz the query failed if (pResult->pResult==NULL) { SendError(46, pLir->loginAttempts, pLir->networkId); return -1; } //Temporary data CHARACTER_PLAY_TEMP_DATA *temp_data=(CHARACTER_PLAY_TEMP_DATA*)pLir->pTempData; MYSQL_ROW row=mysql_fetch_row(pResult->pResult); //Oh shizzle no name found for play xD if (row!=0) pLir->characterId=atoi(row[0]); else { gCoreLog.warning("No name found for Play!"); gpLoginServer->Kick(pLir->networkId); return 0; } //Make sure the account can play this character bool allowed=false; int campaign_face=atoi(row[2]) >> 4; //Figure out what bit campaign this character uses int bit=0; if (campaign_face==0){bit=1;} else if (campaign_face==1){bit=2;} else if (campaign_face==2){bit=4;} if (bit>0) { if ((pLir->ownedCampaigns & bit)==bit) { allowed=true; } } if (!allowed) { SendError(165, pLir->loginAttempts, pLir->networkId); return -1; } //Send an update query to update the account's last played character char query[120]; sprintf(query, "UPDATE accounts SET LastCharacterPlayed=\"%s\" WHERE AccountID=\"%u\"@NOSTATUS", pLir->name, pLir->accountId); gDatabase.Query(query, (long)strlen(query)); gPacketManager.DirSwitch("Data/Packets/PlayCharacter/"); if (BIT_TEST(pLir->bitfield, LD_AUTHENTICATED)==false) { gpLoginServer->Kick(pLir->networkId); } //Set the zone id pLir->zoneId=atoi(row[1]);//Read_uShort(ns->dest+10); //---------------------------------------------- //Get the optimal game server //---------------------------------------------- GAMESERVER_DATA *pOptGameServ=GetOptimalGameSrv(); if (pOptGameServ!=NULL && !(pLir->accessLevel==50 && gServerStatus.adminLock)) { BIT_SET(pLir->bitfield, LD_LOAD_INTO_INSTANCE); CompiledPacket pck; unsigned short port=pOptGameServ->port; DispatchToGameServer(&pck, pLir->loginAttempts, pLir->zoneId, port, pOptGameServ->ip, pLir->transferId1, pLir->transferId2); Util::SendCompiledPacket(&pck, pLir->networkId, gpLoginServer); BIT_SET(pLir->bitfield, LD_DISPATCHED); pOptGameServ->currentPlayers++; } //No game servers available else { CompiledPacket pck; unsigned char ip[4]; memset(ip, 0, 4); DispatchToGameServer(&pck, pLir->loginAttempts, pLir->zoneId, 0, ip, pLir->transferId1, pLir->transferId2); Util::SendCompiledPacket(&pck, pLir->networkId, gpLoginServer); pLir->gameServerId=0; } delete [] temp_data->pData; return 0; } //************************************ // Name: ProcessCharacterPlay // // Handles the play character request from the client. // // Parameters: // pData - Network data // pLir - Player's local data // // Return: // //************************************ void ProcessCharacterPlay(NetMessage* pData, LOCAL_DATA* pLir) { if (!BIT_TEST(pLir->bitfield, LD_AUTHENTICATED)) { SendError(14, pLir->loginAttempts, pLir->networkId); return; } //Store data we will need when we process the results of the query CHARACTER_PLAY_TEMP_DATA *temp_data=new CHARACTER_PLAY_TEMP_DATA(0, *pData); temp_data->pData=new unsigned char[pData->dataSize]; memcpy(temp_data->pData, pData->pData, pData->dataSize); gCoreLog.debug("Getting char id for: %s", pLir->name); //Extract the login/play attempts //Get the character id char query[160]; sprintf(query, "SELECT ID, Location, CampaignFace FROM characters WHERE Name=\"%s\" AND OwnerAccountID=%u LIMIT 1", pLir->name, pLir->accountId); pLir->queryId=gDatabase.Query(query, (long)strlen(query)); pLir->QueryProcess=CompleteCharacterPlay; pLir->pTempData=(void*)temp_data; }