Skip to content
Snippets Groups Projects
Commit 57e49d4d authored by rswindell's avatar rswindell
Browse files

Detail the whip-saw history of this module.

Use modopts.ini -> [sbbsimsg] -> from_user_prop, if set (e.g. to "name"),
defaults to "alias".
Use human readable BBS name where possible (now in the sbbsimst.lsg).
This module really needs a re-write, but the protocols are sound (finally).
parent f9261e0a
Branches
Tags
No related merge requests found
...@@ -2,6 +2,29 @@ ...@@ -2,6 +2,29 @@
// Synchronet inter-bbs instant message module // Synchronet inter-bbs instant message module
/* History of this module/feature:
Original 2001: Queried systems using Finger (TCP port 79)
Sent message using SMTP-SOML (TCP port 25)
Rev 1.11 2002: Queried system using both TCP and UDP-Finger (port 79)
Still sent messages using SMTP-SOML
Rev 1.22 2007: Queried using SYSTAT/ActiveUser protocol (TCP & UDP port 11)
in addition to Finger (TCP and UDP port 79)
If send via SMTP failed, used MSP protocol (TCP port 18)
Rev 1.25 2009: Removed Finger (both TCP and UDP support), SYSTAT-TCP
and SMTP support, so it now *only*:
Queries using SYSTAT/ActiveUser protocol over UDP port 11
Sends messages using MSP (TCP port 18)
So, while originally the requirements for systems to participate were:
- Synchronet SMTP Server listening on TCP port 25
- fingerservice.js listing on TCP port 79
Now, the requirements are:
- activeuserservice.js (or fingerservice.js) listening on UDP port 11
- mspservice.js listening on TCP port 18
*/
// $Id$ // $Id$
const REVISION = "$Revision$".split(' ')[1]; const REVISION = "$Revision$".split(' ')[1];
...@@ -11,6 +34,11 @@ const UDP_RESPONSE_TIMEOUT = 5000 // milliseconds ...@@ -11,6 +34,11 @@ const UDP_RESPONSE_TIMEOUT = 5000 // milliseconds
load("sbbsdefs.js"); load("sbbsdefs.js");
load("nodedefs.js"); load("nodedefs.js");
load("sockdefs.js"); // SOCK_DGRAM load("sockdefs.js"); // SOCK_DGRAM
var options=load({}, "modopts.js", "sbbsimsg");
if(!options)
options = {};
if(!options.from_user_prop)
options.from_user_prop = "alias";
// Global vars // Global vars
var imsg_user; var imsg_user;
...@@ -35,37 +63,30 @@ if(!f.open("r")) { ...@@ -35,37 +63,30 @@ if(!f.open("r")) {
exit(); exit();
} }
sys = new Array(); var sys = new Array();
list = f.readAll(); list = f.readAll();
f.close(); f.close();
for(i in list) { for(i in list) {
if(list[i]==null) if(list[i]==null)
break; break;
while(list[i].charAt(0)==' ') // skip prepended spaces var line = list[i].trimLeft();
list[i] = list[i].slice(1); if(line.charAt(0)==';') // comment?
continue;
word = list[i].split(/\s+/); var word = line.split('\t');
var host = word[0].trimRight();
if(word[0].charAt(0)==';' || // comment? if(host == system.host_name
word[0] == system.host_name || || host == system.inetaddr) // local system?
word[0] == system.inetaddr) // local system?
continue; // ignore continue; // ignore
if(word[1] != undefined) { var ip_addr = word[1];
if(!word[1].length) var bbs_name = word[2];
{
printf("Setting zero-len %s to undefined\r\n",word[1]);
word[1]=undefined;
}
if(word[1].search(/^\s*$/m)!=-1) if(ip_addr == client.socket.local_ip_address || ip_addr == server.interface_ip_address)
{ continue;
printf("Setting %s to undefined\r\n",word[1]);
word[1]=undefined;
}
}
sys.push( { addr: word[0], ip : word[1], udp: false, failed: false, reply: 999999 } ); sys.push( { addr: host, ip : ip_addr, name: bbs_name, failed: false, reply: 999999 } );
} }
function save_sys_list() function save_sys_list()
...@@ -79,7 +100,7 @@ function save_sys_list() ...@@ -79,7 +100,7 @@ function save_sys_list()
if(sys[i].ip == undefined) if(sys[i].ip == undefined)
f.writeln(sys[i].addr); f.writeln(sys[i].addr);
else else
f.writeln(format("%-63s ", sys[i].addr) + sys[i].ip); f.writeln(format("%-63s\t%s\t%s", sys[i].addr, sys[i].ip, sys[i].name));
} }
f.close(); f.close();
} }
...@@ -89,7 +110,7 @@ function sortarray(a, b) ...@@ -89,7 +110,7 @@ function sortarray(a, b)
return(a.reply-b.reply); return(a.reply-b.reply);
} }
function parse_response(response, show) function parse_response(response, show, sys)
{ {
// Skip header // Skip header
while(response.length && response[0].charAt(0)!='-') while(response.length && response[0].charAt(0)!='-')
...@@ -122,7 +143,9 @@ function parse_response(response, show) ...@@ -122,7 +143,9 @@ function parse_response(response, show)
,response[j],response[j].slice(26))); ,response[j],response[j].slice(26)));
} }
var u = new Object; var u = new Object;
u.host = sys[i].addr; u.host = sys.addr;
u.bbs = sys.name;
u.ip = sys.ip;
u.name = format("%.25s",response[j]); u.name = format("%.25s",response[j]);
u.name = truncsp(u.name); u.name = truncsp(u.name);
imsg_user.push(u); imsg_user.push(u);
...@@ -134,22 +157,17 @@ function list_users(show) ...@@ -134,22 +157,17 @@ function list_users(show)
{ {
imsg_user = new Array(); imsg_user = new Array();
var udp_req=0; var udp_req=0;
var udp_replies=0;
var replies=0; var replies=0;
users = 0; users = 0;
start = new Date(); start = new Date();
print("\1m\1hListing Systems and Users (Ctrl-C to Abort)..."); print("\1m\1hListing Systems and Users (Ctrl-C to Abort)...");
/* UDP systems */
for(i=0;sys[i]!=undefined;i++)
sys[i].udp=false; // Reset the udp flag
sock = new Socket(SOCK_DGRAM); sock = new Socket(SOCK_DGRAM);
//sock.debug=true; //sock.debug=true;
for(i=0;sys[i]!=undefined && !(bbs.sys_status&SS_ABORT);i++) { for(var i=0; sys[i]!=undefined && !(bbs.sys_status&SS_ABORT);i++) {
if(sys[i].ip==undefined) if(sys[i].ip==undefined)
continue; continue;
/* Try SYSTAT and finger */
if(!sock.sendto("\r\n",sys[i].ip,IPPORT_SYSTAT)) // Get list of active users if(!sock.sendto("\r\n",sys[i].ip,IPPORT_SYSTAT)) // Get list of active users
continue; continue;
udp_req++; udp_req++;
...@@ -166,41 +184,37 @@ function list_users(show) ...@@ -166,41 +184,37 @@ function list_users(show)
message=sock.recvfrom(20000); message=sock.recvfrom(20000);
if(message==null) if(message==null)
continue; continue;
i=get_sysnum(message.ip_address); var found = get_system_by_ip(message.ip_address);
if(i==-1) if(!found)
continue; continue;
if(sys[i].udp == false) {
replies++; replies++;
udp_replies++; found.reply=new Date().valueOf()-start.valueOf();
sys[i].udp=true;
sys[i].reply=new Date().valueOf()-start.valueOf();
response=message.data.split("\r\n"); response=message.data.split("\r\n");
if(show) { if(show) {
console.line_counter=0; // defeat pause console.line_counter=0; // defeat pause
printf("\1n\1h%-25.25s\1n ",sys[i].addr); printf("\1n\1h%-25.25s\1n ",found.name);
} }
parse_response(response, show); parse_response(response, show, found);
}
} }
sock.close(); sock.close();
t = new Date().valueOf()-start.valueOf(); t = new Date().valueOf()-start.valueOf();
printf("\1m\1h%lu systems (%lu UDP) and %lu users listed in %d seconds.\r\n" printf("\1m\1h%lu systems and %lu users listed in %d seconds.\r\n"
,replies, udp_replies, users, t/1000); ,replies, users, t/1000);
save_sys_list(); save_sys_list();
} }
function get_sysnum(ip) function get_system_by_ip(ip)
{ {
for(i in sys) for(var i in sys)
if(sys[i].ip==ip) if(sys[i].ip==ip)
return(i); return(sys[i]);
printf("Unexpected response from %s\r\n",ip); printf("Unexpected response from %s\r\n",ip);
return(-1); return null;
} }
function send_msg(dest, msg) function send_msg(dest, msg)
...@@ -221,7 +235,7 @@ function send_msg(dest, msg) ...@@ -221,7 +235,7 @@ function send_msg(dest, msg)
alert("MSP Connection to " + host + " failed with error " + sock.last_error); alert("MSP Connection to " + host + " failed with error " + sock.last_error);
} }
else { else {
sock.send("B"+destuser+"\0"+/* Dest node +*/"\0"+msg+"\0"+user.name+"\0"+"Node: "+bbs.node_num+"\0\0"+system.name+"\0"); sock.send("B"+destuser+"\0"+/* Dest node +*/"\0"+msg+"\0"+user[options.from_user_prop]+"\0"+"Node: "+bbs.node_num+"\0\0"+system.name+"\0");
} }
} while(0); } while(0);
...@@ -307,7 +321,7 @@ while(bbs.online) { ...@@ -307,7 +321,7 @@ while(bbs.online) {
done=false; done=false;
while(bbs.online && !done) { while(bbs.online && !done) {
printf("\r\1n\1h\x11\1n-[\1hQ\1nuit]-\1h\x10 \1y%-25s \1c%s\1>" printf("\r\1n\1h\x11\1n-[\1hQ\1nuit]-\1h\x10 \1y%-25s \1c%s\1>"
,imsg_user[last_user].name,imsg_user[last_user].host); ,imsg_user[last_user].name,imsg_user[last_user].bbs);
switch(console.getkey(K_UPPER|K_NOECHO)) { switch(console.getkey(K_UPPER|K_NOECHO)) {
case '+': case '+':
case '>': case '>':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment