More work on Edit Frame

This commit is contained in:
Deon George 2019-10-02 15:47:56 +10:00
parent bb031b1b82
commit d43d5b71fd
5 changed files with 110 additions and 14 deletions

View File

@ -8,15 +8,14 @@ use App\Classes\Control\Telnet;
abstract class Control abstract class Control
{ {
const prefix = 'App\Classes\Control\';
// Has this control class finished with input // Has this control class finished with input
protected $complete = FALSE; protected $complete = FALSE;
// The server object that is running this control class // The server object that is running this control class
protected $so = NULL; protected $so = NULL;
// The frame applicable for this control (not the current rendered frame, thats in $so)
protected $fo = NULL;
/** /**
* What is the state of the server outside of this control. * What is the state of the server outside of this control.
* Should only contain * Should only contain
@ -27,9 +26,8 @@ abstract class Control
*/ */
public $state = []; public $state = [];
public function __construct(Server $so,Frame $fo=NULL) { public function __construct(Server $so,array $args=[]) {
$this->so = $so; $this->so = $so;
$this->fo = $fo;
// Boot control, preparing anything before keyboard entry // Boot control, preparing anything before keyboard entry
$this->boot(); $this->boot();
@ -48,11 +46,10 @@ abstract class Control
return $this->complete; return $this->complete;
} }
// @todo Change to Dynamic Calls by the existence of files in App\Classes\Control public static function factory(string $name,Server $so,array $args=[]) {
public static function factory(string $name,Server $so,Frame $fo=NULL) {
switch ($name) { switch ($name) {
case 'editframe': case 'editframe':
return new EditFrame($so,$fo); return new EditFrame($so,$args);
case 'register': case 'register':
return new Register($so); return new Register($so);
@ -61,7 +58,12 @@ abstract class Control
return new Telnet($so); return new Telnet($so);
default: default:
throw new \Exception('Unknown control method: '.$name); $c = self::prefix.$name;
$o = class_exists($c) ? new $c($so,$args) : FALSE;
$so->log('debug',sprintf(($o ? 'Executing: %s' : 'Class doesnt exist: %s'),$c));
return $o;
} }
} }

View File

@ -2,8 +2,11 @@
namespace App\Classes\Control; namespace App\Classes\Control;
use Illuminate\Support\Arr;
use App\Classes\Control; use App\Classes\Control;
use App\Classes\Parser\Ansi; use App\Classes\Frame;
use App\Classes\Server;
/** /**
* Class Edit Frame handles frame editing * Class Edit Frame handles frame editing
@ -15,6 +18,19 @@ class EditFrame extends Control
private $x = 1; private $x = 1;
private $y = 1; private $y = 1;
// The frame applicable for this control (not the current rendered frame, thats in $so)
protected $fo = NULL;
public function __construct(Server $so,array $args=[])
{
if (! $args OR ! Arr::get($args,'fo') OR (! $args['fo'] instanceof Frame))
throw new \Exception('Missing frame to Edit');
$this->fo = $args['fo'];
parent::__construct($so);
}
protected function boot() protected function boot()
{ {
// Clear screen and setup edit. // Clear screen and setup edit.

View File

@ -0,0 +1,55 @@
<?php
namespace App\Classes\Control;
use App\Classes\Control;
/**
* Class Test
*
* This is a test class for Control Validation Processing
*
* @package App\Classes\Control
*/
class Test extends Control
{
public function boot()
{
$this->so->co->send(CLS.HOME.DOWN.CON);
$this->so->co->send('Press 1, or 2, or 4, 0 to end.');
}
public function handle(string $read)
{
switch ($read)
{
case 0:
$this->complete = TRUE;
$read = '';
break;
case 1:
$this->so->co->send('You pressed ONE.');
$read = '';
break;
case 2:
$this->so->co->send('You pressed TWO.');
$read = '';
break;
case 3:
$this->so->co->send('You pressed THREE.');
$read = '';
break;
case 4:
$this->so->co->send('You pressed FOUR.');
$read = '';
break;
}
return $read;
}
}

View File

@ -61,6 +61,7 @@ abstract class Frame
const FRAMETYPE_ACTION = 'a'; const FRAMETYPE_ACTION = 'a';
const FRAMETYPE_LOGIN = 'l'; const FRAMETYPE_LOGIN = 'l';
const FRAMETYPE_TERMINATE = 't'; const FRAMETYPE_TERMINATE = 't';
const FRAMETYPE_EXTERNAL = 'x';
// Fields that are editable // Fields that are editable
// @todo This needs rework. // @todo This needs rework.
@ -161,6 +162,11 @@ abstract class Frame
return $this->po->char($x,$y); return $this->po->char($x,$y);
} }
public function content(): string
{
return $this->fo->content;
}
/** /**
* Return fields within the frame. * Return fields within the frame.
*/ */

View File

@ -184,7 +184,6 @@ abstract class Server {
if ($read != '') { if ($read != '') {
if ($read == TCP_IAC) { if ($read == TCP_IAC) {
// If we are not already in a TELNET LOOP // If we are not already in a TELNET LOOP
if ($control !== CONTROL_TELNET) { if ($control !== CONTROL_TELNET) {
$control = CONTROL_TELNET; $control = CONTROL_TELNET;
@ -225,8 +224,6 @@ abstract class Server {
$action = $save->state['action']; $action = $save->state['action'];
$control = FALSE; $control = FALSE;
} }
dump(sprintf('End: Control is now: %s: Method Count: %s',is_object($control) ? get_class($control) : serialize($control),$method->count()));
} }
printf("- End CONTROL: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n", printf("- End CONTROL: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",
@ -446,6 +443,7 @@ abstract class Server {
// List of alternate frames has been presented // List of alternate frames has been presented
case MODE_WARPTO: case MODE_WARPTO:
// @todo If we are in a control, we need to terminate it.
if (is_numeric($read) AND $read) { if (is_numeric($read) AND $read) {
$timewarpalt = $alts->get($read-1)->id; $timewarpalt = $alts->get($read-1)->id;
$action = ACTION_GOTO; $action = ACTION_GOTO;
@ -666,6 +664,7 @@ abstract class Server {
// Clear the command, we are finished processing // Clear the command, we are finished processing
$cmd = ''; $cmd = '';
$mode = FALSE;
break; break;
} }
@ -731,7 +730,7 @@ abstract class Server {
} }
$control = CONTROL_EDIT; $control = CONTROL_EDIT;
$method->push(Control::factory('editframe',$this,$next_fo)); $method->push(Control::factory('editframe',$this,['fo'=>$next_fo]));
$next_fo = NULL; $next_fo = NULL;
$method->last()->state['control'] = $control; $method->last()->state['control'] = $control;
$method->last()->state['action'] = FALSE; $method->last()->state['action'] = FALSE;
@ -930,6 +929,24 @@ abstract class Server {
break; break;
// External Frame - run by a control.
case FRAME::FRAMETYPE_EXTERNAL:
$external = explode(' ',$this->fo->content());
$x = Control::factory(array_shift($external),$this,$external);
if (! $x)
{
$this->sendBaseline($client,ERR_PAGE);
$mode = $action = FALSE;
break;
}
$method->push($x);
$control = CONTROL_METHOD;
$action = FALSE;
break;
// Terminate Frame // Terminate Frame
case Frame::FRAMETYPE_TERMINATE: case Frame::FRAMETYPE_TERMINATE:
$client->send($output); $client->send($output);