diff --git a/exec/dorkit/socket_console.js b/exec/dorkit/socket_console.js new file mode 100644 index 0000000000000000000000000000000000000000..9a2327f72d8076cba06f85161a0c2a6fd2d8d62d --- /dev/null +++ b/exec/dorkit/socket_console.js @@ -0,0 +1,43 @@ +/* + * 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);"); diff --git a/exec/dorkit/socket_input.js b/exec/dorkit/socket_input.js new file mode 100644 index 0000000000000000000000000000000000000000..7d995c8767236cb3cdbab25d66418b7ae5eb7861 --- /dev/null +++ b/exec/dorkit/socket_input.js @@ -0,0 +1,74 @@ +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)); + } +} diff --git a/exec/load/dorkit.js b/exec/load/dorkit.js index a3598466cff28187377bb18e741cc9f1d6671223..34f215b4b5c345352588c248c9ae55600762ebe7 100644 --- a/exec/load/dorkit.js +++ b/exec/load/dorkit.js @@ -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; }