Browse Source

Login Server now supports auto account creation upon a new acct

This includes creation of a new parameter in the LoginServer.ini, AccountCreation in the LoginConfig block can be 0 to disable, by default it is 1 (or if the field is not defined, its considered true)

Fixes #51
Image 4 years ago
parent
commit
d87a363e4b

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

@@ -445,7 +445,7 @@ bool LoginDatabase::UpdateCharacterGender(int32 account_id, int32 character_id,
 	return true;
 }
 
-LoginAccount* LoginDatabase::LoadAccount(const char* name, const char* password){
+LoginAccount* LoginDatabase::LoadAccount(const char* name, const char* password, bool attemptAccountCreation){
 	LoginAccount* acct = NULL;
 	Query query;
 	query.escaped_name = getEscapeString(name);
@@ -463,6 +463,14 @@ 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)
+		{
+			Query newquery;
+			newquery.RunQuery2(Q_INSERT, "insert into account set name='%s',passwd=sha2('%s',512)", query.escaped_name, query.escaped_pass);
+			// re-run the query for select only not account creation
+			return LoadAccount(name, password, false);
+		}
+
 	}
 	return acct;
 }

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

@@ -35,7 +35,7 @@ public:
 	void UpdateAccountIPAddress(int32 account_id, int32 address);
 	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);
+	LoginAccount* LoadAccount(const char* name, const char* password, bool attemptAccountCreation=true);
 	int32 CheckServerAccount(char* name, char* passwd);
 	void  GetServerAccounts(vector<LWorld*>* server_list);
 	char* GetServerAccountName(int32 id);

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

@@ -183,7 +183,7 @@ bool Client::Process() {
 						getConnection()->SetClientVersion(GetOrigVersion());
 						EQ2_16BitString username = packet->getType_EQ2_16BitString_ByName("username");
 						EQ2_16BitString password = packet->getType_EQ2_16BitString_ByName("password");
-						LoginAccount* acct = database.LoadAccount(username.data.c_str(),password.data.c_str());
+						LoginAccount* acct = database.LoadAccount(username.data.c_str(),password.data.c_str(), net.IsAllowingAccountCreation());
 						if(acct){
 							Client* otherclient = client_list.FindByLSID(acct->getLoginAccountID());
 							if(otherclient)

+ 5 - 0
EQ2/source/LoginServer/net.cpp

@@ -230,6 +230,11 @@ bool NetConnection::ReadLoginConfig() {
 				eqsf.listen_ip_address = new char[sizeof(buf) + 1];
 				strcpy(eqsf.listen_ip_address, buf);
 			}
+			if (!strncasecmp(type, "accountcreation", 15)) {
+				if (Seperator::IsNumber(buf)) {
+					allowAccountCreation = atoi(buf);
+				}
+			}
 		}
 	}
 

+ 3 - 0
EQ2/source/LoginServer/net.h

@@ -38,6 +38,7 @@ public:
 		Uplink_WrongVersion = false;
 		numclients = 0;
 		numservers = 0;
+		allowAccountCreation = true;
 	}
 	void UpdateWindowTitle(char* iNewTitle = 0);
 	bool Init();
@@ -57,6 +58,7 @@ public:
 	char*	GetUplinkAccount()	{ return uplinkaccount; }
 	char*	GetUplinkPassword()	{ return uplinkpassword; }
 
+	bool	IsAllowingAccountCreation() { return allowAccountCreation; }
 
 protected:
 	friend class LWorld;
@@ -69,4 +71,5 @@ private:
 	char	uplinkaccount[300];
 	char	uplinkpassword[300];
 	eServerMode	LoginMode;
+	bool	allowAccountCreation;
 };

+ 1 - 0
server/LoginServer.ini

@@ -35,3 +35,4 @@ updateserverport=9104
 [LoginConfig]
 ServerMode=StandAlone
 ServerPort=9100
+AccountCreation=1