1 // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
2 // For more information, see LICENCE in the main folder
4 #include "../common/socket.h"
5 #include "../common/showmsg.h"
6 #include "../common/timer.h"
7 #include "../common/ers.h"
8 #include "../common/cli.h"
10 #include "char_cnslif.h"
15 /*======================================================
16 * Login-Server help option info
17 *------------------------------------------------------*/
18 void display_helpscreen(bool do_exit)
20 ShowInfo("Usage: %s [options]\n", SERVER_NAME);
22 ShowInfo("Options:\n");
23 ShowInfo(" -?, -h [--help]\t\tDisplays this help screen.\n");
24 ShowInfo(" -v [--version]\t\tDisplays the server's version.\n");
25 ShowInfo(" --run-once\t\t\tCloses server after loading (testing).\n");
26 ShowInfo(" --char-config <file>\t\tAlternative char-server configuration.\n");
27 ShowInfo(" --lan-config <file>\t\tAlternative lag configuration.\n");
28 ShowInfo(" --inter-config <file>\t\tAlternative inter-server configuration.\n");
29 ShowInfo(" --msg-config <file>\t\tAlternative message configuration.\n");
35 * Timered function to check if the console has a new event to be read.
36 * @param tid: timer id
37 * @param tick: tick of execution
38 * @param id: user account id
42 int cnslif_console_timer(int tid, unsigned int tick, int id, intptr_t data) {
43 char buf[MAX_CONSOLE_IN]; //max cmd atm is 63+63+63+3+3
45 memset(buf,0,MAX_CONSOLE_IN); //clear out buf
48 if(fgets(buf, MAX_CONSOLE_IN, stdin)==NULL)
50 else if(strlen(buf)>MIN_CONSOLE_IN)
56 // Console Command Parser [Wizputer]
57 int cnslif_parse(const char* buf)
63 if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 ){
64 if((n = sscanf(buf, "%63[^\n]", type))<1) return -1; //nothing to do no arg
66 if( n != 2 ){ //end string
67 ShowNotice("Type: '%s'\n",type);
71 ShowNotice("Type of command: '%s' || Command: '%s'\n",type,command);
73 if( n == 2 && strcmpi("server", type) == 0 ){
74 if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 ){
77 else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 )
78 ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n");
79 else if( strcmpi("reloadconf", command) == 0 ) {
80 ShowInfo("Reloading config file \"%s\"\n", CHAR_CONF_NAME);
81 char_config_read(CHAR_CONF_NAME, false);
84 else if( strcmpi("ers_report", type) == 0 ){
87 else if( strcmpi("help", type) == 0 ){
88 ShowInfo("Available commands:\n");
89 ShowInfo("\t server:shutdown => Stops the server.\n");
90 ShowInfo("\t server:alive => Checks if the server is running.\n");
91 ShowInfo("\t server:reloadconf => Reload config file: \"%s\"\n", CHAR_CONF_NAME);
92 ShowInfo("\t ers_report => Displays database usage.\n");
98 void do_init_chcnslif(void){
99 if( charserv_config.console ){ //start listening
100 add_timer_func_list(cnslif_console_timer, "cnslif_console_timer");
101 add_timer_interval(gettick()+1000, cnslif_console_timer, 0, 0, 1000); //start in 1s each 1sec