// *************************************************************** // Function: CreateNewPvECharacter.cpp // *************************************************************** #include "Main.h" #include #include "LocalData.h" #include "../../src/SharedStructures.h" //************************************ // Name: CreateNewCharacter // // Processes the temporary item query. Creates the character if it can and sends a response back to the game server. // // Parameters: // pResult - Database query result // pLir - Player's data // // Return: // //************************************ int CreateNewCharacter(QUERY_RESULT* pResult, LOCAL_DATA* pLir) { if (pResult->pResult==NULL) { gCoreLog.error("Character creation query failed!"); gpLoginServer->Kick(pLir->networkId); return -1; } if (mysql_num_rows(pResult->pResult)!=5) { char query[210]; sprintf(query, "SELECT ID, Data, ItemLocType FROM items WHERE OwnerCID=1 AND OwnerAID=%u", pLir->accountId); pLir->queryId=gDatabase.Query(query, (long)strlen(query)); pLir->QueryProcess=CreateNewCharacter; return 1; } //char *name, unsigned char *app, int AccountID, char *armors CREATE_CHARACTER *character_msg=(CREATE_CHARACTER*)pLir->pTempData; assert(character_msg!=NULL); //Extract the name and appearance from the packet char name[50]; strcpy(name, (char*)character_msg->name); //Extract the appearance unsigned char *pApp=character_msg->appearance; //Extract the account id unsigned int account_id=pLir->accountId; //------------------------------------------------ //Get an unused character id # //------------------------------------------------ srand((unsigned int)TimerGetTime()); int char_id=gData.freeCharacterID; gData.freeCharacterID++; char queryFC[300]; sprintf(queryFC, "UPDATE cfg_server_options SET Setting=\"%d\" WHERE OptionName=\"Character_Free_ID_Count\" LIMIT 1", gData.freeCharacterID); gDatabase.Query(queryFC, (long)strlen(queryFC)); long num_items=0; Item* pItems=Item::ConvertResultSet(pResult->pResult, &num_items); //Update our armors to use the new character id vector my_items; for (int i=0; i<5; i++) { pItems[i].Delete(); pItems[i].GenerateId(account_id, char_id, &my_items); pItems[i].SetItemStorageLocation(LOC_IN_EQUIPPED); my_items.push_back(pItems[i]); } if (pItems!=NULL && num_items>1) { delete [] pItems; } else if (pItems!=NULL) { delete pItems; } pItems=NULL;//*/ //------------------------------------------------------------- //Create the query that adds our character to the database //Should be modified at a later date if armor storage changes. //------------------------------------------------------------- ostringstream s; s << "INSERT INTO characters ("; s << "Name, "; s << "ID, "; s << "HeightSex, "; s << "HairSkinColor, "; s << "ProfessionHairStyle, "; s << "CampaignFace, "; s << "Level, "; s << "CharacterType, "; s << "HeadArmor, "; s << "ChestArmor, "; s << "ArmsArmor, "; s << "LegArmor, "; s << "FeetArmor, "; s << "OwnerAccountID"; s << ")"; s << "VALUES("; s << "\"" << name << "\", "; //Character name s << char_id << ", "; //Character ID s << (unsigned int)pApp[0] << ", "; //HeightSex s << (unsigned int)pApp[1] << ", "; //HairSkinColor s << (unsigned int)pApp[2] << ", "; //ProfessionHairStyle s << (unsigned int)pApp[3] << ", "; //CampaignFace //Check for PvP character if (character_msg->appearance[4]==1) { s << gServerConfig.maxLevel << ", "; //Level 1 s << "1"; //PvP character } else { s << "1, "; //Level 1 s << "0"; //Not PvP character } assert(my_items.size()==5); for (unsigned int i=0; iaccountId; gpInternalComm->SendData(&s2); //reset our local data RevokeAuthentication(pLir->networkId); gpLoginServer->Kick(pLir->networkId); return 0; }