Browse Source

Login Server Updates

Fixes #55 - check on if an account exists or not before attempting an account creation (we still rely on the DB to do the password comparison as its own query)
Image 4 years ago
parent
commit
5cd1bacc28

+ 14 - 1
EQ2/source/LoginServer/LoginDatabase.cpp

@@ -463,7 +463,7 @@ LoginAccount* LoginDatabase::LoadAccount(const char* name, const char* password,
 		}
 		else if(mysql_num_rows(result) > 0)
 			LogWrite(LOGIN__ERROR, 0, "Login", "Error in LoginAccount: more than one account returned for '%s'", name);
-		else if (attemptAccountCreation)
+		else if (attemptAccountCreation && !database.GetAccountIDByName(name))
 		{
 			Query newquery;
 			newquery.RunQuery2(Q_INSERT, "insert into account set name='%s',passwd=sha2('%s',512)", query.escaped_name, query.escaped_pass);
@@ -475,6 +475,19 @@ LoginAccount* LoginDatabase::LoadAccount(const char* name, const char* password,
 	return acct;
 }
 
+int32 LoginDatabase::GetAccountIDByName(const char* name) {
+	int32 id = 0;
+	Query query;
+	MYSQL_ROW row;
+	query.escaped_name = getEscapeString(name);
+	MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT id from account where name='%s'", query.escaped_name);
+	if (result && mysql_num_rows(result) == 1) {
+		row = mysql_fetch_row(result);
+		id = atoi(row[0]);
+	}
+	return id;
+}
+
 int32 LoginDatabase::CheckServerAccount(char* name, char* passwd){
 	int32 id = 0;
 	Query query;

+ 1 - 0
EQ2/source/LoginServer/LoginDatabase.h

@@ -36,6 +36,7 @@ public:
 	void UpdateWorldIPAddress(int32 world_id, int32 address);
 	void SaveBugReport(int32 world_id, char* category, char* subcategory, char* causes_crash, char* reproducible, char* summary, char* description, char* version, char* player, int32 account_id, char* spawn_name, int32 spawn_id, int32 zone_id);
 	LoginAccount* LoadAccount(const char* name, const char* password, bool attemptAccountCreation=true);
+	int32 GetAccountIDByName(const char* name);
 	int32 CheckServerAccount(char* name, char* passwd);
 	void  GetServerAccounts(vector<LWorld*>* server_list);
 	char* GetServerAccountName(int32 id);

+ 1 - 0
EQ2/source/LoginServer/client.cpp

@@ -164,6 +164,7 @@ bool Client::Process() {
 				PacketStruct* packet = configReader.getStruct("LS_LoginRequest", 1);
 				if(packet->LoadPacketData(app->pBuffer,app->size)){
 					version = packet->getType_int32_ByName("version");
+					//[7:19 PM] Kirmmin: Well, I very quickly learned that unknown3 in LS_LoginRequest packet is the same value as cl_eqversion in the eq2_defaults.ini file.
 
 					LogWrite(LOGIN__DEBUG, 0, "Login", "Client Version Provided: %i", version);