#include "Main.h" #include "../../src/IC.h" #include "../../src/SharedStructures.h" struct CCNameCheck { unsigned char dest[1000]; NetMessage d; char name[38]; short nameLength; }; void PropheciesRPGCCProf(PLAYER_DATA* pLir); //This function sends an error to the client void SendCharacterCreateError(int errorCode, short networkId) { CompiledPacket pck; pck.AddShort(ServerOpcode(9)); pck.AddLong(errorCode); Util::SendCompiledPacket(&pck, networkId, gpGameServer); } int CCCheckName(QUERY_RESULT* pQueryResult, PLAYER_DATA* pLir) { CCNameCheck *cc=(CCNameCheck*)pLir->pTempData; unsigned char* pData=cc->dest; NetMessage d=cc->d; unsigned char* pName_unicode=(unsigned char*)cc->name; unsigned short name_length=cc->nameLength; NetMessage s; //--------------------------------------------------- //This character name is already in use //--------------------------------------------------- if (mysql_num_rows(pQueryResult->pResult)>0) { SendCharacterCreateError(0x1D, pLir->networkId); } //-------------------------------------------- //The character name is not already in use //Check for restricted names //-------------------------------------------- else { char temp[50]; strcpy(temp, (char*)pName_unicode); for (unsigned int i=0; i19) { name_allowed=false; } else { //check name against the currently restricted names for (unsigned int i=0; inetworkId); } //-------------------------------------------------- //The name is allowed //-------------------------------------------------- else { //Save the items to the database for (int i=0; i<5; i++) { pLir->pCharCreate->armor[i].GenerateId(pLir->accountId, 1, &pLir->myItems); pLir->pCharCreate->armor[i].SetItemStorageLocation(LOC_IN_STORAGE); pLir->pCharCreate->armor[i].Save(); } //Create the new character message and send it to the auth server CREATE_CHARACTER charMsg; memset(&charMsg, 0, sizeof(CREATE_CHARACTER)); unsigned char pckBuf[sizeof(CREATE_CHARACTER)+2]; //Appearance memcpy(charMsg.appearance, pData+4+name_length*2, 4); //Name length charMsg.nameLength=name_length; //Unicode name memcpy(charMsg.name, pName_unicode, (int)name_length); //Account id charMsg.accountId=pLir->accountId; //Character type charMsg.appearance[4]=(int)pLir->pCharCreate->isPvP; s.dataSize=PreparePacket(GS_CREATE_CHARACTER, &charMsg, sizeof(CREATE_CHARACTER), pckBuf); s.networkId=gpInternalComm->GetClientModeId(); s.pData=pckBuf; gpInternalComm->SendData(&s); } } return 0; } int TranslateBodyPart(int num) { if (num==4){return 0;}//head if (num==2){return 1;}//chest if (num==6){return 2;}//hands if (num==3){return 3;}//legs if (num==5){return 4;}//feet return 0; } int TranslateDyeColor(int num) { if (num==9){return 0;}//gray dye if (num==2){return 1;}//blue if (num==3){return 2;}//green if (num==4){return 3;}//purple if (num==5){return 4;}//red if (num==6){return 5;}//yellow if (num==7){return 6;}//brown if (num==8){return 7;}//orange return 0; } void ExtractItemGlue(unsigned char* pData, int ds, PLAYER_DATA* pLir) { for (int i=0; ids-1){} else { unsigned char* t=pData+i+8; unsigned char tup[2]={0x00, 0x80}; if (memcmp(t, tup, 2)==0) { for (int j=0; j<5; j++) { if (pLir->pCharCreate->itemGlue[j]==-1) { memcpy(&pLir->pCharCreate->itemGlue[j], (void*)(pData+i+2), 2); //LogKnownData("ItemGlue", (void*)(data+i+2), 2); break; } } } } } } } int BPToPosition2(int num) { if (num==0){return 4;}//head if (num==1){return 2;}//chest if (num==2){return 6;}//hands if (num==3){return 3;}//legs if (num==4){return 5;}//feet return 0; } int HandleOpcode_CHARCREATE_DEFAULT_DYE(NetMessage* pData, PLAYER_DATA* pLir) { NetMessage s; s.networkId=pData->networkId; //check if this is the 34 byte packet sent asking for more data? if (pLir->pCharCreate->step==1) { gCoreLog.debug("WE received the 34 byte packet!"); //finish sending the data to the client char file[200]; sprintf(file, "Data/Packets/CharacterCreation/"); gPacketManager.DirSwitch(file); //Extract the item glue we must use short ds=0; unsigned char* pPckData=gPacketManager.GetData("A34Data1", &ds); ExtractItemGlue(pPckData, ds, pLir); while((s.pData=gPacketManager.GetData("A34Data1", &s.dataSize, 2920))!=NULL) { gpGameServer->SendData(&s); } pLir->pCharCreate->step++; pLir->pCharCreate->defaultdye=pData->pData[9]; //CoreLog.LogKnownData("Pvp", dest, d.dataSize); //Check PvP status of this character if (pData->pData[4] == 0) { pLir->pCharCreate->isPvP=true; } for (unsigned int i=0; i<5; i++) { gItemDefMan.CreateArmor("Starter", &pLir->pCharCreate->armor[i], i, 1); pLir->pCharCreate->armor[i].SetColorWithDye(pLir->pCharCreate->defaultdye); pLir->pCharCreate->armor[i].SetItemStoragePosition(BPToPosition2(i)); } PropheciesRPGCCProf(pLir); } return 34; } //check to see if a profession packet has arrived int HandleOpcode_CHARCREATE_PROFESSION(NetMessage* pData, PLAYER_DATA* pLir) { pLir->pCharCreate->campaign=pData->pData[2]; pLir->pCharCreate->profession=pData->pData[3]; pLir->pCharCreate->defaultdye=pData->pData[7]; PropheciesRPGCCProf(pLir); return 32; } //If a dye packet has arrived int HandleOpcode_CHARCREATE_DYE_INFO(NetMessage* pData, PLAYER_DATA* pLir) { NetMessage s; s.networkId=pData->networkId; int server_bp=TranslateBodyPart(pData->pData[2]); int dye_color=pData->pData[3]; pLir->pCharCreate->armor[server_bp].SetColorWithDye(dye_color); CompiledPacket pck; pck.AddShort(ServerOpcode(3)); pck.AddLong(pLir->pCharCreate->itemGlue[server_bp]); unsigned char item_pck[500]; int size=pLir->pCharCreate->armor[server_bp].ToItemPacket(item_pck); pck.Add(item_pck, size, false); pck.AddShort(ServerOpcode(4)); pck.AddLong(pLir->pCharCreate->itemGlue[server_bp]); pck.AddByte(pLir->pCharCreate->profession); pck.AddShort(ServerOpcode(7)); pck.AddLong(pLir->pCharCreate->itemGlue[server_bp]); pck.AddLong(pLir->pCharCreate->itemGlue[server_bp]); s.pData=pck.GetString(&s.dataSize); gpGameServer->SendData(&s); //Store the dye in our dye array pLir->pCharCreate->dyes[TranslateBodyPart((int)pData->pData[2])]=pData->pData[3]; pLir->pCharCreate->dyeTimer=(int)TimerGetTime();//*/ return 4; } //We have received a character creation name, validate it int HandleOpcode_CREATE_CHARACTER(NetMessage* pData, PLAYER_DATA* pLir) { //Extract the name from the packet int name_length=pData->pData[2]; unsigned char name_unicode[100]; memset(name_unicode, 0, 100); memcpy(name_unicode, pData->pData+4, name_length*2); Util::StripUnicode(name_unicode); //Check if the name is already in the database char query[400]; sprintf(query, "SELECT Name FROM characters WHERE Name = '%s' LIMIT 1", name_unicode); pLir->queryId=gDatabase.Query(query, strlen(query)); CCNameCheck* nc=new CCNameCheck; nc->d=*pData; strcpy(nc->name, (char*)name_unicode); memcpy(nc->dest, pData->pData, pData->dataSize); nc->nameLength=(short)name_length; pLir->pTempData=nc; pLir->QueryProcess=CCCheckName; gCoreLog.debug("Validating character name..."); return 12 + name_length; }