2018-12-01 21:50:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Viewdata/Videotex Server
|
|
|
|
*
|
|
|
|
* Inspired by Rob O'Donnell at irrelevant.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2018-12-07 05:19:51 +00:00
|
|
|
use Sock\{SocketServer,SocketException};
|
|
|
|
|
|
|
|
use App\Models\Mode;
|
2018-12-07 03:22:47 +00:00
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
class Server extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-12-07 05:19:51 +00:00
|
|
|
protected $signature = 'server {--mode=VideoTex : Server Mode Profile}';
|
2018-12-01 21:50:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-12-07 05:19:51 +00:00
|
|
|
protected $description = 'Start Server';
|
2018-12-01 21:50:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @throws \Sock\SocketException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Check dependencies
|
|
|
|
*/
|
|
|
|
if (! extension_loaded('sockets' ) ) {
|
|
|
|
throw new SocketException(SocketException::CANT_ACCEPT,'Missing sockets extension');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! extension_loaded('pcntl' ) ) {
|
|
|
|
throw new SocketException(SocketException::CANT_ACCEPT,'Missing pcntl extension');
|
|
|
|
}
|
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
$mo = Mode::where('name','LIKE',$this->option('mode'))->firstOrFail();
|
2018-12-01 21:50:34 +00:00
|
|
|
|
|
|
|
$server = new SocketServer(config('app.port'),config('app.bind'));
|
|
|
|
$server->init();
|
2018-12-07 05:19:51 +00:00
|
|
|
$server->setConnectionHandler([$mo->server(),'onConnect']);
|
2018-12-07 03:22:47 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$server->listen();
|
|
|
|
|
|
|
|
} catch (SocketException $e) {
|
|
|
|
if ($e->getMessage() == 'Can\'t accept connections: "Success"')
|
|
|
|
Log::debug('Server Terminated.');
|
|
|
|
else
|
|
|
|
Log::emergency('Uncaught Message: '.$e->getMessage());
|
|
|
|
}
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
2018-12-06 03:09:43 +00:00
|
|
|
}
|