summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
Diffstat (limited to 'src/login')
-rw-r--r--src/login/lclif.c2
-rw-r--r--src/login/login.c104
-rw-r--r--src/login/login.h20
3 files changed, 109 insertions, 17 deletions
diff --git a/src/login/lclif.c b/src/login/lclif.c
index f32538610..47b2526c4 100644
--- a/src/login/lclif.c
+++ b/src/login/lclif.c
@@ -284,7 +284,7 @@ bool lclif_send_server_list(struct login_session_data *sd)
packet->server_list[n].ip = htonl((subnet_char_ip) ? subnet_char_ip : server[i].ip);
packet->server_list[n].port = sockt->ntows(htons(server[i].port)); // [!] LE byte order here [!]
safestrncpy(packet->server_list[n].name, server[i].name, 20);
- packet->server_list[n].usercount = server[i].users;
+ packet->server_list[n].usercount = login->convert_users_to_colors(server[i].users);
if (server[i].type == CST_PAYING && sd->expiration_time > time(NULL))
packet->server_list[n].property = CST_NORMAL;
diff --git a/src/login/login.c b/src/login/login.c
index ae584206f..3db9558b8 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1604,7 +1604,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 +1618,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 +1627,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 +1702,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 +1710,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 +1728,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 +1772,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 +1806,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 +1865,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))
+ if (!login->config_read_console(filename, &config, imported))
retval = false;
- if (!login_config_read_log(filename, &config, imported))
+ if (!login->config_read_log(filename, &config, imported))
retval = false;
- if (!login_config_read_account(filename, &config, imported))
+ if (!login->config_read_account(filename, &config, imported))
retval = false;
- if (!login_config_read_permission(filename, &config, imported))
+ if (!login->config_read_permission(filename, &config, imported))
+ retval = false;
+ 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 +1900,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 +1935,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");
@@ -2168,6 +2226,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;
}
diff --git a/src/login/login.h b/src/login/login.h
index 5632e6529..d5c9972c0 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -32,6 +32,8 @@
struct mmo_account;
struct AccountDB;
+struct config_t;
+struct config_setting_t;
enum E_LOGINSERVER_ST
{
@@ -119,6 +121,11 @@ struct Login_Config {
bool use_dnsbl; ///< dns blacklist blocking ?
VECTOR_DECL(char *) dnsbl_servers; ///< dnsbl servers
+ bool send_user_count_description;
+ uint32 users_low;
+ uint32 users_medium;
+ uint32 users_high;
+
bool client_hash_check; ///< flags for checking client md5
// TODO: VECTOR candidate
struct client_hash_node *client_hash_nodes; ///< linked list containg md5 hash for each gm group
@@ -209,6 +216,19 @@ struct login_interface {
void (*parse_request_connection) (int fd, struct login_session_data* sd, const char *ip, uint32 ipl);
void (*config_set_defaults) (void);
bool (*config_read) (const char *filename, bool included);
+ bool (*config_read_inter) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_console) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_log) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_account) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_permission) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_permission_hash) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_permission_blacklist) (const char *filename, struct config_t *config, bool imported);
+ bool (*config_read_users) (const char *filename, struct config_t *config, bool imported);
+ void (*clear_dnsbl_servers) (void);
+ void (*config_set_dnsbl_servers) (struct config_setting_t *setting);
+ void (*clear_client_hash_nodes) (void);
+ void (*config_set_md5hash) (struct config_setting_t *setting);
+ uint16 (*convert_users_to_colors) (uint16 users);
char *LOGIN_CONF_NAME;
char *NET_CONF_NAME; ///< Network configuration filename
};