clrghouz/app/Classes/BBS/Server/Videotex.php
2023-09-13 20:59:40 +10:00

91 lines
2.3 KiB
PHP

<?php
namespace App\Classes\BBS\Server;
use App\Classes\BBS\Server as AbstractServer;
use App\Classes\Sock\SocketClient;
class Videotex extends AbstractServer
{
protected const LOGKEY = 'BVS';
/* CONSTS */
public const PORT = 516;
protected function init(SocketClient $client)
{
define('ESC', chr(27));
define('CON', chr(17)); // Cursor On
define('COFF', chr(20)); // Cursor Off
define('HOME', chr(30));
define('LEFT', chr(8)); // Move Cursor
define('RIGHT', chr(9)); // Move Cursor
define('DOWN', chr(10)); // Move Cursor
define('UP', chr(11)); // Move Cursor
define('CR', chr(13));
define('LF', chr(10));
define('CLS', chr(12));
define('HASH', '_'); // Enter
define('STAR', '*'); // Star Entry
define('SPACE', ''); // Space
// NOTE: This consts are effective output
define('RESET', '');
define('RED', ESC.'A');
define('GREEN', ESC.'B');
define('YELLOW', ESC.'C');
define('BLUE', ESC.'D');
define('MAGENTA', ESC.'E');
define('CYAN', ESC.'F');
define('WHITE', ESC.'G');
define('NEWBG', ESC.']');
// Raw attributes - used when storing frames.
define('R_RED', chr(1));
define('R_GREEN', chr(2));
define('R_YELLOW', chr(3));
define('R_BLUE', chr(4));
define('R_MAGENTA', chr(5));
define('R_CYAN', chr(6));
define('R_WHITE', chr(7));
define('FLASH', chr(8));
define('KEY_DELETE', chr(0x7f));
define('KEY_LEFT', chr(0x08));
define('KEY_RIGHT', chr(0x09));
define('KEY_DOWN', chr(0x0a));
define('KEY_UP', chr(0x0b));
parent::init($client);
}
public function moveCursor($x,$y): string
{
// Take the shortest path.
if ($y < 12) {
return HOME.
(($x < 21)
? str_repeat(DOWN,$y-1).str_repeat(RIGHT,$x)
: str_repeat(DOWN,$y).str_repeat(LEFT,40-$x));
} else {
return HOME.str_repeat(UP,24-$y+1).
(($x < 21)
? str_repeat(RIGHT,$x)
: str_repeat(LEFT,40-$x));
}
}
public function sendBaseline(string $text,bool $reposition=FALSE) {
$this->client->send(HOME.UP.$text.
($this->blp > $this->po->strlenv($text)
? str_repeat(' ',$this->blp-$this->po->strlenv($text)).
($reposition ? HOME.UP.str_repeat(RIGHT,$this->po->strlenv($text)) : '')
: ''),
static::TIMEOUT
);
$this->blp = $this->po->strlenv($text);
}
}