Skip to content
Snippets Groups Projects
Commit 83253146 authored by deuce's avatar deuce
Browse files

Add socket/telnet I/O support.

parent 5f70c1ed
No related branches found
No related tags found
No related merge requests found
/*
* Clears the current screen to black and moves to location 1,1
* sets the current attribute to 7
*/
dk.console.remote_io = {
sock:new Socket(true, dk.connection.socket),
clear:function() {
dk.console.attr.value=7;
this.print("\x0c");
},
/*
* Clears to end of line.
* Not available witout ANSI (???)
*/
cleareol:function() {
if(dk.console.ansi)
this.print('\x1b[K');
},
/*
* Moves the cursor to the specified position.
* returns false on error.
* Not available without ANSI
*/
gotoxy:function(x,y) {
if(dk.console.ansi)
this.print(format("\x1b[%u;%uH", y, x));
},
/*
* Writes a string unmodified.
*/
print:function(string) {
this.sock.write(string.replace(/\xff/g, "\xff\xff"));
},
};
if (!dk.console.remote_io.sock.is_connected)
throw("Unable to create socket object");
var input_queue = load(true, "socket_input.js", argv[0], argv[1]);
js.on_exit("input_queue.write(''); input_queue.poll(0x7fffffff);");
js.load_path_list.unshift(js.exec_dir+"/dorkit/");
js.load_path_list.unshift(system.exec_dir+"/dorkit/");
load('ansi_input.js');
var i;
var q = new Queue("dorkit_input");
var k;
var sock=new Socket(true, argv[0]);
if (!sock.is_connected)
throw("Unable to create socket object");
var telnet={
enabled:false,
last:'',
option:'',
interpret:function(ch) {
// TODO: This needs a LOT of work.
if (!this.enabled)
return ch;
if (this.option !== '') {
this.option='';
switch(this.option) {
case '\xfb': // WILL
sock.send('\xff\xfe'+ch); // Send DON'T
break;
case '\xfd': // DO
sock.send('\xff\xfc'+ch); // Send WON'T
break;
}
return '';
}
if (this.last == '\xff') {
this.last = '';
if (ch == '\xff')
return ch;
switch(ch) {
case '\xfb': // WILL
case '\xfd': // DO
this.option=ch;
break;
}
return '';
}
if (this.last == '\r') {
last = '';
if (ch == '\n' || ch == '\x00')
return '\r';
return this.last+ch;
}
switch(ch) {
case '\r':
case '\xff':
last = ch;
return '';
}
return ch;
}
};
if (argc > 1)
telnet.enabled=argv[1];
else
telnet.enabled=false;
while(!js.terminated) {
if (parent_queue.poll(0))
break;
k = undefined;
if (socket_select([sock], 0.1).length == 1) {
k = telnet.interpret(read(1));
}
if (k != undefined && k.length) {
for(i=0; i<k.length; i++)
ai.add(k.substr(i,1));
}
}
......@@ -547,7 +547,9 @@ var dk = {
node:undefined,
dte:undefined,
error_correcting:true,
time:undefined
time:undefined,
socket:undefined,
telnet:false
},
user:{
full_name:undefined,
......@@ -702,10 +704,37 @@ var dk = {
this.user.comment = df[49];
this.user.doors_opened = parseInt(df[50], 10);
this.user.messages_left = parseInt(df[50], 10);
},
parse_cmdline:function(argc, argv) {
var i;
for (i=0; i<argc; i++) {
switch(argv[i]) {
case '-t':
case '-telnet':
this.connection.telnet = true;
break;
case '-s':
case '-socket':
if (i+1 < argc)
this.connection.socket = argv[++i];
break;
case '-l':
case '-local':
this.console.local = true;
this.console.remote = false;
break;
}
}
if (this.connection.telnet === undefined)
this.connection.telnet = false;
}
};
load("local_console.js");
dk.parse_cmdline(argc, argv);
if (dk.connection.socket !== undefined)
dk.system.mode = 'socket';
switch(dk.system.mode) {
case 'sbbs':
......@@ -717,4 +746,7 @@ switch(dk.system.mode) {
case 'jsdoor':
load("jsdoor_console.js");
break;
case 'socket':
load("socket_console.js", dk.connection.socket, dk.connection.telnet);
break;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment