From: Ruediger M. <swe...@gm...> - 2004-11-25 02:44:13
|
On Wednesday 24 November 2004 19:27, Ludwig Nussel wrote: > diff -u old new --- rcon.c.old 2004-11-24 13:28:01.000000000 +0100 +++ rcon.c.new 2004-11-24 13:27:45.000000000 +0100 @@ -652,6 +652,7 @@ unsigned short port = 0; char* arg_ip = NULL; char* arg_port = NULL; + char* arg_cmd = NULL; char prompt[] = "RCON> "; @@ -692,7 +693,7 @@ if( argc-argpos<2 || !strcmp(argv[argpos],"--help")) { - printf(_("Usage: %s [server type] <ip> <port>\n"),argv[0]); + printf(_("Usage: %s [server type] <ip> <port> [passwd] [cmd]\n"),argv[0]); printf(_(" server type is either --qws, --hws or --hls.\n")); printf(_(" If no server type is specified, Q3 style rcon is assumed. \n")); return 1; @@ -722,23 +723,30 @@ if(set_nonblock(rcon_fd) == -1) failed("fcntl"); - if(getenv("XQF_RCON_PASSWORD")) + if (argc-argpos<=0) { - rcon_password = g_strdup(getenv("XQF_RCON_PASSWORD")); + while(!buf || !*buf) + { + // translator: readline prompt + buf = readline(_("Password: ")); + } + rcon_password = g_strdup(buf); } else { - while(!buf || !*buf) + rcon_password=argv[argpos++]; + if (argc-argpos>0) { - // translator: readline prompt - buf = readline(_("Password: ")); + arg_cmd = argv[argpos++]; } - rcon_password = g_strdup(buf); } - - buf = readline(prompt); - while(buf) + + if (arg_cmd == NULL) { + buf = readline(prompt); + + while(buf) + { res = rcon_send(buf); if (res < 0) { failed("send"); @@ -761,10 +769,37 @@ } } } + if(*buf) add_history(buf); free(buf); buf = readline(prompt); + } + } + else + { + res = rcon_send(arg_cmd); + if (res < 0) { + failed("send"); + } + else + { + if (wait_read_timeout(rcon_fd, 5, 0) <= 0) + { + printf ("*** timeout waiting for reply\n"); + } + else + { + char* msg; + /* see if more packets arrive within a short interval */ + while(wait_read_timeout(rcon_fd, 0, 50000) > 0) + { + msg = rcon_receive(); + printf("%s", msg); + g_free(msg); + } + } + } } return 0; } >> Ok so maybe its also good idea to add a commandline parameter for >> this value too - so the user could switch between fast and stable. > The real fix would be to use terminal functions for placing the > cursor and process packets asynchronously like the GUI does. Of course that would be nice for the console mode but not if you want to use the output via pipes etc. (therefore I made this patch) cu Rudi |