From: Peep P. <so...@us...> - 2004-03-18 20:59:19
|
Update of /cvsroot/agd/server/lib/sys In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2558 Modified Files: player.c Log Message: New features; ctime() in LPC. Index: player.c =================================================================== RCS file: /cvsroot/agd/server/lib/sys/player.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- player.c 16 Mar 2004 14:02:55 -0000 1.6 +++ player.c 18 Mar 2004 20:49:37 -0000 1.7 @@ -1,9 +1,6 @@ string _name, last_cmd; -void input(string in); -void set_name(string name); - -void create(void) { +void create() { input_to("input"); } @@ -11,40 +8,93 @@ _name = name; } -string query_name() -{ +string query_name() { return _name; } -void do_cmd(string cmd) -{ - if(cmd == "/quit") { - shout(time() + ": " + _name + " has quit the game\n", this_object()); - destruct(this_object()); - } else if(cmd == "/uptime") { - write("The driver has been running for " + asctime(uptime()) + "\n"); - } else if(cmd == "/print_objs") { - print_objs(); - } else { - shout(time() + ": " + _name + " said: " + cmd + "\n", this_object()); - write(time() + ": You say: " + cmd + "\n"); +void write_help() { + write("Available commands:\n"); + write("\t/help: Displays this text.\n"); + write("\t/uptime: Shows for how long the driver has been running.\n"); + write("\t/version: Shows AGD version information.\n"); + write("\t/quit: Quits the game.\n"); + write("\t/.: Repeats last command.\n"); +} + +/* Converts a time integer into a textual representation */ +string ctime(int t) { + int secs, mins, hrs, days; + string ret; + + secs = t; + if(secs >= 60) { + secs /*%=*/ = secs % 60; + mins = t /*/=*/ = t / 60; + if(mins >= 60) { + mins /*%=*/ = mins % 60; + hrs = t /*/=*/ = t / 60; + if(hrs > 24) { + hrs /*%=*/ = hrs % 24; + days = t / 24; + } + } + } + + ret = ""; /* :-( */ + if(days) + ret/* +=*/ = ret + days + " day" + days>1?"s":"" + " "; + if(hrs) + ret/* +=*/ = ret + hrs + " hour" + hrs>1?"s":"" + " "; + if(mins) + ret/* +=*/ = ret + mins + " minute" + mins>1?"s":"" + " "; + if(secs) { + ret/* +=*/ = ret + secs + " second" + secs>1?"s":"" + " "; } + return ret; } -void input(string in) -{ - if(in == ".") { - if(last_cmd) - do_cmd(last_cmd); - else - write("No last command.\n"); +void input(string cmd) { + if(cmd[0] == '/') { +/* switch(cmd[1..]) { + case "quit": + break; + case "uptime": + break; + case "print_objs": + break; + }*/ + if(cmd == "/quit") { + shout(time() + ": " + capitalize(_name) + " has quit the game\n", this_object()); + destruct(this_object()); + } else if(cmd == "/uptime") { + write("The driver has been running for " + ctime(uptime()) + "\n"); + } else if(cmd == "/print_objs") { + print_objs(); + } else if(cmd == "/version") { + "/sys/master"->write_version(); + } else if(cmd == "/help") { + write_help(); + } else if(cmd == "/.") { + if(last_cmd) { + input(last_cmd); + } else + write("No last command.\n"); + } else { + write("Unknown command.\n"); + } } else { - do_cmd(in); - last_cmd = in; + shout(time() + ": " + capitalize(_name) + " says: " + cmd + "\n", this_object()); + write(time() + ": You say: " + cmd + "\n"); } + if(cmd != "/.") + last_cmd = cmd; input_to("input"); } void write_prompt() { write("> "); } + +void net_dead() { + shout(_name + " went netdead!", (object)0); +} |