Enabled ANSI and Videotex servers and frames

This commit is contained in:
Deon George
2018-12-09 09:43:18 +11:00
parent 6c91c69bd9
commit 0eb71ef7c6
11 changed files with 429 additions and 243 deletions

View File

@@ -9,17 +9,30 @@ use Sock\{SocketClient,SocketException};
use App\Classes\Frame as FrameClass;
use App\Models\Frame as FrameModel;
use App\Models\Mode;
abstract class Server {
// Size of Bottom Line Pollution
private $blp = 0;
private $mo = NULL; // Our Mode object
protected $blp = 0; // Size of Bottom Line Pollution
public function __construct()
public function __construct(Mode $o)
{
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');
$this->mo = $o;
define('MSG_SENDORNOT', GREEN.'KEY 1 TO SEND, 2 NOT TO SEND');
define('MSG_SENT', GREEN.'MESSAGE SENT - KEY _ TO CONTINUE');
define('MSG_NOTSENT', GREEN.'MESSAGE NOT SENT - KEY _ TO CONTINUE');
define('ERR_DATABASE', RED.'UNAVAILABLE AT PRESENT - PLSE TRY LATER');
define('ERR_NOTSENT', WHITE.'MESSAGE NOT SENT DUE TO AN ERROR');
define('ERR_PRIVATE', WHITE.'PRIVATE PAGE'.GREEN.'- FOR EXPLANATION *37_..');
define('ERR_ROUTE', WHITE.'MISTAKE?'.GREEN.'TRY AGAIN OR TELL US ON *08');
define('ERR_PAGE',ERR_ROUTE);
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');
}
/**
@@ -55,7 +68,7 @@ abstract class Server {
// $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(CLS);
$client->send(CLS.COFF);
// Setup VARS
$timewarp = FALSE; // Is timewarp active.
@@ -151,6 +164,14 @@ abstract class Server {
continue;
case TCP_OPT_WINDOWSIZE:
$session_note .= 'WINDOWSIZE';
$session_init = FALSE;
$read = '';
Log::debug($session_note);
continue;
default:
if ($session_option AND $read) {
$session_term .= $read;
@@ -575,16 +596,18 @@ abstract class Server {
// Look for requested page
case ACTION_GOTO:
// If we wanted a "Searching..." message, this is where to put it.
try {
$fo = $timewarpalt
? new FrameClass(FrameModel::findOrFail($timewarpalt))
: (new FrameModel)->fetch($page['frame'],$page['index']);
? $this->mo->frame(FrameModel::findOrFail($timewarpalt))
: $this->mo->frameLoad($page['frame'],$page['index'],$this);
} catch (ModelNotFoundException $e) {
$this->sendBaseline($client,ERR_PAGE);
$mode = $action = FALSE;
// We initialise $fo anyway
$fo = $this->mo->frame($this->testFrame());
break;
}
@@ -649,6 +672,7 @@ abstract class Server {
case 'i':
$client->send($output);
$mode = $action = false;
break;
// Active Frame. Prestel uses this for a Response Frame.
@@ -684,8 +708,8 @@ abstract class Server {
case 't':
$client->send($output);
$action = ACTION_TERMINATE;
break;
break;
}
break;
@@ -719,7 +743,7 @@ abstract class Server {
$line .= BLUE.$date.' '.$o->note;
$output .= $this->outputPosition(0,$y++).$line.str_repeat(' ',40-$this->strlenv($line));
$output .= $this->outputPosition(0,$y++).$line.str_repeat(' ',40-$this->strlenv($line)); // @todo should use frame::page_length
}
if ($timewarp) {
@@ -750,7 +774,7 @@ abstract class Server {
// Something bad happened. We'll log it and then disconnect.
} catch (\Exception $e) {
Log::emergency($e->getMessage());
Log::emergency($e->getMessage(),['line'=>$e->getLine(),'file'=>$e->getFile()]);
}
$client->close();
@@ -784,16 +808,7 @@ abstract class Server {
* @param $text
* @param bool $reposition
*/
function sendBaseline($client,$text,$reposition=FALSE) {
$client->send(HOME.UP.$text.
($this->blp > $this->strlenv($text)
? str_repeat(' ',$this->blp-$this->strlenv($text)).
($reposition ? HOME.UP.str_repeat(RIGHT,$this->strlenv($text)) : '')
: '')
);
$this->blp = $this->strlenv($text);
}
abstract function sendBaseline($client,$text,$reposition=FALSE);
/**
* Calculate the length of text
@@ -802,9 +817,12 @@ abstract class Server {
*
* @param $text
* @return int
* @todo Implement this as a helper
*/
function strlenv($text):int {
return strlen($text)-substr_count($text,ESC);
}
abstract function strlenv($text):int;
/**
* Return a test frame appropriate for this server.
* @return mixed
*/
abstract public function testFrame();
}