|
From: Peep P. <so...@us...> - 2004-07-24 18:09:26
|
Update of /cvsroot/agd/server/lib/sys In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1416 Modified Files: player.lpc Log Message: * using add_command system * using process_input apply * some more player commands: tell, history, idle, upgrade, shutdown Index: player.lpc =================================================================== RCS file: /cvsroot/agd/server/lib/sys/player.lpc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- player.lpc 21 Jul 2004 12:11:21 -0000 1.1 +++ player.lpc 24 Jul 2004 18:09:16 -0000 1.2 @@ -1,11 +1,22 @@ -string _name, last_cmd; -int num_input; +string _name; +string *cmd_hist; -void create() { -/* string foo = "foobar"; - foo[4..5] = "ie"; - write("foo: " + foo + "\n");*/ - input_to("input"); +void setup_cmds() { + add_command("say"); + add_command("quit"); + add_command("tell"); + add_command("who"); + add_command("idle"); + add_command("history"); + + add_command("help"); + add_command("uptime"); + add_command("version"); + add_command("time"); + + add_command("update"); + add_command("upgrade"); + add_command("shutdown"); } void set_name(string name) { @@ -16,16 +27,43 @@ return _name; } -void write_help() { +void old_cmd(int i) { + if(i >= 0 && i < sizeof(cmd_hist)) { + do_command(cmd_hist[i]); + } else + write("Invalid number.\n"); +} + +int process_input(string str) { + if(str == ".") { + old_cmd(sizeof(cmd_hist)-1); + return 1; + } else if(str[0] == '!') { + int arg; + arg = atoi(str[1..strlen(str)]); + if(!arg && str[1] != '0') { + write("Syntax: !<number>\n"); + return 1; + } + old_cmd(arg); + return 1; + } else { + cmd_hist += ({ str }); + } + return 0; +} + +void write_prompt() { + write("> "); +} + +void net_dead() { + shout(_name + " went netdead!"); +} + +void do_help() { write("Available commands:\n" - "\tsay: Says something to everyone logged on.\n" - "\thelp: Displays this text.\n" - "\tuptime: Shows for how long the driver has been running.\n" - "\tversion: Shows AGD version information.\n" - "\tquit: Quits the game.\n" - "\ttime: Shows current time.\n" - "\twho: Shows who's playing.\n" - "\t.: Repeats last command.\n"); + " say <text>, help, uptime, version, quit, time, who, tell <person> <text>\n"); } /* Converts a time integer into a textual representation, @@ -72,7 +110,7 @@ return ret; } -object do_update(string path) { +void do_update(string path) { object ret; ret = load_object(path); if(ret) { @@ -80,63 +118,110 @@ } else { write("Failed to update " + path + "!\n"); } - return ret; } -void input(string cmd) { - if(strlen(cmd) >= 3 && cmd[0..2] == "say") { - string t = strftime(time(), "[%H:%M] "); - string text = cmd[4..strlen(cmd)]; - shout(t + capitalize(_name) + " says: "+ text +"\n"); - write(t + "You say: " + text + "\n"); - } else if(cmd == "quit") { - shout(strftime(time(), "[%H:%M] ") + capitalize(_name) + - " has quit the game.\n"); - destruct(this_object()); - } else if(cmd == "uptime") { - write("AGD " + __VERSION__ + " has been running for " + ctime(uptime()) + ".\n"); - } else if(cmd == "version") { - "/sys/master"->write_version(); - } else if(cmd == "help") { - write_help(); - } else if(strlen(cmd) >= 6 && cmd[0..5] == "update") { - string filename = cmd[6..strlen(cmd)]; - do_update(filename); - } else if(cmd == "time") { - int t = time(); - write("The current time is: " + asctime(t) + ".\n"); - } else if(cmd == "who") { - object *ppl = users(); - int i; - for(;i<sizeof(ppl);i++) { - write(i + ": " + ppl[i]->query_name() + "\n"); - } - if(sizeof(ppl) == 1) { - write("Nobody else besides you. :(\n"); - } else { - write(sizeof(ppl) + " players.\n"); - } - } else if(cmd == ".") { - if(last_cmd) { - input(last_cmd); - } else - write("No last command.\n"); - } else { - write("Unknown command. Try 'help'.\n"); - } +void do_say(string text) { + shout(capitalize(_name) + " says: " + text + "\n"); +} - if(cmd != ".") { - last_cmd = cmd; - num_input++; +void do_quit() { + shout(capitalize(_name) + " has quit the game.\n"); + destruct(); +} + +void do_uptime() { + write("AGD " + __VERSION__ + " has been running for " + ctime(uptime()) + ".\n"); +} + +void do_version() { + master()->write_version(); +} + +void do_time() { + int t = time(); + write("The current time is: " + asctime(t) + ".\n"); +} + +void do_who() { + object *ppl = users(); + int i; + + if(sizeof(ppl) == 1) { + write("Nobody else besides you. :(\n"); + return; } - input_to("input"); + + for(;i<sizeof(ppl);i++) { + write(i + ". " + ppl[i]->query_name() + "\n"); + } + + write(sizeof(ppl) + " players.\n"); } -void write_prompt() { - write(_name + /* "@" + __HOSTNAME__ + */ ":" + - num_input + "$ "); +void do_tell(string str) { + string *args; + string text; + object ob; + + args = explode(str, " "); + if(!args || sizeof(args) < 2 || !args[0] || !args[1]) { + write("Syntax: tell <person> <text>\n"); + return; + } + + ob = find_player(args[0]); + if(!ob) { + write("No such player.\n"); + return; + } + + if(this_player()->query_name() == ob->query_name()) { + write("You try to have conversation with yourself for a while, but it gets boring quickly because you usually know what you'll answer.\n"); + return; + } + + text = implode(args[1..sizeof(args)-1], " "); + tell_object(ob, capitalize(_name) + " tells you: " + text + "\n"); + write("You tell " + capitalize(args[0]) + ": " + text + "\n"); } -void net_dead() { - shout(_name + " went netdead!"); +void do_history() { + int i; + for(i=0;i<sizeof(cmd_hist);i++) { + write(i + ": " + cmd_hist[i] + "\n"); + } + write("You can invoke an old command using !<number>\n"); +} + +void do_idle(string str) { + object ob; + int t; + + ob = find_player(str); + if(!ob) { + write("No such player.\n"); + return; + } + + t = query_idle(ob); + if(t) + write(ob->query_name() + " has been idle for " + ctime(t) + ".\n"); + else + write(ob->query_name() + " is not idle.\n"); +} + +void do_upgrade() { + object ob; + ob = load_object("/sys/player"); + if(!ob) { + write("Couldn't load /sys/player.\n"); + return; + } + exec(ob); + destruct(); +} + +void do_shutdown() { + write("Ok.. shutting down.\n"); + shutdown(); } |