#include "LoginServ.h" #include "../../src/Utility.h" void SendError(int errorCode, int verifCode, NLsocket sockId); int VerifyAccountSuccess(QUERY_RESULT* pResult, ClientData* pMyClient); int ValidateEmail(QUERY_RESULT* pResult, ClientData* pMyClient); int HandleOpcodeCREATE_ACCOUNT(Packet* pck, GwClient* pClient) { GetClientData(); if(pMyClient->keyValidated) { //Extract the login attempts pMyClient->verifCode=pck->ReadLong(); //Extract the email address wchar_t email[65]; memset(email, 0, 65*2); ushort emailLength=pck->ReadShort(); pck->Read(email, emailLength*2); pMyClient->pEmailAddr=new wchar_t[65]; memcpy(pMyClient->pEmailAddr, email, 65*2); //Check if the email is in use char emailHex[65*5]; Util::BinToHex((unsigned char*)email, 65*2, emailHex); char query[320]; sprintf(query, "SELECT email FROM accounts WHERE email=%s LIMIT 1", emailHex); pMyClient->queryId=gLoginServer.mDatabase.Query(query, (long)strlen(query)); pMyClient->QueryProcess=ValidateEmail; } return pClient->inBuffer.size(); } int ValidateEmail(QUERY_RESULT* pResult, ClientData* pMyClient) { if(pResult->pResult==NULL) { logFile.Write("Failed to validate email!\n"); SendError(46, pMyClient->verifCode, pMyClient->socketId); return -1; } //The email address is already in use if(mysql_num_rows(pResult->pResult)>0) { SendError(105, pMyClient->verifCode, pMyClient->socketId); } //The email address is not in use else { //Set the key to in-use char query[500]; sprintf(query, "UPDATE access_keys SET KeyStatus=%d WHERE AccessKey=\"%s\"", 1, pMyClient->pAccessKey); gLoginServer.mDatabase.Query(query, (long)strlen(query)); //Insert the account char emailHex[65*5]; Util::BinToHex((unsigned char*)pMyClient->pEmailAddr, 65*2, emailHex); sprintf(query, "INSERT INTO accounts(Email) VALUES(%s)", emailHex); pMyClient->queryId=gLoginServer.mDatabase.Query(query, (long)strlen(query), true); pMyClient->QueryProcess=VerifyAccountSuccess; } return 0; } int VerifyAccountSuccess(QUERY_RESULT* pResult, ClientData* pMyClient) { if(pResult->affectedRows==0) { logFile.Write("Could not verify account!\n"); SendError(46, pMyClient->verifCode, pMyClient->socketId); return -1; } //The account was not created if(pResult->affectedRows==0) { SendError(56, pMyClient->verifCode, pMyClient->socketId); } //The account was created else { GwClient* pClient=gLoginServer.mpLoginServer->AccessGwClient(pMyClient->socketId); pClient->WriteShort(ServerOpcode("STREAM_TERMINATOR")); pClient->WriteLong(pMyClient->verifCode); pClient->WriteLong(0); } //Clean up delete [] pMyClient->pEmailAddr; pMyClient->pEmailAddr=NULL; delete [] pMyClient->pAccessKey; pMyClient->pAccessKey=NULL; pMyClient->keyValidated=false; return 0; }