// *************************************************************** // Function: Login.cpp // *************************************************************** #include #include "Main.h" #include "Login.h" #include "LocalData.h" #include "GameServerData.h" #include "../../src/sha256.h" bool HashPassword(unsigned char* pSourceData, unsigned char* pDestBuffer); GAMESERVER_DATA* GetOptimalGameSrv(); void BuildAccountPermissions(CompiledPacket* pPck, LOCAL_DATA* pLir); void SendError(int errorCode, int numLogins, short NetworkID); bool GameServersFull(); //************************************ // Name: BuildAccountPermissions // // Builds the account permissions packet. // // Parameters: // pPck - Destination byte buffer // pLir - Player's data // // Return: // //************************************ void BuildAccountPermissions(CompiledPacket* pPck, LOCAL_DATA* pLir) { pPck->AddShort(ServerOpcode(6)); pPck->AddLong(pLir->loginAttempts); pPck->Fill(0x00, 4); pPck->AddLong(4); pPck->AddByte((unsigned char)pLir->ownedCampaigns); pPck->Fill(0, 9); pPck->AddByte(pLir->ownsEotn);//0x02=eye of the north pPck->Fill(0, 41);//total 51 unsigned char yu[]={0x04, 0x00, 0x01, 0x00, 0x06, 0x00}; pPck->Add(yu, 6, false); pPck->AddByte(0x11);//EULA accepted //0x09 } //************************************ // Name: WriteCharacterInfoStream // // Processes the item load query for the account. (Character armor) // // Parameters: // result - Database query result // lir - Player's data // // Return: // //************************************ int WriteCharacterInfoStream(QUERY_RESULT* pResult, LOCAL_DATA* lir) { CompiledPacket pck(true); NetMessage s(0, 0, lir->networkId); //If we loaded characters and items if (pResult!=NULL) { if (pResult->pResult==NULL) { gCoreLog.error("Getting items for account characters failed!", lir->accountId); SendError(56, lir->loginAttempts, lir->networkId); return -1; } //convert our temporary data back to the proper format PRE_ITEM_LOAD_TEMP_DATA *p_temp_data=(PRE_ITEM_LOAD_TEMP_DATA*)lir->pTempData; //Convert the result set to items long num_items=0; Item* pItems=Item::ConvertResultSet(pResult->pResult, &num_items); //Get real character info from the database and compile character packets from it bool saved_name=false; for (unsigned int i=0; i<(unsigned long)p_temp_data->numCharacters; i++) { //---------------------------------------------------- //There is a character here we must process //---------------------------------------------------- //Build the packet with our information CompiledPacket cp; cp.AddShort(ServerOpcode(7));//packet header cp.AddLong(lir->loginAttempts);//login attempts cp.Fill(0, 16);//md5 hash, just fill with zero for now cp.Fill(0, 4);//no clue //Add character name length cp.AddShort((short)strlen(p_temp_data->characters[i].name)); //Convert the name to unicode and add to the stream char name[39]; memset(name, 0, 39); strcpy(name, p_temp_data->characters[i].name); if (!saved_name) { strcpy(lir->name, p_temp_data->characters[i].name); saved_name=true; } Util::ConvertToUnicode((unsigned char*)name); cp.Add((unsigned char*)name, (unsigned long)strlen(p_temp_data->characters[i].name)*2, false); //Add in the crap after the character name unsigned char ac_header[39]= { 0x3E, 0x00, 0x06, 0x00, //Static? 0x94, 0x00, 0x38, 0x34, //Static? 0xf8=PvP 0x94=PvE? 0x31, 0x30, //Static? 32=PvP 31=PvE? 0x71, 0x00, 0x20, 0x00, //Character ID #? 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x43, 0x5C, 0x5C, 0x05, 0x5C, 0x5C, 0x5C, 0x5C }; //Character location unsigned short character_location=p_temp_data->characters[i].location; memcpy(ac_header+4, &character_location, 2); //Sex and height unsigned char height_sex=p_temp_data->characters[i].heightSex; memcpy(ac_header+10, &height_sex, 1); //Hair&Skin color unsigned char hair_and_skin_color=p_temp_data->characters[i].hairSkinColor; memcpy(ac_header+11, &hair_and_skin_color, 1); //Profession and hair style unsigned char profession_hairstyle=p_temp_data->characters[i].professionHairStyle; memcpy(ac_header+12, &profession_hairstyle, 1); //Campaign and face unsigned char campaign_face=p_temp_data->characters[i].campaignFace; memcpy(ac_header+13, &campaign_face, 1); //Level unsigned char character_level=0; character_level=(p_temp_data->characters[i].level << 4) + ((campaign_face >> 4)+1); memcpy(ac_header+30, &character_level, 1); //Set a byte containing: high level, character type, secondary profession, show helm unsigned char secondary_profession=0; //If needed set high level bit if (p_temp_data->characters[i].level>15){BIT_SET(secondary_profession, 1);} //Set the PvP Only bit if (p_temp_data->characters[i].characterType>0){BIT_SET(secondary_profession, 0x02);} //Set the secondary profession if (p_temp_data->characters[i].secondProfession>10){p_temp_data->characters[i].secondProfession=1;} secondary_profession+=(p_temp_data->characters[i].secondProfession << 2);//pil->characters[i].SecondProfession; //No clue BIT_SET(secondary_profession, 0x40); //Set the show helm bit BIT_SET(secondary_profession, 0x80); memcpy(ac_header+31, &secondary_profession, 1); cp.Add(ac_header, 39, false); //Add the item data, item ID and colors for (int k=0; k<5; k++) { for (unsigned int j=0; j<(unsigned int)num_items; j++) { if (memcmp(p_temp_data->characters[i].armors[k], &pItems[j], 12)==0) { Item* pItem=&pItems[j]; cp.Add((unsigned char*)&pItem->GetRawItemData()->gwId, 2, false); unsigned char col[3]; col[0]=pItem->GetRawItemData()->color[1]; col[1]=pItem->GetRawItemData()->color[2]; col[2]=pItem->GetRawItemData()->color[0]; cp.Add(col, 3, false); } } } s.pData=cp.GetString(&s.dataSize); pck.Add(s.pData, s.dataSize, true); } //Clean up if (num_items>0){delete [] pItems;} if (p_temp_data->characters!=NULL){delete [] p_temp_data->characters;} } //Add the account info. This packet contains the interface positioning data if (lir->pTemporaryData!=NULL) { //We have interface positioning data in the db =) ls_interface_data *temp_interface_data=(ls_interface_data*)lir->pTemporaryData; memcpy(temp_interface_data->data, &ServerOpcode(3), 2); memcpy(temp_interface_data->data+2, &lir->loginAttempts, 4); pck.Add(temp_interface_data->data, temp_interface_data->dataSize, false); delete temp_interface_data; lir->pTemporaryData=NULL; } else { //We don't have interface positioning data in the db =( gPacketManager.DirSwitch("Data/Packets/CharacterSelection/"); s.pData=gPacketManager.GetData("accountinfo1", &s.dataSize); memcpy(s.pData, &ServerOpcode(3), 2); memcpy(s.pData+2, &lir->loginAttempts, 4); pck.Add(s.pData, s.dataSize, false); } //This packet always comes before the account permissions packet //Anyway, build the account permissions packet and add it to the stream pck.AddShort(ServerOpcode(4)); pck.AddLong(lir->loginAttempts); pck.AddLong(1); BuildAccountPermissions(&pck, lir); //Terminate the stream pck.AddShort(ServerOpcode(11)); pck.AddLong(lir->loginAttempts); pck.AddLong(0); s.pData=pck.GetString(&s.dataSize); gpLoginServer->SendData(&s);//*/ return 0; } //This function is called to process the results of getting all the characters tied to the account //It saves the character information temporarily and queries for each character's equipped armor //************************************ // Name: CompleteQueries // // Processes the get characters for account query. It saves the character information temporarily and queries for each character's equipped armor. // // Parameters: // pResult - Database query result // pLir - Player's data // // Return: // //************************************ int CompleteQueries(QUERY_RESULT* pResult, LOCAL_DATA* pLir) { //------------------------------------------------------------ //Send the info for the character selection screen //------------------------------------------------------------ //If we had an error in the query if (pResult->pResult==0) { gCoreLog.error("Getting characters for account %u failed!", pLir->accountId); SendError(56, pLir->loginAttempts, pLir->networkId); return -1; } //Retrieve the number of rows returned from the query unsigned long query_num_rows=(unsigned long)mysql_num_rows(pResult->pResult); //If we have at least one character info returned if (query_num_rows>0) { //Create the character info buffer ls_Character_Info *temp_data=new ls_Character_Info[query_num_rows]; //Iterate through all characters and save their information for (unsigned int i=0; ipResult); //Store the character name strcpy(temp_data[i].name, row[0]); //Character location temp_data[i].location=atoi(row[1]); //Sex and height temp_data[i].heightSex=atoi(row[2]); //Hair&Skin color temp_data[i].hairSkinColor=atoi(row[3]); //Profession and hair style temp_data[i].professionHairStyle=atoi(row[4]); //Campaign and face temp_data[i].campaignFace=atoi(row[5]); //second profession temp_data[i].secondProfession=atoi(row[12]); //character type temp_data[i].characterType=atoi(row[13]); //MissionID temp_data[i].missionID=atoi(row[14]); //Level temp_data[i].level=atoi(row[6]); //Store the item armor id's for (int k=0; k<5; k++) { memcpy(temp_data[i].armors[k], row[7+k], 12); } } //Create our structure PRE_ITEM_LOAD_TEMP_DATA *pil=new PRE_ITEM_LOAD_TEMP_DATA; pil->characters=temp_data; pil->numCharacters=query_num_rows; //Assemble the id's into a format readable by the Item Load function ITEM_ID* pItems=new ITEM_ID[query_num_rows*5]; long count=0; for (unsigned int i=0; iqueryId=Item::Load(pItems, count); pLir->pTempData=(void*)pil; pLir->QueryProcess=WriteCharacterInfoStream; } //If we have no characters, we still have to write the remainder of the character select stream else { WriteCharacterInfoStream(0, pLir); } return 0; } //************************************ // Name: ValidateLogon // // Checks the login attempt against the account data. Verifies password, access level, authorization status, and account marks. Executes query to get characters for account. // // Parameters: // pResult - Database query result // pLir - Player's data // // Return: // //************************************ int ValidateLogon(QUERY_RESULT* pResult, LOCAL_DATA* pLir) { //Convert our temporary data to something usable LoginStructure_1 *temp_data=(LoginStructure_1*)pLir->pTempData; //The query failed if (pResult->pResult==NULL) { gCoreLog.error("Failed to validate login for %s.", temp_data->account); SendError(56, pLir->loginAttempts, pLir->networkId); return -1; } //Get the MySQL row MYSQL_ROW row=mysql_fetch_row(pResult->pResult); //---------------------------------------------------------------------- //if no account exists with that email address //---------------------------------------------------------------------- if (mysql_num_rows(pResult->pResult)==0) { if (temp_data->usingPassword) { //send back a reply that no account exists with that email SendError(21, pLir->loginAttempts, pLir->networkId); gCoreLog.warning("Failed Login: No account exists! %s Attempts: %u#", temp_data->account, pLir->loginAttempts); } else { SendError(16, pLir->loginAttempts, pLir->networkId); gCoreLog.warning("Auto-login failed!", pLir->loginAttempts); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } } //----------------------------------------------------------------------- //We have successfully gotten a hash from the database and all other info //----------------------------------------------------------------------- else { unsigned long acc_id=atoi(row[2]); //Make sure this account isn't already logged in //If it is kick the person who is already using the account hash_map::iterator ltr; for (ltr=gLoginInfo.begin(); ltr!=gLoginInfo.end(); ltr++) { if (BIT_TEST(ltr->second.bitfield, LD_AUTHENTICATED)) { if (ltr->second.networkId!=pLir->networkId && ltr->second.accountId==acc_id) { RevokeAuthentication(ltr->second.networkId); gpLoginServer->Kick(ltr->second.networkId); break; } } } //Make sure the network ID is the same so we don't ban good people by accident hash_map::iterator itr=gBruteForceTracker.find(acc_id); if (itr!=gBruteForceTracker.end()) { if (itr->second.networkId!=pLir->networkId) { itr->second.networkId=pLir->networkId; itr->second.tries=0; } if (itr->second.tries>=(unsigned int)gServerConfig.bfWarningThreshold) { itr->second.tries++; SendError(32, pLir->loginAttempts, pLir->networkId); return 0; } } //If passOK == true we are validated bool password_ok=true; //check the password hash against the stored password hash unsigned char stored_hash[33]; //Prevent checking a NULL password if (row[0]!=NULL && row[0][0]!=NULL) { //Convert the stored hash to bytes from ASCII Util::ToBytes(row[0], (char*)stored_hash, 32); //If the server requires a password and the password does not match if (gServerConfig.requireValidPassword && temp_data->usingPassword && memcmp(stored_hash, temp_data->passHash, 32)!=0) { //send back a reply that the entered password is wrong SendError(11, pLir->loginAttempts, pLir->networkId); SOCKETINFO socket_info=gpLoginServer->GetClientById(pLir->networkId); gCoreLog.warning("Failed Login: Incorrect Password! IP: %d.%d.%d.%d Account: %s Attempts: %u", socket_info.ip[0], socket_info.ip[1], socket_info.ip[2], socket_info.ip[3], temp_data->account, pLir->loginAttempts); password_ok=false; gBruteForceTracker[acc_id].tries++; gBruteForceTracker[acc_id].networkId=pLir->networkId; memcpy(gBruteForceTracker[acc_id].ip, gpLoginServer->GetClientById(pLir->networkId).ip, 4); } } //If we are not using a password for this login, make sure the player is using the same computer if (!temp_data->usingPassword) { unsigned char comp_info_hash[32]; memcpy(comp_info_hash, row[4], 32); if (memcmp(pLir->compHash, comp_info_hash, 32)!=0) { //send back a reply that the entered password is wrong SendError(56, pLir->loginAttempts, pLir->networkId); SOCKETINFO socket_info=gpLoginServer->GetClientById(pLir->networkId); gCoreLog.warning("Failed AUTO Login: Incorrect cHash! IP: %d.%d.%d.%d Account: %s Hack suspected, 24 hour ban.", socket_info.ip[0], socket_info.ip[1], socket_info.ip[2], socket_info.ip[3], temp_data->account, pLir->loginAttempts); gpLoginServer->IssueBan(pLir->networkId, (60*60)*24, "AUTO: Incorrect cHash. Hack suspected"); password_ok=false; gBruteForceTracker[acc_id].tries++; gBruteForceTracker[acc_id].networkId=pLir->networkId; memcpy(gBruteForceTracker[acc_id].ip, gpLoginServer->GetClientById(pLir->networkId).ip, 4); } } //------------------------------------------------------------------------ //Password hashes match. The user entered an account name with the proper //password for the account or auto login succeeded. //------------------------------------------------------------------------ if (password_ok) { /* AccessLevel<=0: The account is banned AccessLevel<=25: The account is suspended AccessLevel<=50: The account is normal AccessLevel<=75: The account can access the admin console but can only use status commands AccessLevel<=100: The account has full access to the admin console */ //get the access level for the account from the database pLir->accessLevel=atoi(row[1]); //Check to see if the suspension has expired if (pLir->accessLevel<=25 && pLir->accessLevel>0) { time_t account_mark_time=0; int duration=0; if (temp_data->usingPassword) { account_mark_time=atoi(row[4]); duration=atoi(row[5]); } else { account_mark_time=atoi(row[6]); duration=atoi(row[7]); } if (difftime(time(NULL), account_mark_time)>duration) { pLir->accessLevel=50; char query[100]; sprintf(query, "UPDATE accounts SET AccessLevel=50 WHERE AccountID=%u LIMIT 1", acc_id); gDatabase.Query(query, (long)strlen(query)); } } //------------------------------------------------ //check the access level for account bans //if the account is banned //------------------------------------------------ if (pLir->accessLevel==0) { //send back a reply that account is banned SendError(45, pLir->loginAttempts, pLir->networkId); SOCKETINFO si=gpLoginServer->GetClientById(pLir->networkId); gCoreLog.warning("Failed Login: Account Banned! IP: %d.%d.%d.%d Account: %s Attempts: %d", si.ip[0], si.ip[1], si.ip[2], si.ip[3], temp_data->account, pLir->loginAttempts); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } //------------------------------------------------ //check to see if the account is suspended //if the account is suspended //------------------------------------------------ else if (pLir->accessLevel<=25) { //send back a reply that account is suspended SendError(45, pLir->loginAttempts, pLir->networkId); SOCKETINFO socket_info=gpLoginServer->GetClientById(pLir->networkId); gCoreLog.warning("Failed Login: Account Suspended! IP: %d.%d.%d.%d Account: %s Attempts: %d", socket_info.ip[0], socket_info.ip[1], socket_info.ip[2], socket_info.ip[3], temp_data->account, pLir->loginAttempts); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } //Check for admin lock of the server. Prevent non-admins from logging in. else if (pLir->accessLevel<=50 && gServerStatus.adminLock && temp_data->usingPassword) { SendError(17, pLir->loginAttempts, pLir->networkId); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } //---------------------------------------------------- //check if the account is normal or above //if the account is in normal or elevated standing //---------------------------------------------------- else if (pLir->accessLevel>=50) { //------------------------------------------------------- //Get the client's IP address and check if it is already //in use. If it is then send an error. //------------------------------------------------------- SOCKETINFO socket_info=gpLoginServer->GetClientById((short)pLir->networkId); //------------------------------------------------- //Make sure the game servers are not down or full //------------------------------------------------- GAMESERVER_DATA* p_opt_game_serv=GetOptimalGameSrv(); //If compiled with allow with no game server then ignore game server checking if (gServerConfig.ignoreNoGameServer) { GAMESERVER_DATA gs_data; p_opt_game_serv=&gs_data; } //------------------------------------------------- //All game servers are currently full //------------------------------------------------- if (GameServersFull()) { SendError(18, pLir->loginAttempts, pLir->networkId); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } //No game servers are available so prevent login else if (p_opt_game_serv==NULL) { SendError(167, pLir->loginAttempts, pLir->networkId); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } else { //-------------------------------------------------------------- //Get the account id from the database and add an active client //to the active clients list. //-------------------------------------------------------------- pLir->accountId=atoi(row[2]); if (pLir->accountId==0) { gCoreLog.error("Account ID Failed!"); SendError(56, pLir->loginAttempts, pLir->networkId); NetMessage s(NULL, KICK_CLIENT, pLir->networkId); gpLoginServer->SendData(&s); } BIT_SET(pLir->bitfield, LD_AUTHENTICATED); char random_long[4]; for (int n=0; n<4; n++){random_long[n]=rand()%256;} memcpy(&pLir->transferId1, random_long, 4); for (int n=0; n<4; n++){random_long[n]=rand()%256;} memcpy(&pLir->transferId2, random_long, 4); //----------------------------------------------- //Update the computer info hash for this account //----------------------------------------------- if (temp_data->usingPassword) { char comp_hash_hex[100]; Util::BinToHex(pLir->compHash, 32, comp_hash_hex); char comp_query[150]; sprintf(comp_query, "UPDATE accounts SET CompHash=%s WHERE AccountID=\"%u\"@NOSTATUS", comp_hash_hex, pLir->accountId); pLir->queryId=gDatabase.Query(comp_query, (long)strlen(comp_query)); } //----------------------------------------------- //Set stuff //----------------------------------------------- if (!temp_data->usingPassword) { if (row[5]!=NULL) { strcpy(pLir->name, row[5]); } } unsigned long num_players=0; hash_map::iterator itr; for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED)) { num_players++; } } if (num_players>(unsigned long)gServerStatus.peakPlayers) { gServerStatus.peakPlayers=num_players; } //Check the authorization stuff. if (row[3]!=0 && row[3][0]!=0) { bool authorization_fail=false; //Get the authData unsigned char auth_data[70]; memcpy(auth_data, row[3], 70); //Decrypt the authData for (int i=0; i<70; i++) { auth_data[i]=auth_data[i]^pLir->compHash[i%32]; } //Check the time stamp time_t current_time=time(NULL); time_t stamp_time; memcpy(&stamp_time, auth_data, 4); if (difftime(current_time, stamp_time)<(60*60)*10) { //Decrypt the campaigns and eotn values unsigned char campaigns=auth_data[4]^2; unsigned char owns_eotn=auth_data[5]^2; unsigned char owns[2]; owns[0]=campaigns; owns[1]=owns_eotn; //Extract the hashes CompiledPacket comp_hash(true); CompiledPacket secret_hash(true); for (int i=0; i<64; i+=2) { comp_hash.AddByte(auth_data[i+6]^owns[1-((i/2)%2)]); secret_hash.AddByte(auth_data[i+6+1]^owns[0+((i/2)%2)]); } int ds=0; unsigned char *pC_hash=comp_hash.GetString(&ds); unsigned char *pS_hash=secret_hash.GetString(&ds); //Check the computer hash against this computer's hash if (memcmp(pC_hash, pLir->compHash, 32)==0) { int key=5; //Generate the secret hash CompiledPacket pck_secret_hash(true); pck_secret_hash.AddByte(0x14^key); pck_secret_hash.Fill(0, 13); pck_secret_hash.AddByte(owns[0]); pck_secret_hash.Fill(0, 9); pck_secret_hash.AddByte(owns[1]); pck_secret_hash.Add(pLir->compHash, 32, false); unsigned char shHash[32]; ds=0; unsigned char *secret_hash_data=pck_secret_hash.GetString(&ds); Util::Hash(secret_hash_data, shHash, ds); //Check the secret hashes to make sure they match if (memcmp(shHash, pS_hash, 32)==0) { pLir->ownsEotn=owns[1]; pLir->ownedCampaigns=owns[0]; } else { authorization_fail=true; } } else { authorization_fail=true; } } else { authorization_fail=true; } if (authorization_fail) { pLir->ownedCampaigns=0; pLir->ownsEotn=0; } } else { pLir->ownedCampaigns=0; pLir->ownsEotn=0; } //If we are using a password, i.e. no auto login if (temp_data->usingPassword) { pLir->pTemporaryData=NULL; if (atoi(row[6])>0) { ls_interface_data *temp_interface_data=new ls_interface_data; pLir->pTemporaryData=temp_interface_data; temp_interface_data->dataSize=atoi(row[6]); memcpy(temp_interface_data->data, row[7], temp_interface_data->dataSize); } //Generate the query to grab all the characters char query[600]; sprintf(query, "SELECT Name, Location, HeightSex, HairSkinColor, ProfessionHairStyle, CampaignFace, Level, HeadArmor, ChestArmor, ArmsArmor, LegArmor, FeetArmor, SecondProfession, CharacterType, MissionID FROM characters WHERE OwnerAccountID=\"%u\"", pLir->accountId); pLir->queryId=gDatabase.Query(query, (long)strlen(query)); pLir->QueryProcess=CompleteQueries; } } } } } return 0; } //************************************ // Name: HandleOpcode_ACCOUNT_LOGIN // // Handles the account login packet. Generates a query to get the needed account information from the database. // // Parameters: // pData - Network data // pLir - Player's data // // Return: // //************************************ int HandleOpcode_ACCOUNT_LOGIN(NetMessage* pData, LOCAL_DATA* pLir) { assert(pData!=NULL); LoginStructure_1 *temp_data=new LoginStructure_1; //------------------------------------------------------------------------------ //Variables that store information from the login packet //------------------------------------------------------------------------------ unsigned char password[23]; memset(password, 0, 23); memset(temp_data->passHash, 0, 33);//hash is only 32 bytes in length, 33 for the terminating 0 memset(temp_data->account, 0, 129); //---------------------------------------------------------------------------------- //if the first login attempt then do this //For some reason the packets between the first login and the following differ //---------------------------------------------------------------------------------- if (pData->dataSize>=32) { //Grab the loginAttempts, password, and account name from the packet. pLir->loginAttempts=Read_uLong(pData->pData+2); memcpy(password, pData->pData+8, (int)pData->pData[6]); Util::StripUnicode(password); //remove unicode from the password HashPassword(password, temp_data->passHash); //hash the password memcpy(temp_data->account, pData->pData+32, Read_uShort(pData->pData+30)*2); Util::StripUnicode(temp_data->account); //strip unicode from the account name } else { gpLoginServer->Kick(pLir->networkId); } //--------------------------------------------------------------------------------- //clear our password data from memory(for security reasons) //Then make a query to the database to get the account information required for validating login //--------------------------------------------------------------------------------- memset(password, 0, 23); //We are using a password, not auto-login temp_data->usingPassword=true; //Create the new query char query[500]; sprintf(query, "SELECT Password, AccessLevel, AccountID, Authorization, TimeAccountMarked, DurationOfMark, InterfaceDataSize, InterfaceData FROM accounts WHERE Email=\"%s\" LIMIT 1", temp_data->account); pLir->queryId=gDatabase.Query(query, (long)strlen(query)); pLir->pTempData=(void*)temp_data; pLir->QueryProcess=ValidateLogon; //This instructs the ChopPacket function to completely ignore this packet, if it was 0 it would make a copy return pData->dataSize; } void core_sha256 (unsigned long* m, int l); unsigned long* str2binb(char *str); //number of bits in an ascii value #define CHRSZ 8 //************************************ // Name: HashPassword // // Makes a SHA256 hash of the password data. // // Parameters: // pSourceData - Source buffer // pDestBuffer - Destination buffer // // Return: // true //************************************ bool HashPassword(unsigned char* pSourceData, unsigned char* pDestBuffer) { sha256_context ctx; assert(pSourceData!=NULL); assert(pDestBuffer!=NULL); sha256_starts( &ctx ); sha256_update( &ctx, pSourceData, (unsigned long)strlen( (char*)pSourceData ) ); sha256_finish( &ctx, pDestBuffer ); return true; } //************************************ // Name: SendError // // Sends a GW error message to the client. Only works on the login server. // // Parameters: // errorCode - GW error code number to send // numLogins - Number of login attempts // NetworkID - Unique network Id for the player // // Return: // //************************************ void SendError(int errorCode, int numLogins, short NetworkID) { unsigned char data[10]={0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00}; memcpy(data, &ServerOpcode(5), 2); memcpy(data+2, &numLogins, 4); memcpy(data+6, &errorCode, 4); NetMessage s; s.pData=data; s.dataSize=10; s.networkId=NetworkID; gpLoginServer->SendData(&s); }