summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-10-29 00:16:03 +0300
committerAndrei Karas <akaras@inbox.ru>2017-10-29 02:10:10 +0300
commitebff7968504ee090961390820ce74458d7b0f956 (patch)
tree9e6268b61e9e5e86112632ade1dc2a6da27ee8f0
parent0e16e4d19a3ffc16d34a39c3ded3a9b20c1298b8 (diff)
downloadhercules-ebff7968504ee090961390820ce74458d7b0f956.tar.gz
hercules-ebff7968504ee090961390820ce74458d7b0f956.tar.bz2
hercules-ebff7968504ee090961390820ce74458d7b0f956.tar.xz
hercules-ebff7968504ee090961390820ce74458d7b0f956.zip
Add configurable way to show char servers with color in list in client.
Options configurable in login-server.conf in users_count section.
-rw-r--r--conf/login/login-server.conf16
-rw-r--r--src/login/lclif.c2
-rw-r--r--src/login/login.c60
-rw-r--r--src/login/login.h7
4 files changed, 84 insertions, 1 deletions
diff --git a/conf/login/login-server.conf b/conf/login/login-server.conf
index 71928e3d0..4ad02deb2 100644
--- a/conf/login/login-server.conf
+++ b/conf/login/login-server.conf
@@ -54,6 +54,22 @@ login_configuration: {
date_format: "%Y-%m-%d %H:%M:%S"
}
+ // for packet version >= 20170726
+ users_count: {
+ // if false, dont show any colored strings.
+ // if true, show special users count numbers for coloring char servers.
+ send_user_count_description: true
+
+ // users counts for use different colors.
+ // below 'low' show green text
+ // below 'medium' show oragne text
+ // below 'high' show red text
+ // higher 'high' show purple text
+ low: 200
+ medium: 500
+ high: 1000
+ }
+
// Account engine configuration
account: {
// Can you use _M/_F to make new accounts on the server?
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 360160b4f..3db9558b8 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1815,6 +1815,38 @@ bool login_config_read_permission(const char *filename, struct config_t *config,
}
/**
+ * 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.
@@ -1843,6 +1875,8 @@ bool login_config_read(const char *filename, bool imported)
retval = false;
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
retval = false;
@@ -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
//--------------------------------------
@@ -2175,11 +2233,13 @@ void login_defaults(void) {
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 38d14d797..d5c9972c0 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -121,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
@@ -218,10 +223,12 @@ struct login_interface {
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
};