Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Add config flag to dis/allow new accounts
Browse files Browse the repository at this point in the history
new flag "account_creation" in login config file
(true/false) which permits new accounts to be
created. Defaults to true.
  • Loading branch information
Kreidos committed Apr 14, 2020
1 parent e2b49fa commit 7b52c1f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions conf/login_darkstar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ msg_server_ip: 127.0.0.1

#Logging of user IP address to database (true/false)
log_user_ip: false

#New accounts may be created? (true/false)
account_creation: true

10 changes: 10 additions & 0 deletions src/login/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ int32 do_init(int32 argc, char** argv)

messageThread = std::thread(message_server_init);
ShowStatus("The login-server is " CL_GREEN"ready" CL_RESET" to work...\n");

if(!login_config.account_creation)
{
ShowStatus("New account creation is " CL_RED"disabled" CL_RESET" in login_config.\n");
}

bool attached = isatty(0);

Expand Down Expand Up @@ -440,6 +445,10 @@ void login_config_read(const char *key, const char *value)
{
login_config.log_user_ip = config_switch(value);
}
else if (strcmp(key, "account_creation") == 0)
{
login_config.account_creation = config_switch(value);
}
else
{
ShowWarning("Unknown setting '%s' with value '%s' in login file\n", key, value);
Expand Down Expand Up @@ -490,6 +499,7 @@ void login_config_default()
login_config.msg_server_ip = "127.0.0.1";

login_config.log_user_ip = "false";
login_config.account_creation = "true";
}

void version_info_default()
Expand Down
1 change: 1 addition & 0 deletions src/login/login.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct login_config_t
uint16 msg_server_port; // chat server port
std::string msg_server_ip; // chat server IP
bool log_user_ip; // log user ip -> default false
bool account_creation; // allow new accounts to be created -> default true
};

struct version_info_t
Expand Down
13 changes: 12 additions & 1 deletion src/login/login_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,20 @@ int32 login_parse(int32 fd)
}
break;
case LOGIN_CREATE:
//looking for same login
Sql_EscapeString(SqlHandle, escaped_name, name.c_str());
Sql_EscapeString(SqlHandle, escaped_pass, password.c_str());

//check if account creation is disabled
if (!login_config.account_creation)
{
ShowWarning(CL_WHITE"login_parse" CL_RESET": New account attempt <" CL_WHITE"%s" CL_RESET"> but is disabled in config.\n", escaped_name);
session[fd]->wdata.resize(1);
ref<uint8>(session[fd]->wdata.data(), 0) = LOGIN_ERROR_CREATE;
do_close_login(sd, fd);
return 0;
}

//looking for same login
if (Sql_Query(SqlHandle, "SELECT accounts.id FROM accounts WHERE accounts.login = '%s'", escaped_name) == SQL_ERROR)
{
session[fd]->wdata.resize(1);
Expand Down

0 comments on commit 7b52c1f

Please sign in to comment.