Skip to content
Permalink
Browse files

0.72.19 Add records table module

  • Loading branch information...
brakerb committed Aug 11, 2019
1 parent dbdebf4 commit 2ad4452902d9a9a0f5c023910af08a70f7a8440b
@@ -28,14 +28,18 @@ protected function configure()
->addArgument('groupId', InputArgument::OPTIONAL, 'Group id to add');
}
protected function initialize(InputInterface $input, OutputInterface $output)
{
Log::setOutput($output);
ConfigController::init();
Database::init();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$login = $input->getArgument('login');
$groupId = $input->getArgument('groupId');
$helper = new QuestionHelper();
Log::setOutput($output);
ConfigController::init();
Database::init();
$player = Player::find($login);
@@ -1,14 +1,34 @@
<?php
require 'gbxdatafetcher/gbxdatafetcher.inc.php';
namespace esc\Commands;
use Error;
use esc\Classes\Database;
use esc\Classes\File;
use esc\Classes\Hook;
use esc\Classes\ManiaLinkEvent;
use esc\Classes\RestClient;
use esc\Classes\Server;
use esc\Classes\Log;
use esc\Classes\Timer;
use esc\Controllers\AfkController;
use esc\Controllers\BansController;
use esc\Controllers\ChatController;
use esc\Controllers\ConfigController;
use esc\Controllers\CountdownController;
use esc\Controllers\EventController;
use esc\Controllers\HookController;
use esc\Controllers\MapController;
use esc\Controllers\MatchSettingsController;
use esc\Controllers\ModuleController;
use esc\Controllers\PlanetsController;
use esc\Controllers\PlayerController;
use esc\Controllers\QueueController;
use esc\Controllers\SetupController;
use esc\Controllers\TemplateController;
use esc\Models\Map;
use esc\Models\Player;
use Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -28,16 +48,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
global $serverName;
Log::setOutput($output);
esc\Controllers\ConfigController::init();
ConfigController::init();
if ($input->getOption('setup') !== false || !File::exists(cacheDir('.setupfinished'))) {
esc\Controllers\SetupController::startSetup($input, $output, $this->getHelper('question'));
SetupController::startSetup($input, $output, $this->getHelper('question'));
}
try {
$output->writeln("Connecting to server...");
esc\Classes\Server::init(
Server::init(
config('server.ip'),
config('server.port'),
5,
@@ -71,7 +91,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
protected function interact(InputInterface $input, OutputInterface $output)
{
file_put_contents(baseDir(config('server.login') . '_evosc.pid'), getmypid());
file_put_contents(baseDir(config('server.login').'_evosc.pid'), getmypid());
}
private function migrate(InputInterface $input, OutputInterface $output)
@@ -106,22 +126,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
$_onlinePlayers = collect();
esc\Classes\Database::init();
esc\Classes\RestClient::init(serverName());
esc\Controllers\HookController::init();
esc\Controllers\TemplateController::init();
esc\Controllers\ChatController::init();
esc\Classes\ManiaLinkEvent::init();
esc\Controllers\QueueController::init();
esc\Controllers\MatchSettingsController::init();
esc\Controllers\MapController::init();
esc\Controllers\PlayerController::init();
esc\Controllers\AfkController::init();
esc\Controllers\BansController::init();
esc\Controllers\ModuleController::init();
esc\Controllers\PlanetsController::init();
esc\Controllers\CountdownController::init();
Database::init();
RestClient::init(serverName());
HookController::init();
TemplateController::init();
ChatController::init();
ManiaLinkEvent::init();
QueueController::init();
MatchSettingsController::init();
MapController::init();
PlayerController::init();
AfkController::init();
BansController::init();
ModuleController::init();
PlanetsController::init();
CountdownController::init();
//TODO: Collection Transform
$logins = [];
foreach (Server::getPlayerList(500, 0) as $player) {
array_push($logins, $player->login);
@@ -134,14 +155,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
Log::write('Booting core finished.', true);
}
esc\Controllers\ModuleController::bootModules();
ModuleController::bootModules();
if (isVerbose()) {
Log::write('Booting modules finished.', true);
}
$map = Map::where('filename', esc\Classes\Server::getCurrentMapInfo()->fileName)->first();
esc\Classes\Hook::fire('BeginMap', $map);
$map = Map::where('filename', Server::getCurrentMapInfo()->fileName)->first();
Hook::fire('BeginMap', $map);
//Set connected players online
$playerList = collect(Server::rpc()->getPlayerList());
@@ -161,17 +182,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
//cycle-loop
while (true) {
try {
esc\Classes\Timer::startCycle();
Timer::startCycle();
EventController::handleCallbacks(esc\Classes\Server::executeCallbacks());
EventController::handleCallbacks(Server::executeCallbacks());
$pause = esc\Classes\Timer::getNextCyclePause();
$pause = Timer::getNextCyclePause();
$failedConnectionRequests = 0;
usleep($pause);
} catch (Exception $e) {
Log::write('MPS',
'Failed to fetch callbacks from dedicated-server. Failed attempts: ' . $failedConnectionRequests . '/50');
'Failed to fetch callbacks from dedicated-server. Failed attempts: '.$failedConnectionRequests.'/50');
Log::write($e->getMessage());
$failedConnectionRequests++;
@@ -184,12 +205,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
sleep(5);
} catch (Error $e) {
$errorClass = get_class($e);
$output->writeln("<error>$errorClass in " . $e->getFile() . " on Line " . $e->getLine() . "</error>");
$output->writeln("<fg=white;bg=red;options=bold>" . $e->getMessage() . "</>");
$output->writeln("<error>$errorClass in ".$e->getFile()." on Line ".$e->getLine()."</error>");
$output->writeln("<fg=white;bg=red;options=bold>".$e->getMessage()."</>");
$output->writeln("<error>===============================================================================</error>");
$output->writeln("<error>" . $e->getTraceAsString() . "</error>");
$output->writeln("<error>".$e->getTraceAsString()."</error>");
Log::write('EvoSC encountered an error: ' . $e->getMessage(), false);
Log::write('EvoSC encountered an error: '.$e->getMessage(), false);
Log::write($e->getTraceAsString(), false);
}
}
@@ -0,0 +1,59 @@
<?php
namespace esc\Commands;
use esc\Classes\Database;
use esc\Classes\Log;
use esc\Controllers\ConfigController;
use esc\Models\Map;
use esc\Models\Player;
use esc\Modules\LocalRecords\LocalRecords;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class FakeLocals extends Command
{
protected function configure()
{
$this->setName('fake:locals')
->setDescription('Adds fake local records for testing.');
}
protected function initialize(InputInterface $input, OutputInterface $output)
{
ConfigController::init();
Log::setOutput($output);
Database::init();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$maps = Map::all();
$bar = new ProgressBar($output, $maps->count());
$bar->start();
foreach ($maps as $map) {
$localCount = $map->locals()->count();
$local = $map->locals()->first();
for ($i = $localCount; $i < 100; $i++) {
$playerId = Player::inRandomOrder()->first()->id;
$map->locals()->insert([
'Player' => $playerId,
'Map' => $map->id,
'Score' => ($local->Score ?? rand(55000, 9000)) + rand(1, 100),
'Checkpoints' => $local->Checkpoints ?? '1,2,3,4,5,6,7',
'Rank' => 0
]);
}
$bar->advance();
LocalRecords::fixRanks($map);
}
$bar->finish();
}
}
@@ -16,10 +16,13 @@ protected function configure()
$this->setName('fix:scores');
}
protected function execute(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output)
{
Log::setOutput($output);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!file_exists('config/database.config.json')) {
$output->writeln('config/database.config.json not found');
@@ -11,6 +11,7 @@
use esc\Controllers\MapController;
use esc\Controllers\TemplateController;
use esc\Models\Player;
use esc\Modules\LocalRecords\LocalRecords;
use esc\Modules\MusicClient\MusicClient;
use Illuminate\Support\Collection;
@@ -24,6 +25,6 @@ public function __construct()
public static function testStuff(Player $player = null)
{
TemplateController::loadTemplates();
UiSettings::mleShowSettingsWindow($player);
LocalRecords::showLocalsTable($player);
}
}
@@ -64,7 +64,7 @@
}
}else{
declare Boolean playerIsRacing = InputPlayer.RaceState == CTmMlPlayer::ERaceState::Running;
declare Boolean overHidespeed = InputPlayer.DisplaySpeed >= hideSpeed;
declare Boolean overHidespeed = InputPlayer.DisplaySpeed > hideSpeed;
if(overHidespeed && playerIsRacing && !HS_Hidden){
hide();
@@ -7,13 +7,15 @@
use esc\Classes\ManiaLinkEvent;
use esc\Classes\Template;
use esc\Controllers\MapController;
use esc\Interfaces\ModuleInterface;
use esc\Models\AccessRight;
use esc\Models\LocalRecord;
use esc\Models\Map;
use esc\Models\Player;
use esc\Modules\RecordsTable;
use Illuminate\Support\Collection;
class LocalRecords
class LocalRecords implements ModuleInterface
{
/**
* @var \Illuminate\Support\Collection
@@ -43,6 +45,7 @@ public function __construct()
AccessRight::createIfNonExistent('local_delete', 'Delete local-records.');
ManiaLinkEvent::add('local.delete', [self::class, 'delete'], 'local_delete');
ManiaLinkEvent::add('locals.show', [self::class, 'showLocalsTable']);
}
//Called on PlayerConnect
@@ -54,6 +57,13 @@ public static function showManialink(Player $player)
Template::show($player, 'local-records.manialink');
}
public static function showLocalsTable(Player $player)
{
$records = MapController::getCurrentMap()->locals()->orderBy('Score')->get();
RecordsTable::show($player, $records, 'Local Records');
}
//Called on PlayerFinish
public static function playerFinish(Player $player, int $score, string $checkpoints)
{
@@ -243,4 +253,14 @@ private static function getNextBetterRank(Player $player, Map $map, int $score)
return 1;
}
/**
* Called when the module is loaded
*
* @param string $mode
*/
public static function start(string $mode)
{
// TODO: Implement start() method.
}
}
@@ -205,6 +205,9 @@
{/block}
{block pendingEvents}
if(event.Control.HasClass("widget") && event.Type == CMlScriptEvent::Type::MouseClick){
TriggerPageAction("locals.show");
}
{/block}
--></script>
</manialink>
@@ -0,0 +1,31 @@
<?php
namespace esc\Modules;
use esc\Classes\ManiaLinkEvent;
use esc\Classes\Template;
use esc\Interfaces\ModuleInterface;
use esc\Models\Player;
use Illuminate\Support\Collection;
class RecordsTable implements ModuleInterface
{
/**
* Called when the module is loaded
*
* @param string $mode
*/
public static function start(string $mode)
{
}
public static function show(Player $player, Collection $records, string $window_title = 'Records')
{
$pages = floor($records->count() / 100);
$records = $records->chunk(100);
$onlineLogins = onlinePlayers()->pluck('Login');
Template::show($player, 'records-table.table', compact('records', 'pages', 'onlineLogins', 'window_title'));
}
}

0 comments on commit 2ad4452

Please sign in to comment.
You can’t perform that action at this time.