viewing paste ra-console-wip | Diff

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/lighta/Documents/Myscript/RO/Servs/ra_pincode/src
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: char/char.c
--- char/char.c (revision 17251)
+++ char/char.c (working copy)
@@ -14,6 +14,7 @@
 #include "../common/utils.h"
 #include "../common/cli.h"
 #include "../common/random.h"
+#include "../common/ers.h"
 #include "int_guild.h"
 #include "int_homun.h"
 #include "int_mercenary.h"
@@ -4343,21 +4344,35 @@
 }
 
 // Console Command Parser [Wizputer]
-int parse_console(const char* command)
+int parse_console(const char* buf)
 {
-       ShowNotice("Console command: %s\n", command);
+       char type[64];
+       char command[64];
+       int n=0;
 
-       if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 || strcmpi("end", command) == 0 )
+       if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 ){
+               if((n = sscanf(buf, "%63[^\n]", type))<1) return -1; //nothing to do no arg
+       }
+       if( n != 2 ){ //end string
+               command[0] = '\0';
+       }
+       ShowNotice("Type of command: '%s' || Command: '%s'\n",type,command);
+
+       if( n == 2 && strcmpi("server", type) == 0 ){
+               if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 ){
                runflag = 0;
+               }
        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("help", command) == 0 )
-       {
-               ShowInfo("To shutdown the server:\n");
-               ShowInfo("  'shutdown|exit|quit|end'\n");
-               ShowInfo("To know if server is alive:\n");
-               ShowInfo("  'alive|status'\n");
        }
+       else if( strcmpi("ers_report", type) == 0 ){
+               ers_report();
+       }
+       else if( strcmpi("help", type) == 0 ){
+               ShowInfo("Command available :");
+               ShowInfo("\t server shutdown|alive : stop server\n");
+               ShowInfo("\t ers_report : display the db usage\n");
+       }
 
        return 0;
 }
@@ -5182,11 +5197,6 @@
        add_timer_func_list(online_data_cleanup, "online_data_cleanup");
        add_timer_interval(gettick() + 1000, online_data_cleanup, 0, 0, 600 * 1000);
 
-       if( console )
-       {
-               //##TODO invoke a CONSOLE_START plugin event
-       }
-
        //Cleaning the tables for NULL entrys @ startup [Sirius]
        //Chardb clean
        if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '0'", char_db) )
@@ -5215,6 +5225,10 @@
                runflag = CHARSERVER_ST_RUNNING;
        }
 
+       if( console ){ //start listening
+               add_timer_func_list(parse_console_timer, "parse_console_timer");
+               add_timer_interval(gettick()+1000, parse_console_timer, 0, 0, 1000); //start in 1s each 1sec
+       }
        return 0;
 }
 
Index: common/cli.c
--- common/cli.c (revision 17251)
+++ common/cli.c (working copy)
@@ -1,6 +1,11 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#ifdef WIN32
+       #include <conio.h>
+#else
+       #include <sys/poll.h>
+#endif
 
 #include "cbasetypes.h"
 #include "showmsg.h"
@@ -135,3 +140,29 @@
     }
     return 1;
 }
+
+int cli_hasevent(){
+#ifdef WIN32
+       return _kbhit();
+#else
+       struct pollfd fds;
+       fds.fd = 0; /* this is STDIN */
+       fds.events = POLLIN;
+       return poll(&fds, 1, 0);
+#endif
+}
+
+int parse_console_timer(int tid, unsigned int tick, int id, intptr_t data) {
+       char buf[MAX_CONSOLE_IN]; //max cmd atm is 63+63+63+3+3
+
+       memset(buf,0,MAX_CONSOLE_IN); //clear out buf
+
+       if(cli_hasevent()){
+               if(fgets(buf, MAX_CONSOLE_IN, stdin)==NULL)
+                       return -1;
+               else if(strlen(buf)>MIN_CONSOLE_IN)
+                       parse_console(buf);
+       }
+       return 0;
+}
+
Index: common/cli.h
--- common/cli.h (revision 17251)
+++ common/cli.h (working copy)
@@ -12,6 +12,8 @@
 extern "C" {
 #endif
 
+#define MAX_CONSOLE_IN 200 //max is map...
+#define MIN_CONSOLE_IN 4 //min is help
 //map
  extern char* MAP_CONF_NAME;
  extern char* INTER_CONF_NAME;
@@ -31,6 +33,8 @@
 
 extern void display_helpscreen(bool exit);
 int cli_get_options(int argc, char ** argv);
+int parse_console_timer(int tid, unsigned int tick, int id, intptr_t data);
+extern int parse_console(const char* buf); //particular for each serv
 
 #ifdef __cplusplus
 }
Index: login/login.c
--- login/login.c (revision 17251)
+++ login/login.c (working copy)
@@ -12,6 +12,7 @@
 #include "../common/timer.h"
 #include "../common/msg_conf.h"
 #include "../common/cli.h"
+#include "../common/ers.h"
 #include "account.h"
 #include "ipban.h"
 #include "login.h"
@@ -366,51 +367,58 @@
 //-----------------------
 // Console Command Parser [Wizputer]
 //-----------------------
-int parse_console(const char* command)
-{
-       ShowNotice("Console command: %s\n", command);
+int parse_console(const char* buf){
+       char type[64];
+       char command[64];
+       int n=0;
 
-       if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 || strcmpi("end", command) == 0 )
+       if( ( n = sscanf(buf, "%127[^:]:%255[^\n\r]", type, command) ) < 2 ){
+               if((n = sscanf(buf, "%63[^\n]", type))<1) return -1; //nothing to do no arg
+       }
+       if( n != 2 ){ //end string
+               command[0] = '\0';
+       }
+       ShowNotice("Type of command: '%s' || Command: '%s'\n",type,command);
+
+       if( n == 2){
+               if(strcmpi("server", type) == 0 ){
+                       if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 ){
                runflag = 0;
+                       }
        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("help", command) == 0 )
-       {
-               ShowInfo("To shutdown the server:\n");
-               ShowInfo("  'shutdown|exit|quit|end'\n");
-               ShowInfo("To know if server is alive:\n");
-               ShowInfo("  'alive|status'\n");
-               ShowInfo("To create a new account:\n");
-               ShowInfo("  'create'\n");
        }
-       else
-       {// commands with parameters
-               char cmd[128], params[256];
-
-               if( sscanf(command, "%127s %255[^\r\n]", cmd, params) < 2 )
+               if( strcmpi("create",type) == 0 )
                {
-                       return 0;
-               }
-
-               if( strcmpi(cmd, "create") == 0 )
-               {
                        char username[NAME_LENGTH], password[NAME_LENGTH], sex;
-
-                       if( sscanf(params, "%23s %23s %c", username, password, &sex) < 3 || strnlen(username, sizeof(username)) < 4 || strnlen(password, sizeof(password)) < 1 )
-                       {
-                               ShowWarning("Console: Invalid parameters for '%s'. Usage: %s <username> <password> <sex:F/M>\n", cmd, cmd);
+                       if( sscanf(command, "%23s %23s %c", username, password, &sex) < 3 || strnlen(username, sizeof(username)) < 4 || strnlen(password, sizeof(password)) < 1 ){
+                               ShowWarning("Console: Invalid parameters for '%s'. Usage: %s <username> <password> <sex:F/M>\n", type, type);
                                return 0;
                        }
-
-                       if( mmo_auth_new(username, password, TOUPPER(sex), "0.0.0.0") != -1 )
-                       {
+                       if( mmo_auth_new(username, password, TOUPPER(sex), "0.0.0.0") != -1 ){
                                ShowError("Console: Account creation failed.\n");
                                return 0;
                        }
                        ShowStatus("Console: Account '%s' created successfully.\n", username);
                }
        }
+       else if( strcmpi("ers_report", type) == 0 ){
+               ers_report();
+       }
+       else if( strcmpi("help", type) == 0 ){
+               ShowInfo("Command available :");
+               ShowInfo("\t server shutdown|alive : stop|chk server\n");
+               ShowInfo("\t ers_report : display the db usage\n");
+               ShowInfo("\t create <username> <password> <sex:F|M>: create new account\n");
+       }
 
+       else
+       {// commands with parameters
+
+
+
+       }
+
        return 0;
 }
 
@@ -1916,10 +1924,6 @@
                }
        }
 
-       if( login_config.console ) {
-               //##TODO invoke a CONSOLE_START plugin event
-       }
-
        // server port open & binding
        if( (login_fd = make_listen_bind(login_config.login_ip,login_config.login_port)) == -1 ) {
                ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",login_config.login_port);
@@ -1934,6 +1938,11 @@
        ShowStatus("The login-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %u).\n\n", login_config.login_port);
        login_log(0, "login server", 100, "login server started");
 
+       if( login_config.console ) {
+               add_timer_func_list(parse_console_timer, "parse_console_timer");
+               add_timer_interval(gettick()+1000, parse_console_timer, 0, 0, 1000); //start in 1s each 1sec
+       }
+
        return 0;
 }
 
Index: map/map.c
--- map/map.c (revision 17251)
+++ map/map.c (working copy)
@@ -3100,8 +3100,7 @@
 /*==========================================
  * Console Command Parser [Wizputer]
  *------------------------------------------*/
-int parse_console(const char* buf)
-{
+int parse_console(const char* buf){
        char type[64];
        char command[64];
        char map[64];
@@ -3114,19 +3113,24 @@
        memset(&sd, 0, sizeof(struct map_session_data));
        strcpy(sd.status.name, "console");
 
-       if( ( n = sscanf(buf, "%63[^:]:%63[^:]:%63s %hd %hd[^\n]", type, command, map, &x, &y) ) < 5 )
-       {
-               if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 )
-               {
-                       n = sscanf(buf, "%63[^\n]", type);
+       if( ( n = sscanf(buf, "%63[^:]:%63[^:]:%63s %hd %hd[^\n]", type, command, map, &x, &y) ) < 5 ){
+               if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 )                {
+                       if((n = sscanf(buf, "%63[^\n]", type))<1) return -1; //nothing to do no arg
                }
        }
 
-       if( n == 5 )
-       {
+       if( n != 5 ){ //end string
+               map[0] = '\0';
+               if( n < 2 )
+                       command[0] = '\0';
+       }
+
+       ShowNotice("Type of command: '%s' || Command: '%s' || Map: '%s' Coords: %d %d\n", type, command, map, x, y);
+
+       if(strcmpi("admin",type) == 0 ) {
+               if(strcmpi("map",command) == 0){
                m = map_mapname2mapid(map);
-               if( m < 0 )
-               {
+                       if( m < 0 ){
                        ShowWarning("Console: Unknown map.\n");
                        return 0;
                }
@@ -3137,42 +3141,23 @@
                if( y > 0 )
                        sd.bl.y = y;
        }
-       else
-       {
-               map[0] = '\0';
-               if( n < 2 )
-                       command[0] = '\0';
-               if( n < 1 )
-                       type[0] = '\0';
-       }
-
-       ShowNotice("Type of command: '%s' || Command: '%s' || Map: '%s' Coords: %d %d\n", type, command, map, x, y);
-
-       if( n == 5 && strcmpi("admin",type) == 0 )
-       {
-               if( !is_atcommand(sd.fd, &sd, command, 0) )
+               else if( !is_atcommand(sd.fd, &sd, command, 0) )
                        ShowInfo("Console: not atcommand\n");
        }
-       else if( n == 2 && strcmpi("server", type) == 0 )
-       {
-               if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 )
-               {
+       else if( n == 2 && strcmpi("server", type) == 0 ){
+               if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 ){
                        runflag = 0;
                }
        }
        else if( strcmpi("ers_report", type) == 0 ){
                ers_report();
        }
-       else if( strcmpi("help", type) == 0 )
-       {
-               ShowInfo("To use GM commands:\n");
-               ShowInfo("  admin:<gm command>:<map of \"gm\"> <x> <y>\n");
-               ShowInfo("You can use any GM command that doesn't require the GM.\n");
-               ShowInfo("No using @item or @warp however you can use @charwarp\n");
-               ShowInfo("The <map of \"gm\"> <x> <y> is for commands that need coords of the GM\n");
-               ShowInfo("IE: @spawn\n");
-               ShowInfo("To shutdown the server:\n");
-               ShowInfo("  server:shutdown\n");
+       else if( strcmpi("help", type) == 0 ) {
+               ShowInfo("Command available :");
+               ShowInfo("\t map <map><x><y> : change our current map\n");
+               ShowInfo("\t admin @acmd : use an atcommand\n");
+               ShowInfo("\t server shutdown : stop server\n");
+               ShowInfo("\t ers_report : display the db usage\n");
        }
 
        return 0;
@@ -3904,11 +3889,6 @@
 
        npc_event_do_oninit();  // Init npcs (OnInit)
 
-       if( console )
-       {
-               //##TODO invoke a CONSOLE_START plugin event
-       }
-
        if (battle_config.pk_mode)
                ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n");
 
@@ -3924,6 +3904,11 @@
                exit(EXIT_FAILURE);
 #endif
 
+       if( console ){ //start listening
+               add_timer_func_list(parse_console_timer, "parse_console_timer");
+               add_timer_interval(gettick()+1000, parse_console_timer, 0, 0, 1000); //start in 1s each 1sec
+       }
+
        return 0;
 }
Viewed 430 times, submitted by lighta.