From a9576422ee56bc8e5fcc8f7c6176c5738fa31c53 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 28 Dec 2018 22:57:19 +1100 Subject: [PATCH] Fixed rendering of login page multiple times --- app/Classes/Control/Telnet.php | 1 - app/Classes/Server.php | 27 +++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/Classes/Control/Telnet.php b/app/Classes/Control/Telnet.php index 9c34be3..67a2dd9 100644 --- a/app/Classes/Control/Telnet.php +++ b/app/Classes/Control/Telnet.php @@ -21,7 +21,6 @@ class Telnet extends Control public function handle(string $read) { - $this->state['mode'] = FALSE; $this->so->log('debug',sprintf('Session Char (%s)',ord($read)),['complete'=>$this->complete,'option'=>$this->option]); switch ($read) { diff --git a/app/Classes/Server.php b/app/Classes/Server.php index f33766d..0a8f3a6 100644 --- a/app/Classes/Server.php +++ b/app/Classes/Server.php @@ -120,11 +120,11 @@ abstract class Server { try { $session = NULL; // TCP Session Details - $client->send(TCP_IAC . TCP_DO . TCP_OPT_SUP_GOAHEAD); // DO SUPPRES GO AHEAD - $client->send(TCP_IAC . TCP_WONT . TCP_OPT_LINEMODE); // WONT LINEMODE - $client->send(TCP_IAC . TCP_DO . TCP_OPT_ECHO); // DO ECHO + $client->send(TCP_IAC.TCP_DO.TCP_OPT_SUP_GOAHEAD); // DO SUPPRES GO AHEAD + $client->send(TCP_IAC.TCP_WONT.TCP_OPT_LINEMODE); // WONT LINEMODE + $client->send(TCP_IAC.TCP_DO.TCP_OPT_ECHO); // DO ECHO // $client->send(TCP_IAC.TCP_AYT); // AYT - $client->send(TCP_IAC . TCP_DO . TCP_OPT_TERMTYPE . TCP_IAC . TCP_SB . TCP_OPT_TERMTYPE . TCP_OPT_ECHO . TCP_IAC . TCP_SE); // Request Term Type + $client->send(TCP_IAC.TCP_DO.TCP_OPT_TERMTYPE.TCP_IAC.TCP_SB.TCP_OPT_TERMTYPE.TCP_OPT_ECHO.TCP_IAC.TCP_SE); // Request Term Type $client->send(CLS.COFF); @@ -133,10 +133,10 @@ abstract class Server { $timewarpalt = FALSE; // Alternative timewarp frame to get $history = collect(); // Page history for going backwards $action = ACTION_GOTO; // Initial action. - $cmd = ''; // Current *command being typed in - $mode = FALSE; // Current mode. - $user = new User; // The logged in user $control = FALSE; // Logic in control + $mode = FALSE; // Current mode. + $cmd = ''; // Current *command being typed in + $user = new User; // The logged in user $method = collect(); // Method in control for CONTROL_METHOD $current = []; // Attributes about the current page @@ -157,7 +157,7 @@ abstract class Server { while ($action != ACTION_TERMINATE) { // Read a character from the client session $read = $client->read(1); - printf(". Got: %s (%s)\n",$read,ord($read)); + printf(". Got: %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control); // It appears that read will return '' instead of false when a disconnect has occurred. // We'll set it to NULL so its caught later @@ -214,6 +214,8 @@ abstract class Server { } } + printf("- End Control: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control); + switch ($mode) { // Key presses during field input. case MODE_FIELD: @@ -644,6 +646,8 @@ abstract class Server { } } + printf("- End Mode: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control); + // This section performs some action if it is deemed necessary if ($action) { printf("+ Performing action: %s\n",$action); @@ -792,13 +796,14 @@ abstract class Server { // Standard Frame case Frame::FRAMETYPE_INFO: $client->send($output); - $mode = $action = false; + $mode = $action = FALSE; break; // Login Frame. case Frame::FRAMETYPE_LOGIN: $client->send($output); + $action = FALSE; $output = ''; // If this is the registration page @@ -807,7 +812,7 @@ abstract class Server { $control = CONTROL_METHOD; $method->push(Control::factory('register',$this)); $method->last()->state['control'] = $control; - $method->last()->state['action'] = $action; + $method->last()->state['action'] = FALSE; $method->last()->state['mode'] = MODE_FIELD; } @@ -894,6 +899,8 @@ abstract class Server { break; } + printf("- End Action: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control); + // We need to reposition the cursor to the current field. if ($current['fieldreset'] !== FALSE) { $client->send($this->outputPosition($current['field']->x,$current['field']->y).CON);