Skip to content
Permalink
Browse files
Merge pull request #96 from cydh/console/server-reloadconf
server:reloadconf
Look cute enough, 
Don't forget you need to have console enable in *_athena.conf to use it.
  • Loading branch information
lighta committed Sep 12, 2014
2 parents f703f59 + 7cac208 commit 20ff69e5cefbcd325bce269c80f43b8dd3935223
Showing with 85 additions and 60 deletions.
  1. +48 −42 src/char/char.c
  2. +1 −0 src/char/char.h
  3. +5 −0 src/char/char_cnslif.c
  4. +25 −18 src/login/login.c
  5. +1 −0 src/login/login.h
  6. +5 −0 src/login/logincnslif.c
@@ -2527,13 +2527,13 @@ void char_set_defaults(){
charserv_config.guild_exp_rate = 100;
}

int char_config_read(const char* cfgName){
bool char_config_read(const char* cfgName, bool normal){
char line[1024], w1[1024], w2[1024];
FILE* fp = fopen(cfgName, "r");

if (fp == NULL) {
ShowError("Configuration file not found: %s.\n", cfgName);
return 1;
return false;
}

while(fgets(line, sizeof(line), fp)) {
@@ -2545,6 +2545,49 @@ int char_config_read(const char* cfgName){

remove_control_chars(w1);
remove_control_chars(w2);

// Config that loaded only when server started, not by reloading config file
if (normal) {
if (strcmpi(w1, "userid") == 0) {
safestrncpy(charserv_config.userid, w2, sizeof(charserv_config.userid));
} else if (strcmpi(w1, "passwd") == 0) {
safestrncpy(charserv_config.passwd, w2, sizeof(charserv_config.passwd));
} else if (strcmpi(w1, "server_name") == 0) {
safestrncpy(charserv_config.server_name, w2, sizeof(charserv_config.server_name));
} else if (strcmpi(w1, "wisp_server_name") == 0) {
if (strlen(w2) >= 4) {
safestrncpy(charserv_config.wisp_server_name, w2, sizeof(charserv_config.wisp_server_name));
}
} else if (strcmpi(w1, "login_ip") == 0) {
charserv_config.login_ip = host2ip(w2);
if (charserv_config.login_ip) {
char ip_str[16];
safestrncpy(charserv_config.login_ip_str, w2, sizeof(charserv_config.login_ip_str));
ShowStatus("Login server IP address : %s -> %s\n", w2, ip2str(charserv_config.login_ip, ip_str));
}
} else if (strcmpi(w1, "login_port") == 0) {
charserv_config.login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
charserv_config.char_ip = host2ip(w2);
if (charserv_config.char_ip) {
char ip_str[16];
safestrncpy(charserv_config.char_ip_str, w2, sizeof(charserv_config.char_ip_str));
ShowStatus("Character server IP address : %s -> %s\n", w2, ip2str(charserv_config.char_ip, ip_str));
}
} else if (strcmpi(w1, "bind_ip") == 0) {
charserv_config.bind_ip = host2ip(w2);
if (charserv_config.bind_ip) {
char ip_str[16];
safestrncpy(charserv_config.bind_ip_str, w2, sizeof(charserv_config.bind_ip_str));
ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip2str(charserv_config.bind_ip, ip_str));
}
} else if (strcmpi(w1, "char_port") == 0) {
charserv_config.char_port = atoi(w2);
} else if (strcmpi(w1, "console") == 0) {
charserv_config.console = config_switch(w2);
}
}

if(strcmpi(w1,"timestamp_format") == 0) {
safestrncpy(timestamp_format, w2, sizeof(timestamp_format));
} else if(strcmpi(w1,"console_silent")==0){
@@ -2553,41 +2596,6 @@ int char_config_read(const char* cfgName){
ShowInfo("Console Silent Setting: %d\n", atoi(w2));
} else if(strcmpi(w1,"stdout_with_ansisequence")==0){
stdout_with_ansisequence = config_switch(w2);
} else if (strcmpi(w1, "userid") == 0) {
safestrncpy(charserv_config.userid, w2, sizeof(charserv_config.userid));
} else if (strcmpi(w1, "passwd") == 0) {
safestrncpy(charserv_config.passwd, w2, sizeof(charserv_config.passwd));
} else if (strcmpi(w1, "server_name") == 0) {
safestrncpy(charserv_config.server_name, w2, sizeof(charserv_config.server_name));
} else if (strcmpi(w1, "wisp_server_name") == 0) {
if (strlen(w2) >= 4) {
safestrncpy(charserv_config.wisp_server_name, w2, sizeof(charserv_config.wisp_server_name));
}
} else if (strcmpi(w1, "login_ip") == 0) {
charserv_config.login_ip = host2ip(w2);
if (charserv_config.login_ip) {
char ip_str[16];
safestrncpy(charserv_config.login_ip_str, w2, sizeof(charserv_config.login_ip_str));
ShowStatus("Login server IP address : %s -> %s\n", w2, ip2str(charserv_config.login_ip, ip_str));
}
} else if (strcmpi(w1, "login_port") == 0) {
charserv_config.login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
charserv_config.char_ip = host2ip(w2);
if (charserv_config.char_ip) {
char ip_str[16];
safestrncpy(charserv_config.char_ip_str, w2, sizeof(charserv_config.char_ip_str));
ShowStatus("Character server IP address : %s -> %s\n", w2, ip2str(charserv_config.char_ip, ip_str));
}
} else if (strcmpi(w1, "bind_ip") == 0) {
charserv_config.bind_ip = host2ip(w2);
if (charserv_config.bind_ip) {
char ip_str[16];
safestrncpy(charserv_config.bind_ip_str, w2, sizeof(charserv_config.bind_ip_str));
ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip2str(charserv_config.bind_ip, ip_str));
}
} else if (strcmpi(w1, "char_port") == 0) {
charserv_config.char_port = atoi(w2);
} else if (strcmpi(w1, "char_maintenance") == 0) {
charserv_config.char_maintenance = atoi(w2);
} else if (strcmpi(w1, "char_new") == 0) {
@@ -2664,8 +2672,6 @@ int char_config_read(const char* cfgName){
charserv_config.char_config.char_del_option = atoi(w2);
} else if(strcmpi(w1,"db_path")==0) {
safestrncpy(schema_config.db_path, w2, sizeof(schema_config.db_path));
} else if (strcmpi(w1, "console") == 0) {
charserv_config.console = config_switch(w2);
} else if (strcmpi(w1, "fame_list_alchemist") == 0) {
fame_list_size_chemist = atoi(w2);
if (fame_list_size_chemist > MAX_FAME_LIST) {
@@ -2709,13 +2715,13 @@ int char_config_read(const char* cfgName){
} else if (strcmpi(w1, "char_checkdb") == 0) {
charserv_config.char_check_db = config_switch(w2);
} else if (strcmpi(w1, "import") == 0) {
char_config_read(w2);
char_config_read(w2, normal);
}
}
fclose(fp);

ShowInfo("Done reading %s.\n", cfgName);
return 0;
return true;
}


@@ -2811,7 +2817,7 @@ int do_init(int argc, char **argv)
cli_get_options(argc,argv);

char_set_defaults();
char_config_read(CHAR_CONF_NAME);
char_config_read(CHAR_CONF_NAME, true);
char_lan_config_read(LAN_CONF_NAME);
char_set_default_sql();
char_sql_config_read(SQL_CONF_NAME);
@@ -271,6 +271,7 @@ int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, i
int char_msg_config_read(char *cfgName);
const char* char_msg_txt(int msg_number);
void char_do_final_msg(void);
bool char_config_read(const char* cfgName, bool normal);


#endif /* _CHAR_SQL_H_ */
@@ -77,6 +77,10 @@ int cnslif_parse(const char* buf)
}
else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 )
ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n");
else if( strcmpi("reloadconf", command) == 0 ) {
ShowInfo("Reloading config file \"%s\"\n", CHAR_CONF_NAME);
char_config_read(CHAR_CONF_NAME, false);
}
}
else if( strcmpi("ers_report", type) == 0 ){
ers_report();
@@ -85,6 +89,7 @@ int cnslif_parse(const char* buf)
ShowInfo("Available commands:\n");
ShowInfo("\t server:shutdown => Stops the server.\n");
ShowInfo("\t server:alive => Checks if the server is running.\n");
ShowInfo("\t server:reloadconf => Reload config file: \"%s\"\n", CHAR_CONF_NAME);
ShowInfo("\t ers_report => Displays database usage.\n");
}

@@ -538,14 +538,15 @@ int login_lan_config_read(const char *lancfgName) {
/**
* Reading main configuration file.
* @param cfgName: Name of the configuration (could be fullpath)
* @return 0:success, 1:failure (file not found|readable)
* @param normal: Config read normally when server started
* @return True:success, Fals:failure (file not found|readable)
*/
int login_config_read(const char* cfgName) {
bool login_config_read(const char* cfgName, bool normal) {
char line[1024], w1[32], w2[1024];
FILE* fp = fopen(cfgName, "r");
if (fp == NULL) {
ShowError("Configuration file (%s) not found.\n", cfgName);
return 1;
return false;
}
while(fgets(line, sizeof(line), fp)) {
if (line[0] == '/' && line[1] == '/')
@@ -554,6 +555,21 @@ int login_config_read(const char* cfgName) {
if (sscanf(line, "%31[^:]: %1023[^\r\n]", w1, w2) < 2)
continue;

// Config that loaded only when server started, not by reloading config file
if (normal) {
if( !strcmpi(w1, "bind_ip") ) {
login_config.login_ip = host2ip(w2);
if( login_config.login_ip ) {
char ip_str[16];
ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_config.login_ip, ip_str));
}
}
else if( !strcmpi(w1, "login_port") )
login_config.login_port = (uint16)atoi(w2);
else if(!strcmpi(w1, "console"))
login_config.console = (bool)config_switch(w2);
}

if(!strcmpi(w1,"timestamp_format"))
safestrncpy(timestamp_format, w2, 20);
else if(strcmpi(w1,"db_path")==0)
@@ -565,16 +581,7 @@ int login_config_read(const char* cfgName) {
if( msg_silent ) /* only bother if we actually have this enabled */
ShowInfo("Console Silent Setting: %d\n", atoi(w2));
}
else if( !strcmpi(w1, "bind_ip") ) {
login_config.login_ip = host2ip(w2);
if( login_config.login_ip ) {
char ip_str[16];
ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_config.login_ip, ip_str));
}
}
else if( !strcmpi(w1, "login_port") ) {
login_config.login_port = (uint16)atoi(w2);
} else if(!strcmpi(w1, "log_login"))
else if(!strcmpi(w1, "log_login"))
login_config.log_login = (bool)config_switch(w2);
else if(!strcmpi(w1, "new_account"))
login_config.new_account_flag = (bool)config_switch(w2);
@@ -594,8 +601,6 @@ int login_config_read(const char* cfgName) {
login_config.min_group_id_to_connect = atoi(w2);
else if(!strcmpi(w1, "date_format"))
safestrncpy(login_config.date_format, w2, sizeof(login_config.date_format));
else if(!strcmpi(w1, "console"))
login_config.console = (bool)config_switch(w2);
else if(!strcmpi(w1, "allowed_regs")) //account flood protection system
login_config.allowed_regs = atoi(w2);
else if(!strcmpi(w1, "time_allowed"))
@@ -657,8 +662,10 @@ int login_config_read(const char* cfgName) {
}
#endif
else if(!strcmpi(w1, "import"))
login_config_read(w2);
login_config_read(w2, normal);
else {// try the account engines
if (!normal)
continue;
if (accounts && accounts->set_property(accounts, w1, w2))
continue;
// try others
@@ -668,7 +675,7 @@ int login_config_read(const char* cfgName) {
}
fclose(fp);
ShowInfo("Finished reading %s.\n", cfgName);
return 0;
return true;
}

/**
@@ -812,7 +819,7 @@ int do_init(int argc, char** argv) {
login_set_defaults();
logcnslif_get_options(argc,argv);

login_config_read(login_config.loginconf_name);
login_config_read(login_config.loginconf_name, true);
msg_config_read(login_config.msgconf_name);
login_lan_config_read(login_config.lanconf_name);
//end config
@@ -121,6 +121,7 @@ extern struct Login_Config login_config;
int login_msg_config_read(char *cfgName);
const char* login_msg_txt(int msg_number);
void login_do_final_msg(void);
bool login_config_read(const char* cfgName, bool normal);

/// Online User Database [Wizputer]
struct online_login_data {
@@ -124,6 +124,10 @@ int cnslif_parse(const char* buf){
}
else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 )
ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n");
else if( strcmpi("reloadconf", command) == 0 ) {
ShowInfo("Reloading config file \"%s\"\n", login_config.loginconf_name);
login_config_read(login_config.loginconf_name, false);
}
}
if( strcmpi("create",type) == 0 )
{
@@ -151,6 +155,7 @@ int cnslif_parse(const char* buf){
ShowInfo("Available commands:\n");
ShowInfo("\t server:shutdown => Stops the server.\n");
ShowInfo("\t server:alive => Checks if the server is running.\n");
ShowInfo("\t server:reloadconf => Reload config file: \"%s\"\n", login_config.loginconf_name);
ShowInfo("\t ers_report => Displays database usage.\n");
ShowInfo("\t create:<username> <password> <sex:M|F> => Creates a new account.\n");
}

1 comment on commit 20ff69e

@cydh
Copy link
Contributor

@cydh cydh commented on 20ff69e Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol "cute" u say
/me slaps @lighta

Please sign in to comment.