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
This commit is contained in:
Image 2020-03-18 23:48:57 -04:00
parent ec9b1ae7a5
commit d87a363e4b
6 changed files with 20 additions and 3 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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)

View file

@ -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);
}
}
}
}

View file

@ -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;
};

View file

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