diff --git a/exec/finger.js b/exec/finger.js index 860ce851d0a60cae46f0cab3e5e87ba7abdc42ae..0aa1e30384ff82cc032b1fa95ef1310ee7957747 100644 --- a/exec/finger.js +++ b/exec/finger.js @@ -1,8 +1,10 @@ -// finger.js +// $Id$ -// A simple finger client +// A simple finger/systat (who) client suitable for running via the BBS or JSexec -load('sockdefs.js'); +"use strict"; + +var lib = load({}, "finger_lib.js"); var dest; var use_udp = false; var protocol = "finger"; @@ -21,24 +23,25 @@ for(i = 0; i < argc; i++) { } } -if(!dest && (dest = prompt("User (user@hostname)"))==null) - exit(); +function finger(dest, protocol, use_udp) +{ + if(!dest && (dest = prompt("User (user@hostname)"))==null) + return; -if((hp = dest.indexOf('@'))==-1) { - dest += "@" + system.host_name; - hp = dest.indexOf('@') -} + writeln(); + var hp; + if((hp = dest.indexOf('@')) == -1) { + dest += "@" + system.host_name; + hp = dest.indexOf('@') + } -host = dest.slice(hp+1); -sock = new Socket(use_udp ? SOCK_DGRAM : SOCK_STREAM); -//sock.debug = true; -if(!sock.connect(host, protocol)) - alert("Connection to " + host + " failed with error " + sock.last_error); -else { - sock.send(dest.slice(0,hp)+"\r\n"); - if(use_udp) - print(sock.recvfrom().data); - else while(sock.is_connected && !js.terminated) - print(sock.readline()); + var host = dest.slice(hp + 1); + var result = lib.request(host, dest.slice(0, hp), protocol, use_udp); + if(typeof result != 'object') + alert(result); + else + for(var i in result) + writeln(result[i]); } -sock.close(); + +finger(dest, protocol, use_udp); \ No newline at end of file