-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a few commands and improve some stuff
**New Stuff** * server:console -- see the server console * server:say -- send a message to the console **Fixes** * server:list -- now checks status of server process * server:create -- shut git the fu*k up * server:path -- now tells you the path if it is set and a paht isn't provided * server:stop -- now sends message to server, disablable
- Loading branch information
Novalis
committed
Nov 16, 2017
1 parent
ca419a7
commit c9f4a0c
Showing
10 changed files
with
231 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace App\Commands\Server; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Contracts\Filesystem\FileNotFoundException; | ||
use Illuminate\Support\Facades\Storage; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class ConsoleCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'server:console {name? : The name of the server} {--no-warning : Don\'t show the warning}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'See the server console'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle(): void | ||
{ | ||
try { | ||
$servers = json_decode(Storage::get('servers.json'), true); | ||
} catch (FileNotFoundException $e) { | ||
$this->error('FiveM is not installed! Please run server:install'); | ||
exit; | ||
} | ||
|
||
$serverName = $this->argument('name'); | ||
|
||
if (empty($serverName)) { | ||
$serverName = $this->ask('Which server'); | ||
} | ||
|
||
$serverName = str_slug($serverName); | ||
|
||
if (! isset($servers[$serverName])) { | ||
$this->error('That server does not exist!'); | ||
exit; | ||
} | ||
|
||
$server = $servers[$serverName]; | ||
|
||
$status = []; | ||
exec("ps auxw | grep -i fivem- | grep -v grep | awk '{print $13}'", $status); | ||
$status = str_replace('fivem-', '', $status); | ||
|
||
if (! $server['status'] && ! in_array($serverName, $status)) { | ||
$this->error('That server is not up!'); | ||
exit; | ||
} | ||
|
||
if ($server['status'] && ! in_array($serverName, $status)) { | ||
$this->warn("$serverName may have crashed!"); | ||
if ($this->confirm("Do you want to put it back up?")) { | ||
$this->call('server:start', ['name' => $serverName, '-q' => true]); | ||
} else { | ||
$server['status'] = false; | ||
$servers[$serverName] = $server; | ||
Storage::put('servers.json', json_encode($servers)); | ||
} | ||
exit; | ||
} | ||
|
||
if(!$this->option('no-warning')) { | ||
$this->warn('Remember to do [CTRL+A, D] to close the console or you will crash the server!'); | ||
sleep(2); | ||
} | ||
|
||
system("screen -r fivem-$serverName"); | ||
} | ||
|
||
/** | ||
* Define the command's schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* | ||
* @return void | ||
*/ | ||
public function schedule(Schedule $schedule): void | ||
{ | ||
// $schedule->command(static::class)->everyMinute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace App\Commands\Server; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Contracts\Filesystem\FileNotFoundException; | ||
use Illuminate\Support\Facades\Storage; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class SayCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'server:say {name?} {message?}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Send a message to the server'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle(): void | ||
{ | ||
try { | ||
$servers = json_decode(Storage::get('servers.json'), true); | ||
} catch (FileNotFoundException $e) { | ||
$this->error('FiveM is not installed! Please run server:install'); | ||
exit; | ||
} | ||
|
||
$serverName = $this->argument('name'); | ||
|
||
if (empty($serverName)) { | ||
$serverName = $this->ask('Which server'); | ||
} | ||
|
||
$message = $this->argument('message'); | ||
|
||
if (empty($message)) { | ||
$message = $this->ask('What is your question'); | ||
} | ||
|
||
$serverName = str_slug($serverName); | ||
|
||
$server = $servers[$serverName]; | ||
|
||
if (empty($server)) { | ||
$this->error('That server does not exist!'); | ||
exit; | ||
} | ||
|
||
if (! $server['status']) { | ||
$this->error('That server is not up!'); | ||
exit; | ||
} | ||
|
||
exec("screen -S fivem-$serverName -X stuff 'say $message'$(echo -ne '\015')"); | ||
} | ||
|
||
/** | ||
* Define the command's schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* | ||
* @return void | ||
*/ | ||
public function schedule(Schedule $schedule): void | ||
{ | ||
// $schedule->command(static::class)->everyMinute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* Laravel Zero - An elegant starting point for your Laravel Console Application | ||
* | ||
* @package Laravel Zero | ||
* @author Nuno Maduro <enunomaduro@gmail.com> | ||
*/ | ||
|
||
require_once __DIR__ . '/bootstrap/init.php'; |
This file was deleted.
Oops, something went wrong.