diff --git a/exec/dorkit/ansi_input.js b/exec/dorkit/ansi_input.js index e4d5d4063be5e16c816c02346d7d6acb4c5c1216..1f01a8fd6b29b470a1d71ffbe0ee3fb94954d769 100644 --- a/exec/dorkit/ansi_input.js +++ b/exec/dorkit/ansi_input.js @@ -189,5 +189,8 @@ var ai={ this.ansi_started = 0; } return; - } + }, + close:function() { + this.input_queue.write("CONNECTION_CLOSED"); + }, }; diff --git a/exec/dorkit/jsexec_input.js b/exec/dorkit/jsexec_input.js index 7c7abf6ceab1d164f9b856ec2aa40f8fd887cc45..800fd3406d0a97753940673fd54d52dd7ab6ff52 100644 --- a/exec/dorkit/jsexec_input.js +++ b/exec/dorkit/jsexec_input.js @@ -12,3 +12,4 @@ while(!js.terminated) { ai.add(k); } } +ai.close(); diff --git a/exec/dorkit/local_console.js b/exec/dorkit/local_console.js index 788c015b497954935490db29c07c791267f873d6..4f6d194c34b7a99168f36e1df19d8656ed60839c 100644 --- a/exec/dorkit/local_console.js +++ b/exec/dorkit/local_console.js @@ -2,6 +2,7 @@ * Implements the local console using conio */ +var dk_local_console_terminated = false; require('graphic.js', 'Graphic'); if (js.global.conio !== undefined && dk.console.local) { conio.init(); @@ -11,6 +12,12 @@ if (js.global.conio !== undefined && dk.console.local) { dk.console.input_queue_callback.push(function() { 'use strict'; + if (js.terminated !== dk_local_console_terminated) { + dk_local_console_terminated = js.terminated; + return(dk.console.key.CONNECTION_CLOSED); + } + if (dk_local_console_terminated) + return undefined; var ch; if (conio.kbhit) { ch = conio.getch(); @@ -67,6 +74,16 @@ if (js.global.conio !== undefined && dk.console.local) { } return undefined; } + else if (ch == 0xe0) { + if (conio.kbhit) { + ch = conio.getch(); + switch(ch) { + case 0x7e: + return dk.console.key.CONNECTION_CLOSED; + } + } + return undefined; + } return ascii(ch); } diff --git a/exec/dorkit/sbbs_input.js b/exec/dorkit/sbbs_input.js index aa5edca05a7a2716f062b067f171f621cd16e3da..aea5b4e7d5f19e3699b004c0b0312b8719fb3f6e 100644 --- a/exec/dorkit/sbbs_input.js +++ b/exec/dorkit/sbbs_input.js @@ -12,3 +12,4 @@ while(!js.terminated) { k = console.inkey(0, 100); ai.add(k); } +ai.close(); diff --git a/exec/dorkit/socket_input.js b/exec/dorkit/socket_input.js index b7b5ce62dfb50114e7e81454c3697a4731696d73..60a16e3827c1c0309d579043c84ad2352155e767 100644 --- a/exec/dorkit/socket_input.js +++ b/exec/dorkit/socket_input.js @@ -67,6 +67,8 @@ while(!js.terminated) { k = undefined; if (socket_select([sock], 0.1).length == 1) { k = telnet.interpret(sock.read(1)); + if (k === '') + break; } if (k != undefined && k.length) { for(i=0; i<k.length; i++) @@ -75,3 +77,4 @@ while(!js.terminated) { else ai.add(''); } +ai.close(); diff --git a/exec/load/dorkit.js b/exec/load/dorkit.js index c027497632b308f4233025303eb933965aa74549..0fb8a3f7864657a8b2a57a54432f222f4269b36e 100644 --- a/exec/load/dorkit.js +++ b/exec/load/dorkit.js @@ -1,6 +1,7 @@ /*jslint bitwise, this, devel, getset, for*/ // TODO: Auto-pause stuff... +js.auto_terminate = false; js.load_path_list.unshift(js.exec_dir+"dorkit/"); js.on_exit("js.load_path_list.shift()"); if (js.global.system !== undefined) { @@ -130,7 +131,8 @@ var dk = { KEY_ALT_9:'KEY_ALT_9', KEY_ALT_0:'KEY_ALT_0', POSITION_REPORT:'POSITION_REPORT', - UNKNOWN_ANSI:'UNKNOWN_ANSI' + UNKNOWN_ANSI:'UNKNOWN_ANSI', + CONNECTION_CLOSED:'CONNECTION_CLOSED' }, x:1, // Current column (1-based) @@ -471,6 +473,31 @@ var dk = { */ input_queue_callback:[], + Private_connection_close:function() { + dk.connection.active = false; + if (dk.connection.inactive_time === undefined) + dk.connection.inactive_time = system.timer; + js.terminated = true; + }, + + Private_connection_check:function() { + var elapsed; + + if (dk.connection.inactive_time !== undefined) { + elapsed = system.timer - dk.connection.inactive_time; + if (elapsed > dk.connection.disconnect_timeout) + js.auto_terminate = true; + mswait(1); + return true; + } + else if (js.terminated) { + dk.connection.inactive_time = system.timer; + mswait(1); + return true; + } + return false; + }, + /* * Waits up to timeout millisections and returns true if a key * is pressed before the timeout. For ANSI sequences, returns @@ -482,6 +509,8 @@ var dk = { var d; var end = (new Date()).valueOf() + timeout; + if (this.Private_connection_check()) + return true; if (this.keybuf.length > 0) { return true; } @@ -518,9 +547,13 @@ var dk = { var ret; var m; + if (this.Private_connection_check()) + return this.key.CONNECTION_CLOSED; if (this.keybuf.length > 0) { ret = this.keybuf.shift(); - return ret; + if (ret !== this.key.CONNECTION_CLOSED) + return ret; + this.Private_connection_close(); } if (!this.waitkey(0)) { return undefined; @@ -570,10 +603,14 @@ var dk = { 'use strict'; var ret; + if (this.Private_connection_check()) + return undefined; while (1) { if (this.keybuf.length > 0) { do { ret = this.keybuf.shift(); + if (ret === this.key.CONNECTION_CLOSED) + this.Private_connection_close(); } while(ret.length > 1 && ret.indexOf('\x00') === -1); return ret; } @@ -856,7 +893,10 @@ var dk = { error_correcting:true, time:undefined, socket:undefined, - telnet:false + telnet:false, + active:true, + inactive_time:undefined, + disconnect_timeout:30 }, user:{ full_name:undefined, diff --git a/src/conio/ciolib.h b/src/conio/ciolib.h index daf82538024c7e17f42467a46799c4d2f8f84c19..602c14331894f7d650b2e73900d12903d4029fb9 100644 --- a/src/conio/ciolib.h +++ b/src/conio/ciolib.h @@ -698,8 +698,8 @@ CIOLIBEXPORT void CIOLIBCALL mousestate_res(int *x_res, int *y_res, uint8_t *but #define CIO_KEY_ALT_F(x) ((x<11)?((0x67 + x) << 8):((0x80 + x) << 8)) #define CIO_KEY_BACKTAB (0x0f << 8) -#define CIO_KEY_MOUSE 0x7d00 // This is the right mouse on Schneider/Amstrad PC1512 PC keyboards "F-14" -#define CIO_KEY_QUIT 0x7e00 // "F-15" +#define CIO_KEY_MOUSE 0x7dE0 // This is the right mouse on Schneider/Amstrad PC1512 PC keyboards "F-14" +#define CIO_KEY_QUIT 0x7eE0 // "F-15" #define CIO_KEY_ABORTED 0x01E0 // ESC key by scancode #endif /* Do not add anything after this line */