#include "LoginServ.h" #include "../../src/Utility.h" struct DeleteCharacterTempData { wchar_t name[30]; ushort nameLength; }; void SendError(int errorCode, int verifCode, NLsocket sockId); int CompleteDeleteCharacter(QUERY_RESULT* pResult, ClientData* pMyClient); int HandleOpcodeCHARACTER_DELETE(Packet* pck, GwClient* pClient) { GetClientData(); //Client is not authenticated if(!pMyClient->authenticated) { SendError(24, pMyClient->verifCode, pMyClient->socketId); return pClient->inBuffer.size(); } pMyClient->verifCode=pck->ReadLong(); //Save stuff for processing after query DeleteCharacterTempData* pTd=new DeleteCharacterTempData; memset(pTd->name, 0, 60); pTd->nameLength=pck->ReadShort(); pck->Read(pTd->name, pTd->nameLength * 2); printf("Deleting: "); wprintf((wchar_t*)pTd->name); printf("\n"); //------------------------------------------------------------------------------- //Get the character ID so we can erase the character from the account later //------------------------------------------------------------------------------- char query[450]; char nameHex[130]; Util::BinToHex((unsigned char*)pTd->name, 60, nameHex); sprintf(query, "SELECT ID, HeadArmor, ChestArmor, ArmsArmor, LegArmor, FeetArmor FROM characters WHERE Name=%s AND OwnerAccountID=%u LIMIT 1", nameHex, pMyClient->accountId); pMyClient->queryId=gLoginServer.mDatabase.Query(query, (long)strlen(query)); pMyClient->pTempData=(void*)pTd; pMyClient->QueryProcess=CompleteDeleteCharacter; return pClient->inBuffer.size(); } int CompleteDeleteCharacter(QUERY_RESULT* pResult, ClientData* pMyClient) { if(pResult->pResult == NULL) { SendError(46, pMyClient->verifCode, pMyClient->socketId); return -1; } DeleteCharacterTempData* pTd=(DeleteCharacterTempData*)pMyClient->pTempData; MYSQL_ROW row=mysql_fetch_row(pResult->pResult); if(row == NULL) { SendError(46, pMyClient->verifCode, pMyClient->socketId); return -2; } ulong characterId=atoi(row[0]); char query[140]; sprintf(query, "DELETE FROM items WHERE OwnerCID=%u", characterId); gLoginServer.mDatabase.Query(query, (long)strlen(query)); sprintf(query, "DELETE FROM characters WHERE ID=%u AND OwnerAccountID=%u LIMIT 1", characterId, pMyClient->accountId); gLoginServer.mDatabase.Query(query, (long)strlen(query)); printf("Character deleted!\n"); GwClient* pClient=gLoginServer.mpLoginServer->AccessGwClient(pMyClient->socketId); pClient->WriteShort(ServerOpcode("STREAM_TERMINATOR")); pClient->WriteLong(pMyClient->verifCode); pClient->WriteLong(0); return 0; }