diff options
author | Haru <haru@dotalux.com> | 2017-10-30 02:24:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-30 02:24:20 +0100 |
commit | 703a57698fc04d4cba818041b67ffbb028f56e2b (patch) | |
tree | 01941788ac53f988b2481d59c7ca9d77790a2603 /src/login/login.c | |
parent | 7f74da4a69482ce09409744612b69e071ebc0ced (diff) | |
parent | ebff7968504ee090961390820ce74458d7b0f956 (diff) | |
download | hercules-703a57698fc04d4cba818041b67ffbb028f56e2b.tar.gz hercules-703a57698fc04d4cba818041b67ffbb028f56e2b.tar.bz2 hercules-703a57698fc04d4cba818041b67ffbb028f56e2b.tar.xz hercules-703a57698fc04d4cba818041b67ffbb028f56e2b.zip |
Merge pull request #1891 from 4144/listcolor
Add ability to show char servers list with colors based on players count.
Diffstat (limited to 'src/login/login.c')
-rw-r--r-- | src/login/login.c | 104 |
1 files changed, 88 insertions, 16 deletions
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; } |