Created frames table with migration

This commit is contained in:
Deon George 2018-12-03 23:59:22 +11:00
parent 4504818e25
commit 3651a6508a
11 changed files with 1049 additions and 732 deletions

View File

@ -56,7 +56,7 @@ class Frame
if (! $this->hasFlag('ip')) {
// Set the page header: CUG/Site Name | Page # | Cost
$this->output .= $this->render_header($this->header).
$this->render_page($this->frame->frame_id,$this->frame->subframe_id).
$this->render_page($this->frame->frame,$this->frame->index).
$this->render_cost($this->frame->cost);
}
@ -93,14 +93,14 @@ class Frame
for ($x=0;$x<$this->frame_width;$x++)
{
$posn = $y*40+$x;
$byte = ord(isset($this->frame->frame_content{$posn}) ? $this->frame->frame_content{$posn} : ' ')%128;
$byte = ord(isset($this->frame->content{$posn}) ? $this->frame->content{$posn} : ' ')%128;
// dump(sprintf('Y: %s,X: %s, POSN: %s, BYTE: %s',$y,$x,$posn,$byte));
// Check for start-of-field
if ($byte == ord(ESC)) { // Esc designates start of field (Esc-K is end of edit)
$infield = TRUE;
$fieldlength = 0;
$fieldtype = ord(substr($this->frame->frame_content,$posn+1,1))%128;
$fieldtype = ord(substr($this->frame->content,$posn+1,1))%128;
$byte = ord(' '); // Replace ESC with space.
} else {
@ -132,7 +132,7 @@ class Frame
// Replace field with Date
if ($field == '%date') {
if ($fieldlength == 1)
$datetime = strtoupper(date('D d M Y H:i:s'));
$datetime = date('D d M H:ia');
if ($fieldlength <= strlen($datetime))
$byte = ord($datetime{$fieldlength-1});
@ -168,7 +168,7 @@ class Frame
}
// truncate end of lines
if (isset($pageflags['tru']) && substr($this->frame->frame_content,$y*40+$x,40-$x) === str_repeat(' ',40-$x)) {
if (isset($pageflags['tru']) && substr($this->frame->content,$posn,40-$x) === str_repeat(' ',40-$x)) {
$this->output .= CR . LF;
break;
}
@ -183,7 +183,7 @@ class Frame
*/
public function framenum()
{
return $this->frame->frame_id.$this->frame->subframe_id;
return $this->frame->frame.$this->frame->index;
}
/**
@ -253,6 +253,17 @@ class Frame
return sprintf(WHITE.'% '.$this->pagenum_length.'.0f%s',$num,$frame);
}
/**
* Get the route for the key press
*
* @param string $read
*/
public function route(string $read)
{
// @todo
return FALSE;
}
/**
* Calculate the length of text
*
@ -270,21 +281,21 @@ class Frame
// Simulate a DB load
$o = new \App\Models\Frame;
$o->frame_content = '';
$o->content = '';
$o->flags = ['ip'];
$o->frametype = 'a';
$o->frame_id = 999;
$o->subframe_id = 'a';
$o->type = 'a';
$o->frame = 999;
$o->index = 'a';
// Header
$o->frame_content .= substr(R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T-12345678901234567890',0,20).
$o->content .= substr(R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T-12345678901234567890',0,20).
R_WHITE.'999999999a'.R_RED.sprintf('%07.0f',999).'u';
$o->frame_content .= str_repeat('+-',18).' '.R_RED.'01';
$o->frame_content .= 'Date: '.ESC.str_repeat('d',25).str_repeat('+-',4);
$o->frame_content .= 'Name: '.ESC.str_repeat('u',5).str_repeat('+-',14);
$o->frame_content .= 'Address: '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
$o->frame_content .= ' : '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
$o->content .= str_repeat('+-',18).' '.R_RED.'01';
$o->content .= 'Date: '.ESC.str_repeat('d',25).str_repeat('+-',4);
$o->content .= 'Name: '.ESC.str_repeat('u',5).str_repeat('+-',14);
$o->content .= 'Address: '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
$o->content .= ' : '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
return $o;
}

View File

@ -0,0 +1,61 @@
<?php
namespace App\Console\Commands;
use App\Models\Frame;
use Illuminate\Console\Command;
class FrameDelete extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'frame:delete {frame} {index}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete frames from the database.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
*/
public function handle()
{
if (! is_numeric($this->argument('frame')))
throw new \Exception('Frame is not numeric: '.$this->argument('frame'));
if (strlen($this->argument('index')) != 1 OR ! preg_match('/^[a-z]$/',$this->argument('index')))
throw new \Exception('Subframe failed validation');
try {
$o = Frame::where('frame',$this->argument('frame'))
->where('index',$this->argument('index'))
->firstOrFail();
} catch (ModelNotFoundException $e) {
$this->error('Page not found to delete: '.$this->argument('frame').$this->argument('index'));
die(1);
}
$o->delete();
$this->info('Page deleted: '.$this->argument('frame').$this->argument('index'));
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace App\Console\Commands;
use App\Models\Frame;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class FrameImport extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'frame:import {frame} {index} {file} '.
'{--cost=0 : Frame Cost }'.
'{--mode=1 : Frame Emulation Mode }'.
'{--replace : Replace existing frame}'.
'{--type=i : Frame Type}'.
'{--trim : Trim off header (first 40 chars)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import frames into the database. The frames should be in binary format.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
*/
public function handle()
{
if (! is_numeric($this->argument('frame')))
throw new \Exception('Frame is not numeric: '.$this->argument('frame'));
if (strlen($this->argument('index')) != 1 OR ! preg_match('/^[a-z]$/',$this->argument('index')))
throw new \Exception('Subframe failed validation');
if (! file_exists($this->argument('file')))
throw new \Exception('File not found: '.$this->argument('file'));
$o = new Frame;
if ($this->option('replace')) {
try {
$o = $o->where('frame',$this->argument('frame'))
->where('index',$this->argument('index'))
->firstOrFail();
} catch (ModelNotFoundException $e) {
$this->error('Page not found to replace: '.$this->argument('frame').$this->argument('index'));
die(1);
}
} else {
$o->frame = $this->argument('frame');
$o->index = $this->argument('index');
}
$o->content = ($this->option('trim'))
? substr(file_get_contents($this->argument('file')),40)
: file_get_contents($this->argument('file'));
$o->cost = $this->option('cost');
$o->mode_id = $this->option('mode');
$o->type = $this->option('type');
$o->save();
}
}

View File

@ -79,6 +79,8 @@ class Server extends Command
/**
* Connection handler
*
* @todo: Pressing * three times gets "Shouldnt get here".
*/
function onConnect(SocketClient $client) {
Log::info('Connection from: ',['client'=>$client->getAddress()]);
@ -97,29 +99,27 @@ class Server extends Command
return;
// We are now the child.
// @todo Need to intercept any crashes and close the TCP port.
try {
$session_init = $session_option = FALSE;
$session_note = ''; // TCP Session Notice
$session_term = ''; // TCP Terminal Type
$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);
$read = '';
// @todo Deprecate and have an exception handler handle this.
// like throw new FatalClientException(CLS.UP.ERR_DATABASE,500,NULL,$client);
// @todo Get the login page, and if it is not available, throw the ERR_DATEBASE error.
// @todo Get the login/start page, and if it is not available, throw the ERR_DATEBASE error.
$db = new \vvdb();
// Connect to database. Returns error message if unable to connect.
$r = $db->connect($config['dbserver'],$config['database'],$config['dbuser'], $config['dbpass']);
$r = $db->connect($config['dbserver'], $config['database'], $config['dbuser'], $config['dbpass']);
/*
if (!empty($r)) {
http_response_code(500);
@ -129,19 +129,19 @@ class Server extends Command
*/
// $user will eventually contain validated user details.
$user = array( 'systel' => '019990001',
$user = array('systel' => '019990001',
'username' => 'DEMONSTRATION DATA USER',
'address1' => '8 HERBAL HILL',
'address2' => 'LONDON',
'address3' => 'EC1R 5EJ',
'address4' => '',
'address5' => '',
'CUGS' => array( 7800, 15500), // Closed User Groups this user has access to
'CUGS' => array(7800, 15500), // Closed User Groups this user has access to
);
$history = array(); // backup history
$cmd = ''; // current *command being typed in
$cmd = ''; // Current *command being typed in
$mode = false; // input mode.
$prevmode = false; // previous mode
$timewarp = false;
@ -153,7 +153,7 @@ class Server extends Command
$page = $service['start_page'];
$subpage = 'a';
} else {
$page = '999'; // next page
$page = '98'; // next page
$subpage = 'a';
}
$curpage = ''; // current page
@ -163,7 +163,7 @@ class Server extends Command
$blp = 0; // botton line polluted (by this no. of characters)
$resetpsn = false; // flag to reset position (used in fields)
if (! isset($config['varient_id']))
if (!isset($config['varient_id']))
$config['varient_id'] = NULL;
$service = $db->getServiceById($config['service_id']);
//dd($service);
@ -175,26 +175,25 @@ class Server extends Command
$matches = array();
if (preg_match('@'.$service['page_format'].'@',$service['start_frame'],$matches)) {
if (preg_match('@' . $service['page_format'] . '@', $service['start_frame'], $matches)) {
$page = $matches[1];
$subpage = $matches[2];
echo " Using start page ".$page.$subpage."\n";
echo " Using start page " . $page . $subpage . "\n";
}
// $start = $service['start_frame'];
// where to start from
while( $action != ACTION_TERMINATE ) {
while ($action != ACTION_TERMINATE) {
// Read a character from the client session
$read = $client->read(1);
if ($read != '') {
dump(sprintf('Mode: [%s] CMD: [%s] frame: [%s] Received [%s (%s)]',$mode,$cmd,$page,$read,ord($read)));
dump(sprintf('Mode: [%s] CMD: [%s] frame: [%s] Received [%s (%s)]', $mode, $cmd, $page, $read, ord($read)));
// Client initiation input
// TELNET http://pcmicro.com/netfoss/telnet.html
if ($read == TCP_IAC OR $session_init OR $session_option)
{
Log::debug(sprintf('Session Char (%s)',ord($read)),['init'=>$session_init,'option'=>$session_option]);
if ($read == TCP_IAC OR $session_init OR $session_option) {
Log::debug(sprintf('Session Char (%s)', ord($read)), ['init' => $session_init, 'option' => $session_option]);
switch ($read) {
// Command being sent.
@ -211,7 +210,7 @@ class Server extends Command
case TCP_SE:
$session_option = $session_init = FALSE;
Log::debug('Session Terminal: '.$session_term);
Log::debug('Session Terminal: ' . $session_term);
break;
@ -256,12 +255,12 @@ class Server extends Command
$read = '';
} else {
Log::debug(sprintf('Unhandled char in session_init :%s (%s)',$read,ord($read)));
Log::debug(sprintf('Unhandled char in session_init :%s (%s)', $read, ord($read)));
}
}
}
switch($mode){
switch ($mode) {
// Key presses during field input.
case MODE_FIELD:
//dump(sprintf('** Processing Keypress in MODE_FIELD [%s (%s)]. Last POS [%s]',$read,ord($read),$curfp));
@ -289,7 +288,7 @@ class Server extends Command
}
if ($curfield !== false) {
$client->send(outputPosition($fields[$curfield]['x'],$fields[$curfield]['y']).CON);
$client->send(outputPosition($fields[$curfield]['x'], $fields[$curfield]['y']) . CON);
$mode = MODE_FIELD;
$fielddate[$curfield] = '';
@ -340,15 +339,15 @@ class Server extends Command
case CR:
if ($curfp + $fields[$curfield]['x'] > 40) { // on second or later line of a field
$client->send($read);
$curfp = (($curfp + $fields[$curfield]['x'])%40)*40;
$curfp = (($curfp + $fields[$curfield]['x']) % 40) * 40;
} else {
$client->send(outputPosition($fields[$curfield]['x'],$fields[$curfield]['y']).CON);
$client->send(outputPosition($fields[$curfield]['x'], $fields[$curfield]['y']) . CON);
$curfp = 0;
}
break;
case ESC:
break; ;
break;;
// Record Data Entry
default:
@ -363,7 +362,8 @@ class Server extends Command
// Other Frame Types - Shouldnt get here.
default:
throw new \Exception('Shouldnt get here',500);
$client->close();
throw new \Exception('Shouldnt get here', 500);
} // switch frame types
@ -371,11 +371,11 @@ class Server extends Command
// Form submission: 1 to send, 2 not to send.
case MODE_SUBMITRF:
switch($read){
switch ($read) {
// @todo Input received, process it.
case '1':
dump(['s'=>$service,'f'=>$fielddata]);
if(TRUE) {
dump(['s' => $service, 'f' => $fielddata]);
if (TRUE) {
sendBaseline($client, $blp, MSG_SENT);
$mode = MODE_RFSENT;
} else {
@ -407,10 +407,10 @@ class Server extends Command
$page = $pagedata['route1'];
$subpage = 'a';
} else if ($r = $db->getFrame($service['service_id'],$varient['varient_id'],$page,chr(1+ord($subpage)))) {
} else if ($r = $db->getFrame($service['service_id'], $varient['varient_id'], $page, chr(1 + ord($subpage)))) {
$action = ACTION_GOTO;
$page = $curpage;
$subpage = chr(1+ord($subpage));
$subpage = chr(1 + ord($subpage));
} else if (!empty($pagedata['route0'])) {
$action = ACTION_GOTO;
@ -446,10 +446,10 @@ class Server extends Command
$page = $pagedata['route2'];
$subpage = 'a';
} else if ($r = $db->getFrame($service['service_id'],$varient['varient_id'],$page,chr(1+ord($subpage)))) {
} else if ($r = $db->getFrame($service['service_id'], $varient['varient_id'], $page, chr(1 + ord($subpage)))) {
$action = ACTION_GOTO;
$page = $curpage;
$subpage = chr(1+ord($subpage));
$subpage = chr(1 + ord($subpage));
} else if (!empty($pagedata['route0'])) {
$action = ACTION_GOTO;
@ -476,7 +476,7 @@ class Server extends Command
*/
case MODE_WARPTO: // expecting a timewarp selection
if (isset($alts[$read - 1 ])) {
if (isset($alts[$read - 1])) {
$v = $db->getAllVarients($config['service_id'], $alts[$read - 1]['varient_id']);
if (!empty($v)) {
$varient = reset($v);
@ -492,7 +492,7 @@ class Server extends Command
// Not doing anything in particular.
case FALSE:
$cmd = '';
Log::debug('Idle',['pid'=>'TBA']);
Log::debug('Idle', ['pid' => $childpid]);
switch ($read) {
case HASH:
@ -514,17 +514,15 @@ class Server extends Command
case '7':
case '8':
case '9':
if (isset($pagedata['route' . $read]) && $pagedata['route' . $read] != '*') {
if ($frame = $fo->route($read)) {
$action = ACTION_GOTO;
$page = $pagedata['route' . $read];
$subpage = 'a';
break;
} else {
sendBaseline($client, $blp, ERR_ROUTE);
$mode = $action = false;
$mode = $action = FALSE;
}
break;
break;
}
break;
@ -536,7 +534,7 @@ class Server extends Command
case MODE_BL: // entering a baseline command
echo "was waiting for page number\n";
// if it's a number, continue entry
if (strpos('0123456789',$read) !== false) { // numeric
if (strpos('0123456789', $read) !== false) { // numeric
$cmd .= $read;
$client->send($read);
$blp++;
@ -565,7 +563,7 @@ class Server extends Command
$client->send(COFF);
$timewarp = !$timewarp;
sendBaseline($client, $blp,
( $timewarp ? MSG_TIMEWARP_ON : MSG_TIMEWARP_OFF));
($timewarp ? MSG_TIMEWARP_ON : MSG_TIMEWARP_OFF));
$cmd = '';
$action = $mode = false;
}
@ -578,8 +576,8 @@ class Server extends Command
if ($prevmode == MODE_FIELD) {
$mode = $prevmode;
$prevmode = false;
$client->send(outputPosition($fields[$curfield]['x'],$fields[$curfield]['y']).CON);
$client->send(str_repeat(' ',$fields[$curfield]['length']));
$client->send(outputPosition($fields[$curfield]['x'], $fields[$curfield]['y']) . CON);
$client->send(str_repeat(' ', $fields[$curfield]['length']));
// tood reset stored entered text
$resetpsn = $curfield;
} else {
@ -614,7 +612,7 @@ class Server extends Command
if ($action) {
echo "Performing action $action\n";
}
switch($action){
switch ($action) {
case ACTION_STAR:
echo " star command started\n";
sendBaseline($client, $blp, GREEN . '*', true);
@ -624,7 +622,6 @@ class Server extends Command
break;
case ACTION_SUBMITRF:
$action = false;
sendBaseline($client, $bpl, MSG_SENDORNOT);
@ -632,8 +629,6 @@ class Server extends Command
break;
case ACTION_BACKUP:
// do we have anywhere to go?
if (count($history) > 1) { // because current page should always be in there.
@ -645,7 +640,7 @@ class Server extends Command
case ACTION_NEXT:
if ($action == ACTION_NEXT) {
$cursub = $subpage;
$subpage = chr(ord($subpage)+1);
$subpage = chr(ord($subpage) + 1);
}
case ACTION_GOTO:
// $client->send(HOME . UP . GREEN . "Searching for page $page");
@ -653,10 +648,10 @@ class Server extends Command
// look for requested page
try {
$fo = (new \App\Models\Frame)->fetch($page,$subpage);
$fo = (new \App\Models\Frame)->fetch($page, $subpage);
} catch (ModelNotFoundException $e) {
Log::debug(sprintf('Frame: %s%s NOT found',$page,$subpage));
Log::debug(sprintf('Frame: %s%s NOT found', $page, $subpage));
if ($action == ACTION_NEXT) {
$subpage = $cursub; // Put subpage back as it was
}
@ -666,7 +661,7 @@ class Server extends Command
break;
}
dump(['m'=>__METHOD__,'service'=>$service['service_id'],'varient'=>$varient['varient_id'],'frame'=>$fo->framenum(),'type'=>$fo->type()]);
dump(['m' => __METHOD__, 'service' => $service['service_id'], 'varient' => $varient['varient_id'], 'frame' => $fo->framenum(), 'type' => $fo->type()]);
// validate if we have access top it
/* if (isset($m['access']) && $m['access'] == 'n') {
@ -684,9 +679,9 @@ class Server extends Command
// we have access...
if ($r['varient_id'] != $varient['varient_id']) {
if (empty($v['varient_date'])) {
sendBaseline($client, $blp, sprintf(MSG_TIMEWARP_TO, 'unknown date') );
sendBaseline($client, $blp, sprintf(MSG_TIMEWARP_TO, 'unknown date'));
} else {
sendBaseline($client, $blp, sprintf(MSG_TIMEWARP_TO,date('j f Y',strtotime($v['varient_date']))) );
sendBaseline($client, $blp, sprintf(MSG_TIMEWARP_TO, date('j f Y', strtotime($v['varient_date']))));
}
$varient = array_merge($varient, array_intersect_key($r, $varient));
}
@ -701,7 +696,7 @@ class Server extends Command
$pageflags = [];
if ($action == ACTION_GOTO || $action == ACTION_NEXT) { // only if new location, not going backwards
$history[] = array($page,$subpage);
$history[] = array($page, $subpage);
}
// drop into
@ -716,11 +711,11 @@ class Server extends Command
*/
// print_r($pageflags); print_r($pagedata);
switch($fo->type()){
switch ($fo->type()) {
default:
case 'i': // standard frame
if ($timewarp && 1 < count(
$alts = $db->getAlternateFrames($service['service_id'],$varient['varient_id'],$curpage,$cursub)
$alts = $db->getAlternateFrames($service['service_id'], $varient['varient_id'], $curpage, $cursub)
)) {
$msg = MSG_TIMEWARP;
} else {
@ -735,7 +730,6 @@ class Server extends Command
break;
case 'a': // active frame. Prestel uses this for Response Framea.
/*
if ($timewarp && 1 < count(
$alts = $db->getAlternateFrames($service['service_id'],$varient['varient_id'],$curpage,$cursub)
@ -805,24 +799,22 @@ class Server extends Command
break;
case ACTION_INFO: // special emulator command
$mode = false;
$cmd='';
$cmd = '';
$action = false;
$output = outputPosition(0,0) . WHITE . NEWBG . RED . 'TIMEWARP INFO FOR Pg.' . BLUE . $curpage . $cursub . WHITE;
$output .= outputPosition(0,1) . WHITE . NEWBG . BLUE . 'Service : ' . substr($service['service_name'] . str_repeat(' ',27),0,27) ;
$output .= outputPosition(0,2) . WHITE . NEWBG . BLUE . 'Varient : ' . substr($varient['varient_name'] . str_repeat(' ',27),0,27) ;
$output .= outputPosition(0,3) . WHITE . NEWBG . BLUE . 'Dated : ' . substr(date('j F Y',strtotime($varient['varient_date'])) . str_repeat(' ',27),0,27);
$output = outputPosition(0, 0) . WHITE . NEWBG . RED . 'TIMEWARP INFO FOR Pg.' . BLUE . $curpage . $cursub . WHITE;
$output .= outputPosition(0, 1) . WHITE . NEWBG . BLUE . 'Service : ' . substr($service['service_name'] . str_repeat(' ', 27), 0, 27);
$output .= outputPosition(0, 2) . WHITE . NEWBG . BLUE . 'Varient : ' . substr($varient['varient_name'] . str_repeat(' ', 27), 0, 27);
$output .= outputPosition(0, 3) . WHITE . NEWBG . BLUE . 'Dated : ' . substr(date('j F Y', strtotime($varient['varient_date'])) . str_repeat(' ', 27), 0, 27);
$alts = $db->getAlternateFrames($service['service_id'],$varient['varient_id'],$curpage,$cursub);
$alts = $db->getAlternateFrames($service['service_id'], $varient['varient_id'], $curpage, $cursub);
if (count($alts) > 1) {
$n = 1;
$output .= outputPosition(0,4) . WHITE . NEWBG . RED . 'ALTERNATIVE VERSIONS:' . str_repeat(' ',16);
$output .= outputPosition(0, 4) . WHITE . NEWBG . RED . 'ALTERNATIVE VERSIONS:' . str_repeat(' ', 16);
$y = 5;
foreach ($alts as $ss){
foreach ($alts as $ss) {
// if (is_numeric($ss['varient_date'])) {
$date = date('d M Y', strtotime($ss['varient_date']));
// } else {
@ -835,7 +827,7 @@ class Server extends Command
$line .= BLUE . $date . ' ' . $ss['varient_name'];
$output .= outputPosition(0,$y) . $line . str_repeat(' ',40-strlenv($line));
$output .= outputPosition(0, $y) . $line . str_repeat(' ', 40 - strlenv($line));
$y++;
$n++;
@ -853,17 +845,23 @@ class Server extends Command
} // switch $action
if ($resetpsn !== false && isset($fields[$resetpsn])) {
$client->send(outputPosition($fields[$resetpsn]['x'],$fields[$resetpsn]['y']).CON);
$client->send(outputPosition($fields[$resetpsn]['x'], $fields[$resetpsn]['y']) . CON);
$resetpsn = false;
}
if( $read === null || socket_last_error()) {
printf( "[%s] Disconnected\n", $client->getaddress() );
if ($read === null || socket_last_error()) {
printf("[%s] Disconnected\n", $client->getaddress());
return false;
}
}
// Something bad happened. We'll log it and then disconnect.
} catch (\Exception $e) {
Log::emergency($e->getMessage());
}
$client->close();
printf( "[%s] Disconnected\n", $client->getaddress() );
}
@ -873,6 +871,7 @@ class Server extends Command
return strlen($text) - substr_count($text, ESC);
}
// @todo Not clearing to end of line.
function sendBaseline($client, &$blp, $text, $reposition = false){
$client->send(HOME . UP . $text .
( $blp > strlenv($text) ? str_repeat(' ',$blp-strlenv($text)) .

View File

@ -13,25 +13,14 @@ class Frame extends Model
* @param string $frame
* @return mixed
*/
public function fetch(int $page,string $frame): \App\Classes\Frame
public function fetch(int $frame,string $index): \App\Classes\Frame
{
if ($page == '999' and $frame == 'a')
if ($frame == '999' and $index == 'a')
{
return new \App\Classes\Frame(\App\Classes\Frame::testFrame());
}
return new \App\Classes\Frame($this->where('frame_id',$page)->where('subframe_id',$frame)->firstOrFail());
}
/**
* Return the frame cost
*
* @return int
*/
public function getCostAttribute()
{
// @todo NOT in DB
return rand(0,999);
return new \App\Classes\Frame($this->where('frame',$frame)->where('index',$index)->firstOrFail());
}
public function hasFlag(string $flag)
@ -45,7 +34,6 @@ class Frame extends Model
*/
public function type()
{
// @todo in DB
return isset($this->frametype) ? $this->frametype : 'i';
return $this->type ?: 'i';
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace App\Traits;
use \Illuminate\Database\Eloquent\Builder;
/**
* Trait HasCompositePrimaryKey
* Enables primary keys to be an array.
*
* @package App\Traits
*/
trait HasCompositePrimaryKey {
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if (! is_array($keys)){
return parent::setKeysForSaveQuery($query);
}
foreach ($keys as $keyName){
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if (is_null($keyName)){
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
}
}

View File

@ -40,7 +40,7 @@
"App\\": "app/"
},
"files": [
"bootstrap/constants.php"
"config/constants.php"
],
"classmap": [
"database/seeds",

View File

@ -0,0 +1,79 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class InitDatabase extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->down();
Schema::create('modes', function (Blueprint $table) {
$table->timestamps();
$table->integer('id')->autoIncrement();
$table->string('name',16);
$table->string('note',255);
$table->unique(['name']);
});
Schema::create('cugs', function (Blueprint $table) {
$table->timestamps();
$table->integer('id');
$table->string('name',16);
$table->string('note',255);
$table->integer('parent_id')->nullable();
$table->primary('id');
$table->foreign('parent_id')->references('id')->on('cugs');
$table->unique(['name']);
});
Schema::create('frames', function (Blueprint $table) {
$table->timestamps();
$table->integer('id')->autoIncrement();
$table->integer('frame');
$table->char('index',1);
$table->integer('mode_id');
$table->char('type',2);
$table->smallInteger('cost')->default(0);
$table->integer('cug_id')->default(0);
$table->boolean('public')->default(FALSE);
$table->binary('content');
$table->string('note',255)->nullable();
//$table->unique(['frame','index','mode_id']); // Not needed since we have timewarp
$table->foreign('mode_id')->references('id')->on('modes');
$table->foreign('cug_id')->references('id')->on('cugs');
});
Schema::create('routes', function (Blueprint $table) {
$table->integer('id')->autoIncrement();
$table->char('key',1);
$table->integer('route');
$table->foreign('route')->references('id')->on('frames');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('routes');
Schema::dropIfExists('frames');
Schema::dropIfExists('cugs');
Schema::dropIfExists('modes');
}
}

View File

@ -11,6 +11,7 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
$this->call(SeedMode::class);
$this->call(SeedCUG::class);
}
}

View File

@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Seeder;
class SeedCUG extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('cugs')->insert([
'created_at' => now(),
'id' => 0,
'name' => 'Public Frames',
'note' => 'All frames belong to this CUG if not any other.',
]);
}
}

View File

@ -0,0 +1,20 @@
<?php
use Illuminate\Database\Seeder;
class SeedMode extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('modes')->insert([
'created_at' => now(),
'name' => 'ViewData',
'note' => 'Original ViewData/VideoTex 40x25 char mode.',
]);
}
}