summaryrefslogtreecommitdiff
path: root/src/login/login.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/login/login.c')
-rw-r--r--src/login/login.c140
1 files changed, 124 insertions, 16 deletions
diff --git a/src/login/login.c b/src/login/login.c
index ae584206f..a78276051 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1360,6 +1360,41 @@ bool login_client_login(int fd, struct login_session_data *sd)
return false;
}
+bool login_client_login_otp(int fd, struct login_session_data *sd) __attribute__((nonnull (2)));
+bool login_client_login_otp(int fd, struct login_session_data *sd)
+{
+ // send ok response with fake token
+#ifdef PACKETVER_ZERO
+#if PACKETVER >= 20171127
+ WFIFOHEAD(fd, 33);
+ WFIFOW(fd, 0) = 0x0ae3;
+ WFIFOW(fd, 2) = 33; // len
+ WFIFOL(fd, 4) = 0; // normal login
+ safestrncpy(WFIFOP(fd, 8), "S1000", 6);
+ safestrncpy(WFIFOP(fd, 28), "token", 6);
+ WFIFOSET(fd, 33);
+#elif PACKETVER >= 20171123
+ WFIFOHEAD(fd, 19);
+ WFIFOW(fd, 0) = 0x0ae3;
+ WFIFOW(fd, 2) = 19; // len
+ WFIFOL(fd, 4) = 0; // normal login
+ safestrncpy(WFIFOP(fd, 8), "S1000", 6);
+ safestrncpy(WFIFOP(fd, 14), "token", 6);
+ WFIFOSET(fd, 19);
+#else
+ WFIFOHEAD(fd, 13);
+ WFIFOW(fd, 0) = 0x0ad1;
+ WFIFOW(fd, 2) = 13; // len
+ WFIFOL(fd, 4) = 0; // normal login
+ safestrncpy(WFIFOP(fd, 8), "token", 6);
+ WFIFOSET(fd, 13);
+#endif
+ return true;
+#else // PACKETVER_ZERO
+ return false;
+#endif // PACKETVER_ZERO
+}
+
void login_char_server_connection_status(int fd, struct login_session_data* sd, uint8 status) __attribute__((nonnull (2)));
void login_char_server_connection_status(int fd, struct login_session_data* sd, uint8 status)
{
@@ -1604,7 +1639,7 @@ bool login_config_read_account(const char *filename, struct config_t *config, bo
/**
* Frees login->config->client_hash_nodes
**/
-void clear_client_hash_nodes(void)
+void login_clear_client_hash_nodes(void)
{
struct client_hash_node *node = login->config->client_hash_nodes;
@@ -1618,7 +1653,7 @@ void clear_client_hash_nodes(void)
}
/**
- * Reads information from login_configuration.permission.hash.md5_hashes.
+ * Reads information from login_configuration.permission.hash.md5_hashes (unused function)
*
* @param setting The setting to read from.
*/
@@ -1627,7 +1662,7 @@ void login_config_set_md5hash(struct config_setting_t *setting)
int i;
int count = libconfig->setting_length(setting);
- clear_client_hash_nodes();
+ login->clear_client_hash_nodes();
// There's no need to parse if it's disabled or if there's no list
if (count <= 0 || !login->config->client_hash_check)
@@ -1702,7 +1737,7 @@ bool login_config_read_permission_hash(const char *filename, struct config_t *co
libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->client_hash_check);
if ((setting = libconfig->lookup(config, "login_configuration/permission/hash/MD5_hashes")) != NULL)
- login_config_set_md5hash(setting);
+ login->config_set_md5hash(setting);
return true;
}
@@ -1710,7 +1745,7 @@ bool login_config_read_permission_hash(const char *filename, struct config_t *co
/**
* Clears login->config->dnsbl_servers, freeing any allocated memory.
*/
-void clear_dnsbl_servers(void)
+void login_clear_dnsbl_servers(void)
{
while (VECTOR_LENGTH(login->config->dnsbl_servers) > 0) {
aFree(&VECTOR_POP(login->config->dnsbl_servers));
@@ -1728,7 +1763,7 @@ void login_config_set_dnsbl_servers(struct config_setting_t *setting)
int i;
int count = libconfig->setting_length(setting);
- clear_dnsbl_servers();
+ login->clear_dnsbl_servers();
// There's no need to parse if it's disabled
if (count <= 0 || !login->config->use_dnsbl)
@@ -1772,7 +1807,7 @@ bool login_config_read_permission_blacklist(const char *filename, struct config_
libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->use_dnsbl);
if ((setting = libconfig->lookup(config, "login_configuration/permission/DNS_blacklist/dnsbl_servers")) != NULL)
- login_config_set_dnsbl_servers(setting);
+ login->config_set_dnsbl_servers(setting);
return true;
}
@@ -1806,15 +1841,47 @@ bool login_config_read_permission(const char *filename, struct config_t *config,
libconfig->setting_lookup_bool_real(setting, "check_client_version", &login->config->check_client_version);
libconfig->setting_lookup_uint32(setting, "client_version_to_connect", &login->config->client_version_to_connect);
- if (!login_config_read_permission_hash(filename, config, imported))
+ if (!login->config_read_permission_hash(filename, config, imported))
retval = false;
- if (!login_config_read_permission_blacklist(filename, config, imported))
+ if (!login->config_read_permission_blacklist(filename, config, imported))
retval = false;
return retval;
}
/**
+ * Reads 'login_configuration.users_count' and initializes required variables.
+ *
+ * @param filename Path to configuration file (used in error and warning messages).
+ * @param config The current config being parsed.
+ * @param imported Whether the current config is imported from another file.
+ *
+ * @retval false in case of error.
+ */
+bool login_config_read_users(const char *filename, struct config_t *config, bool imported)
+{
+ struct config_setting_t *setting = NULL;
+ bool retval = true;
+
+ nullpo_retr(false, filename);
+ nullpo_retr(false, config);
+
+ if ((setting = libconfig->lookup(config, "login_configuration/users_count")) == NULL) {
+ if (imported)
+ return true;
+ ShowError("login_config_read: login_configuration/users_count was not found in %s!\n", filename);
+ return false;
+ }
+
+ libconfig->setting_lookup_bool_real(setting, "send_user_count_description", &login->config->send_user_count_description);
+ libconfig->setting_lookup_uint32(setting, "low", &login->config->users_low);
+ libconfig->setting_lookup_uint32(setting, "medium", &login->config->users_medium);
+ libconfig->setting_lookup_uint32(setting, "high", &login->config->users_high);
+
+ return retval;
+}
+
+/**
* Reads the 'login-config' configuration file and initializes required variables.
*
* @param filename Path to configuration file.
@@ -1833,15 +1900,17 @@ bool login_config_read(const char *filename, bool imported)
if (!libconfig->load_file(&config, filename))
return false; // Error message is already shown by libconfig->load_file
- if (!login_config_read_inter(filename, &config, imported))
+ if (!login->config_read_inter(filename, &config, imported))
+ retval = false;
+ if (!login->config_read_console(filename, &config, imported))
retval = false;
- if (!login_config_read_console(filename, &config, imported))
+ if (!login->config_read_log(filename, &config, imported))
retval = false;
- if (!login_config_read_log(filename, &config, imported))
+ if (!login->config_read_account(filename, &config, imported))
retval = false;
- if (!login_config_read_account(filename, &config, imported))
+ if (!login->config_read_permission(filename, &config, imported))
retval = false;
- if (!login_config_read_permission(filename, &config, imported))
+ if (!login->config_read_users(filename, &config, imported))
retval = false;
if (!loginlog_config_read("conf/common/inter-server.conf", imported)) // Only inter-server
@@ -1866,6 +1935,30 @@ bool login_config_read(const char *filename, bool imported)
return retval;
}
+/**
+ * Convert users count to colors.
+ *
+ * @param users Actual users count.
+ *
+ * @retval users count or color id.
+ **/
+uint16 login_convert_users_to_colors(uint16 users)
+{
+#if PACKETVER >= 20170726
+ if (!login->config->send_user_count_description)
+ return 4;
+ if (users <= login->config->users_low)
+ return 0;
+ else if (users <= login->config->users_medium)
+ return 1;
+ else if (users <= login->config->users_high)
+ return 2;
+ return 3;
+#else
+ return users;
+#endif
+}
+
//--------------------------------------
// Function called at exit of the server
//--------------------------------------
@@ -1877,8 +1970,8 @@ int do_final(void)
HPM->event(HPET_FINAL);
- clear_client_hash_nodes();
- clear_dnsbl_servers();
+ login->clear_client_hash_nodes();
+ login->clear_dnsbl_servers();
login_log(0, "login server", 100, "login server shutdown");
@@ -2160,6 +2253,7 @@ void login_defaults(void) {
login->parse_fromchar = login_parse_fromchar;
login->client_login = login_client_login;
+ login->client_login_otp = login_client_login_otp;
login->parse_request_connection = login_parse_request_connection;
login->auth_ok = login_auth_ok;
login->auth_failed = login_auth_failed;
@@ -2168,6 +2262,20 @@ void login_defaults(void) {
login->config_set_defaults = login_config_set_defaults;
login->config_read = login_config_read;
+ login->config_read_inter = login_config_read_inter;
+ login->config_read_console = login_config_read_console;
+ login->config_read_log = login_config_read_log;
+ login->config_read_account = login_config_read_account;
+ login->config_read_permission = login_config_read_permission;
+ login->config_read_permission_hash = login_config_read_permission_hash;
+ login->config_read_permission_blacklist = login_config_read_permission_blacklist;
+ login->config_read_users = login_config_read_users;
+ login->config_set_dnsbl_servers = login_config_set_dnsbl_servers;
+
+ login->clear_dnsbl_servers = login_clear_dnsbl_servers;
+ login->clear_client_hash_nodes = login_clear_client_hash_nodes;
+ login->config_set_md5hash = login_config_set_md5hash;
+ login->convert_users_to_colors = login_convert_users_to_colors;
login->LOGIN_CONF_NAME = NULL;
login->NET_CONF_NAME = NULL;
}