Moved registration processing into Frame/Action

This commit is contained in:
Deon George
2019-07-14 22:43:31 +10:00
parent 264747e2f3
commit aa6b2f3244
9 changed files with 316 additions and 217 deletions

View File

@@ -76,21 +76,21 @@ abstract class Server {
define('TCP_OPT_LINEMODE', chr(34));
// Status messages
define('MSG_SENDORNOT', GREEN.'KEY 1 TO SEND, 2 NOT TO SEND');
define('MSG_SENT', GREEN.'MESSAGE SENT - KEY '.HASH.' TO CONTINUE');
define('MSG_NOTSENT', GREEN.'MESSAGE NOT SENT - KEY '.HASH.' TO CONTINUE');
define('MSG_SENDORNOT', GREEN.SPACE.'KEY 1 TO SEND, 2 NOT TO SEND');
define('MSG_SENT', GREEN.SPACE.'MESSAGE SENT - KEY '.HASH.' TO CONTINUE');
define('MSG_NOTSENT', GREEN.SPACE.'MESSAGE NOT SENT - KEY '.HASH.' TO CONTINUE');
define('ERR_DATABASE', RED.'UNAVAILABLE AT PRESENT - PLS TRY LATER');
define('ERR_NOTSENT', WHITE.'MESSAGE NOT SENT DUE TO AN ERROR');
define('ERR_PRIVATE', WHITE.'PRIVATE PAGE'.GREEN.'- FOR EXPLANATION *37'.HASH.'..');
define('ERR_ROUTE', WHITE.'MISTAKE?'.GREEN.'TRY AGAIN OR TELL US ON *08');
define('ERR_DATABASE', RED.SPACE.'UNAVAILABLE AT PRESENT - PLS TRY LATER');
define('ERR_NOTSENT', RED.SPACE.'MESSAGE NOT SENT DUE TO AN ERROR');
define('ERR_PRIVATE', WHITE.SPACE.'PRIVATE PAGE'.GREEN.SPACE.'- FOR EXPLANATION *37'.HASH.'..');
define('ERR_ROUTE', WHITE.SPACE.'MISTAKE?'.GREEN.SPACE.'TRY AGAIN OR TELL US ON *08');
define('ERR_PAGE',ERR_ROUTE);
define('ERR_USER_ALREADYMEMBER', RED.'ALREADY MEMBER OF CUG');
define('ERR_USER_ALREADYMEMBER', RED.SPACE.'ALREADY MEMBER OF CUG');
define('MSG_TIMEWARP_ON', WHITE.'TIMEWARP ON'.GREEN.'VIEW INFO WITH *02');
define('MSG_TIMEWARP_OFF', WHITE.'TIMEWARP OFF'.GREEN.'VIEWING DATE IS FIXED');
define('MSG_TIMEWARP_TO', GREEN.'TIMEWARP TO %s');
define('MSG_TIMEWARP', WHITE.'OTHER VERSIONS EXIST'.GREEN.'KEY *02 TO VIEW');
define('MSG_TIMEWARP_ON', WHITE.SPACE.'TIMEWARP ON'.GREEN.SPACE.'VIEW INFO WITH *02');
define('MSG_TIMEWARP_OFF', WHITE.SPACE.'TIMEWARP OFF'.GREEN.SPACE.'VIEWING DATE IS FIXED');
define('MSG_TIMEWARP_TO', GREEN.SPACE.'TIMEWARP TO %s');
define('MSG_TIMEWARP', WHITE.SPACE.'OTHER VERSIONS EXIST'.GREEN.SPACE.'KEY *02 TO VIEW');
}
/**
@@ -154,13 +154,8 @@ abstract class Server {
$method = collect(); // Method in control for CONTROL_METHOD
$current = []; // Attributes about the current page
// field/fieldnum indexes are for fields on the active page
$current['fieldreset'] = FALSE; // Flag to reset position (used in fields)
$current['fieldpos'] = 0; // For current field, position within.
$current['prevmode'] = FALSE; // Previous mode - in case we need to go back to MODE_FIELD
$fielddata = [];
// @todo Get the login/start page, and if it is not available, throw the ERR_DATEBASE error.
if (isset($config['loginpage'])) {
$next_page = ['frame'=>$config['loginpage']];
@@ -202,7 +197,7 @@ abstract class Server {
}
}
if ($control AND $method->count()) {
if ($mode != MODE_BL AND $control AND $method->count()) {
printf("= Start CONTROL: Going to method: %s\n",get_class($method->last()));
// Capture our state when we enter this method.
@@ -257,7 +252,7 @@ abstract class Server {
// If we are the main login screen, see if it is a new user
if ($this->fo->isCUG(0))
{
if ($current['field']->type == 't' AND array_get($fielddata,$current['fieldnum']) == 'NEW')
if ($this->fo->getField()->type == 't' AND $this->fo->getFieldCurrentInput() == 'NEW')
{
$action = ACTION_GOTO;
$next_page = ['frame'=>'981']; // @todo This should be in the DB.
@@ -273,28 +268,17 @@ abstract class Server {
case Frame::FRAMETYPE_ACTION:
switch ($read) {
// End of field entry.
case LF:
case CR:
case HASH:
// Next Field
$current['fieldnum']++;
$current['fieldpos'] = 0;
$this->fo->setFieldNext();
if ($current['fieldnum'] < $this->fo->fields()->count()) {
$current['fieldnum'] = $this->fo->getFieldId('edit',$current['fieldnum']);
if ($current['fieldnum'] !== FALSE) {
$current['field'] = $this->fo->getField($current['fieldnum']);
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
$mode = MODE_FIELD;
// There were no (more) editable fields.
} else {
$action = ACTION_SUBMITRF;
}
if ($x=$this->fo->getField()) {
$client->send($this->moveCursor($x->x,$x->y).CON);
$mode = MODE_FIELD;
// Finished all editable fields.
} else {
// Finished all editable fields.
$action = ACTION_SUBMITRF;
}
@@ -303,63 +287,12 @@ abstract class Server {
case STAR:
$current['prevmode'] = MODE_FIELD;
$action = ACTION_STAR;
$current['fieldpos'] = 0;
$fielddata[$current['fieldnum']] = '';
$current['fielddata'][$current['fieldnum']] = '';
break;
case KEY_DELETE:
if ($current['fieldpos'])
{
$current['fieldpos']--;
if ($this->fo->setFieldCurrentInputDelete())
$client->send(LEFT.$this->fo::$if_filler.LEFT);
$fielddata[$current['fieldnum']] = substr($fielddata[$current['fieldnum']],0,-1);
$current['fielddata'][$current['fieldnum']] = substr($current['fielddata'][$current['fieldnum']],0,-1);
}
break;
case KEY_LEFT:
if ($current['fieldpos']) {
$current['fieldpos']--;
$client->send(LEFT);
}
break;
case KEY_RIGHT:
if ($current['fieldpos']++ < $current['field']->length)
$client->send(RIGHT);
break;
case KEY_DOWN:
if ($current['fieldpos'] + 40 < $current['field']->length) {
$client->send(DOWN);
$current['fieldpos'] = $current['fieldpos'] + 40;
};
break;
case KEY_UP:
if ($current['fieldpos'] - 40 >= 0) {
$client->send($read);
$current['fieldpos'] = $current['fieldpos'] - 40;
};
break;
case CR:
// On second or later line of a field
if ($current['fieldpos'] + $current['field']->x > 40) {
$client->send($read);
$current['fieldpos'] = (($current['fieldpos'] + $current['field']->x) % 40) * 40;
} else {
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
$current['fieldpos'] = 0;
}
break;
@@ -368,18 +301,10 @@ abstract class Server {
// Record Data Entry
default:
if (ord($read) > 31 && $current['fieldpos'] < $current['field']->length) {
if (! array_key_exists($current['fieldnum'],$current['fielddata'])) {
$current['fielddata'][$current['fieldnum']] = '';
$fielddata[$current['fieldnum']] = '';
}
if (ord($read) > 31 && strlen($this->fo->getFieldCurrentInput()) < $this->fo->getField()->length) {
$this->fo->setFieldCurrentInput($read);
$fielddata[$current['fieldnum']]{$current['fieldpos']} = $read; // @todo delete
$current['fielddata'][$current['fieldnum']]{$current['fieldpos']} = $read;
$current['fieldpos']++;
$client->send($this->fo->isFieldMasked($current['field']->type) ?: $read);
$client->send($this->fo->isFieldCurrentMask() ?: $read);
}
}
@@ -407,7 +332,7 @@ abstract class Server {
$mode = MODE_RFSENT;
} elseif ($ao = FrameClass\Action::factory($this->fo->route(1),$this,$user,$action,$mode)) {
$ao->handle($fielddata);
$ao->handle();
$mode = $ao->mode;
$action = $ao->action;
@@ -430,6 +355,7 @@ abstract class Server {
break;
case '2':
// @todo Check if HASH is a valid next destination
$this->sendBaseline($client,MSG_NOTSENT);
$mode = MODE_RFNOTSENT;
@@ -601,7 +527,6 @@ abstract class Server {
}
// Toggle Timewarp Mode
// @todo in forms, the cursor is in the wrong location for ANSI
if ($cmd === '01') {
$client->send(COFF);
$timewarp = !$timewarp;
@@ -609,11 +534,20 @@ abstract class Server {
$cmd = '';
$action = $mode = FALSE;
if ($current['prevmode'] == MODE_FIELD) {
$mode = $current['prevmode'];
$current['prevmode'] = FALSE;
if ($x=$this->fo->getField()) {
// @todo This WHITE should be removed, and the color set to whatever is in the frame
$client->send($this->moveCursor($x->x+strlen($this->fo->getFieldCurrentInput()),$x->y).CON.WHITE);
}
}
break;
}
// Present Timewarp Frames
// @todo in forms, the cursor is in the wrong location for ANSI
if ($cmd === '02') {
$client->send(COFF);
$action = ACTION_INFO;
@@ -671,10 +605,16 @@ abstract class Server {
$mode = $current['prevmode'];
$current['prevmode'] = FALSE;
// @todo The cursor color could be wrong
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
$client->send(str_repeat($this->fo::$if_filler,$current['field']->length));
$current['fieldreset'] = TRUE;
if (! $this->fo->getField())
$this->fo->setFieldPrev();
if ($x=$this->fo->getField()) {
// @todo This WHITE should be removed, and the color set to whatever is in the frame
$client->send($this->moveCursor($x->x,$x->y).CON.WHITE);
$client->send(str_repeat($this->fo::$if_filler,$x->length));
$client->send($this->moveCursor($x->x,$x->y));
$this->fo->resetCurrentFieldData();
}
} else {
$mode = FALSE;
@@ -696,7 +636,10 @@ abstract class Server {
// Our method count should be zero
if ($method->count())
dd($method);
{
dump($method);
throw new \Exception('Method count should be zero, but its not...',500);
}
}
// Nothing typed between * and #
@@ -829,8 +772,10 @@ abstract class Server {
// We need this extra test in case we come from ACTION_BACKUP
if ($action == ACTION_NEXT)
{
$current['page']['index'] = $this->fo->index();
$next_page = ['frame'=>$this->fo->frame(),'index'=>$this->fo->index_next()];
$next_page = [
'frame'=>$this->fo->frame(),
'index'=>$this->fo->index_next()
];
}
// Look for requested page - charge for it to be loaded.
@@ -917,7 +862,6 @@ abstract class Server {
$history->push($next_page);
}
$current['fieldpos'] = 0;
$this->fo = $fo;
$fo = NULL;
$next_page = NULL;
@@ -965,27 +909,21 @@ abstract class Server {
// Active Frame. Prestel uses this for a Response Frame.
case Frame::FRAMETYPE_ACTION:
$client->send($output);
// holds data entered by user.
$fielddata = [];
$current['fielddata'] = [];
if ($this->fo->fields()->count()) {
// Get our first editable field.
$current['fieldnum'] = $this->fo->getFieldId('edit',0);
$current['field'] = $this->fo->getField($current['fieldnum']);
$current['fieldreset'] = TRUE;
$this->fo->resetCurrentField();
if ($current['fieldnum'] !== FALSE) {
if ($x=$this->fo->getField()) {
$mode = MODE_FIELD;
// @todo This WHITE should be removed, and the color set to whatever is in the frame
$client->send($this->moveCursor($x->x,$x->y).CON.WHITE);
// There were no editable fields.
// There were no editable fields.
} else {
$mode = MODE_COMPLETE;
$client->send(COFF);
}
$current['fieldpos'] = 0;
} else {
$mode = FALSE;
}
@@ -1018,7 +956,7 @@ abstract class Server {
if (count($alts)) {
$n = 1;
$output .= $this->moveCursor(0,$y++).WHITE.NEWBG.RED.'ALTERNATIVE VERSIONS:'.str_repeat(' ',16);
$output .= $this->moveCursor(0,$y++).WHITE.SPACE.NEWBG.RED.'ALTERNATIVE VERSIONS:'.str_repeat(' ',16);
foreach ($alts as $o) {
$date = $o->created_at->format('d M Y');
@@ -1026,10 +964,10 @@ abstract class Server {
$line = WHITE.NEWBG;
if ($timewarp) {
$line .= RED.$n++;
$line .= RED.SPACE.$n++;
}
$line .= BLUE.$date.' '.$o->note;
$line .= BLUE.SPACE.$date.' '.$o->note;
$output .= $this->moveCursor(0,$y++).$line.str_repeat(' ',40-$this->fo->strlenv($line)); // @todo should use frame::page_length
}
@@ -1052,12 +990,6 @@ abstract class Server {
serialize($action),
$control);
// We need to reposition the cursor to the current field.
if ($current['fieldreset'] !== FALSE) {
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
$current['fieldreset'] = FALSE;
}
// Did the client disconnect
if ($read === NULL || socket_last_error()) {
$client->close();