This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
vbbs/app/Console/Commands/Server.php

79 lines
1.6 KiB
PHP
Raw Permalink Normal View History

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;
use Sock\{SocketServer,SocketException};
use App\Models\Mode;
2018-12-01 21:50:34 +00:00
class Server extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'server {--mode=VideoTex : Server Mode Profile}';
2018-12-01 21:50:34 +00:00
/**
* The console command description.
*
* @var string
*/
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');
}
$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();
$server->setConnectionHandler([$mo->server(),'onConnect']);
try {
$server->listen();
} catch (SocketException $e) {
if ($e->getMessage() == 'Can\'t accept connections: "Success"')
2018-12-08 23:13:51 +00:00
Log::debug(sprintf('Server Terminated: %s',$mo->name));
else
2018-12-08 23:13:51 +00:00
Log::emergency('Uncaught Message: '.$e->getMessage(),['name'=>$mo->name]);
}
2018-12-01 21:50:34 +00:00
}
2018-12-06 03:09:43 +00:00
}