Skip to content
Snippets Groups Projects
Commit 75ede9e9 authored by rswindell's avatar rswindell
Browse files

Don't try to iterate through argv if argc is undefined (e.g. invoked via

load({}, "sbbsimsg.js") with no args).
the sbbsimsg_lib.parse_active_users() will now return a string on failure, so
display appropriately.
parent 729852b7
No related branches found
No related tags found
No related merge requests found
...@@ -42,27 +42,29 @@ var last_user=0; ...@@ -42,27 +42,29 @@ var last_user=0;
lib.read_sys_list(); lib.read_sys_list();
// Parse arguments // Parse arguments
for(i=0; i<argc; i++) { if(this.argc) {
if(argv[i].toLowerCase()=="-l") { for(i=0; i<argc; i++) {
console.clear(); if(argv[i].toLowerCase()=="-l") {
writeln("Inter-BBS Active Users:"); console.clear();
var timeout = 2500; writeln("Inter-BBS Active Users:");
var sent = lib.request_active_users(); var timeout = 2500;
if(parseInt(argv[i+1])) var sent = lib.request_active_users();
timeout = parseInt(argv[i+1]); if(parseInt(argv[i+1]))
function poll_callback(loop) timeout = parseInt(argv[i+1]);
{ function poll_callback(loop)
printf("%c\1[", "/-\\|"[loop%4]); {
if(console.inkey(0)) printf("%c\1[", "/-\\|"[loop%4]);
return true; if(console.inkey(0))
return true;
}
lib.poll_systems(sent, 0.25, timeout, poll_callback);
list_users();
exit();
}
if(argv[i].toLowerCase()=="-d") {
print(lfexpand(JSON.stringify(lib.sys_list, null, 4)));
exit();
} }
lib.poll_systems(sent, 0.25, timeout, poll_callback);
list_users();
exit();
}
if(argv[i].toLowerCase()=="-d") {
print(lfexpand(JSON.stringify(lib.sys_list, null, 4)));
exit();
} }
} }
...@@ -194,6 +196,7 @@ while(bbs.online) { ...@@ -194,6 +196,7 @@ while(bbs.online) {
var key; var key;
var last_request = 0; var last_request = 0;
var request_interval = 60; // seconds var request_interval = 60; // seconds
var valid_keys = "QLTM\rD";
while(bbs.online && !console.aborted) { while(bbs.online && !console.aborted) {
if(time() - last_request >= request_interval) { if(time() - last_request >= request_interval) {
lib.request_active_users(); lib.request_active_users();
...@@ -204,8 +207,8 @@ while(bbs.online) { ...@@ -204,8 +207,8 @@ while(bbs.online) {
var message = lib.receive_active_users(); var message = lib.receive_active_users();
if(message) { if(message) {
var result = lib.parse_active_users(message, logon_callback, logoff_callback); var result = lib.parse_active_users(message, logon_callback, logoff_callback);
if(!result) if(result !== true)
log(LOG_WARNING, "Failure to parse: "+ JSON.stringify(message)); log(LOG_WARNING, format("%s: %s", result, JSON.stringify(message)));
} }
} }
bbs.nodesync(true); bbs.nodesync(true);
...@@ -213,10 +216,14 @@ while(bbs.online) { ...@@ -213,10 +216,14 @@ while(bbs.online) {
continue prompt; continue prompt;
} }
key=console.inkey(K_UPPER, 500); key=console.inkey(K_UPPER, 500);
if(key=='Q' || key=='L' || key=='T' || key=='M' || key=='\r') if(key && valid_keys.indexOf(key) >= 0)
break; break;
} }
switch(key) { switch(key) {
case 'D':
for(var i in lib.sys_list)
print(i + ' = ' + JSON.stringify(lib.sys_list[i]));
break;
case 'L': case 'L':
print("\1h\1cList\r\n"); print("\1h\1cList\r\n");
list_users(); list_users();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment