Skip to content
Permalink
Browse files

0.56.0 Refactor all chat messages

-Remove crash reports
-Remove message from ChatController
  • Loading branch information...
brakerb committed Mar 5, 2019
1 parent c06d0b3 commit 6fd595d46ffee6e40fa88fe35441d4fb258ef905
@@ -5,7 +5,6 @@ music/
maps/
logs/
cache/
crash-reports/*.json

config/*
!config/default
@@ -36,7 +36,7 @@ public static function ban(Player $player, Player $admin, string $reason = '')
{
Server::banAndBlackList($player->Login, $reason, true);
$player->update(['banned' => true]);
ChatController::message(onlinePlayers(), '_warning', $admin, ' banned ', $player, ', reason: ', secondary($reason));
warningMessage($admin, ' banned ', $player, ', reason: ', secondary($reason))->sendAll();
}
/**
@@ -49,7 +49,7 @@ public static function unban(Player $player, Player $admin)
{
Server::unBan($player->Login);
$player->update(['banned' => false]);
ChatController::message(onlinePlayers(), '_warning', $admin, ' unbanned ', $player);
infoMessage($admin, ' unbanned ', $player)->sendAll();
}
/**
@@ -231,68 +231,4 @@ public static function addAlias(string $command, string $alias)
{
//TODO:
}
/**
* @param \esc\Models\Player|\Illuminate\Support\Collection $recipient
* @param mixed ...$parts
*/
public static function message($recipients, ...$parts)
{
$message = self::prepareMessage(...$parts);
if ($recipients instanceof Player) {
$message->send($recipients);
} else {
$message->sendAll();
}
}
private static function prepareMessage(...$parts): ChatMessage
{
$chatMessage = new ChatMessage();
if (preg_match('/^_(\w+)$/', $parts[0], $matches)) {
//set primary color of message
switch ($matches[1]) {
case 'secondary':
$chatMessage->setColor(config('colors.secondary'));
array_shift($parts);
break;
case 'info':
$chatMessage->setIcon("");
$chatMessage->setColor(config('colors.info'));
array_shift($parts);
break;
case 'warning':
$chatMessage->setIcon("");
$chatMessage->setColor(config('colors.warning'));
array_shift($parts);
break;
case 'local':
$chatMessage->setIcon("");
$chatMessage->setColor(config('colors.local'));
array_shift($parts);
break;
case 'dedi':
$chatMessage->setIcon("");
$chatMessage->setColor(config('colors.dedi'));
array_shift($parts);
break;
default:
if (preg_match('/[0-9a-f]{3}/', $matches[1])) {
$chatMessage->setColor($matches[1]);
array_shift($parts);
}
}
}
$chatMessage->setParts(...$parts);
return $chatMessage;
}
}
@@ -29,7 +29,7 @@ public static function init()
public static function reloadConfig(Player $player)
{
ChatController::message(onlinePlayers(), '_info', $player->group, ' ', $player, ' reloads config.');
infoMessage($player->group, ' ', $player, ' reloads config.')->sendAll();
Config::loadConfigFiles();
Hook::fire('ConfigUpdated');
}
@@ -34,7 +34,7 @@ public static function reloadModule(Player $callee, string $moduleName)
if ($module) {
$module->load($callee);
ChatController::message(onlinePlayers(), '_info', $callee, ' reloads module ', $module);
infoMessage($callee, ' reloads module ', $module)->sendAll();
}
}
@@ -46,7 +46,7 @@ public static function getModules(): Collection
public static function showModules(Player $player)
{
if (!$player->isMasteradmin()) {
ChatController::message($player, warning('Access denied'));
warningMessage('Access denied.')->send($player);
return;
}
@@ -29,14 +29,14 @@ public static function init()
public static function queueMap(Player $player, Map $map, bool $replay = false)
{
if (MapQueue::whereMapUid($map->uid)->count() > 0) {
ChatController::message($player, '_warning', 'The map ', secondary($map), ' is already in queue.');
warningMessage('The map ', secondary($map), ' is already in queue.')->send($player);
return;
}
if (MapQueue::whereRequestingPlayer($player->Login)->count() > 0) {
if (!$player->hasAccess('queue_multiple')) {
ChatController::message($player, '_warning', 'You are only allowed to queue one map at a time.');
warningMessage('You are only allowed to queue one map at a time.')->send($player);
return;
}
@@ -47,10 +47,10 @@ public static function queueMap(Player $player, Map $map, bool $replay = false)
'map_uid' => $map->uid,
]);
if($replay){
ChatController::message(onlinePlayers(), '_info', $player, ' queued map ', secondary($map), ' for replay.');
}else{
ChatController::message(onlinePlayers(), '_info', $player, ' queued map ', secondary($map), '.');
if ($replay) {
infoMessage($player, ' queued map ', secondary($map), ' for replay.')->sendAll();
} else {
infoMessage($player, ' queued map ', secondary($map), '.')->sendAll();
}
Hook::fire('MapQueueUpdated', self::getMapQueue());
@@ -61,15 +61,15 @@ public static function dropMap(Player $player, $mapUid)
$queueItem = MapQueue::whereMapUid($mapUid)->first();
if ($queueItem) {
if ($queueItem->requesting_player == $player->Login || $player->hasAccess('queue_drop')) {
ChatController::message(onlinePlayers(), '_info', $player, ' drops ', secondary($queueItem->map), ' from queue.');
MapQueue::whereMapUid($mapUid)->delete();
Hook::fire('MapQueueUpdated', self::getMapQueue());
if ($queueItem->requesting_player != $player->Login && !$player->hasAccess('queue_drop')) {
warningMessage('You can not drop others players maps.')->send($player);
return;
}
ChatController::message(onlinePlayers(), '_warning', $player, 'You can not drop others players maps.');
infoMessage($player, ' drops ', secondary($queueItem->map), ' from queue.')->sendAll();
MapQueue::whereMapUid($mapUid)->delete();
Hook::fire('MapQueueUpdated', self::getMapQueue());
}
}
@@ -93,7 +93,7 @@ public static function playerDisconnect(Player $player)
if (!$player->hasAccess('queue_keep') && $queryBuilder->count() > 0) {
$queryBuilder->get()->filter(function (MapQueue $item) use ($player) {
ChatController::message(onlinePlayers(), '_info', 'Dropped ', secondary($item->map), ' from queue, because ', secondary($player), ' left.');
infoMessage('Dropped ', secondary($item->map), ' from queue, because ', secondary($player), ' left.')->sendAll();
MapQueue::whereMapUid($item->map_uid)->delete();
});
@@ -28,7 +28,7 @@ public static function addMap(Player $player, $cmd, $mxId)
if ($mxId == 0) {
Log::warning("Requested map with invalid id: " . $mxId);
ChatController::message($player, '_warning', 'Requested map with invalid id: ', $mxId);
warningMessage('Requested map with invalid id: ', $mxId)->send($player);
return;
}
@@ -40,7 +40,7 @@ public static function addMap(Player $player, $cmd, $mxId)
if ($response->getStatusCode() != 200) {
Log::error("ManiaExchange returned with non-success code [" . $response->getStatusCode() . "] " . $response->getReasonPhrase());
ChatController::message($player, "Can not reach mania exchange.");
warningMessage('Can not reach mania exchange.')->send($player);
return;
}
@@ -69,7 +69,7 @@ public static function addMap(Player $player, $cmd, $mxId)
File::put($absolute, $body);
if (!File::exists($absolute)) {
ChatController::message($player, '_warning', "Map download ($mxId) failed.");
warningMessage("Map download ($mxId) failed.")->send($player);
return;
}
@@ -106,16 +106,16 @@ public static function addMap(Player $player, $cmd, $mxId)
Votes::startVote($player, 'Play ' . secondary($map) . '?', function ($success) use ($map, $player) {
if ($success) {
QueueController::queueMap($player, $map);
ChatController::message(onlinePlayers(), '_info', 'Vote to add ', secondary($map), ' was successful.');
ChatController::message(onlinePlayers(), '_info', $map, ' was added to the queue.');
infoMessage('Vote to add ', secondary($map), ' was successful.')->sendAll();
infoMessage($map, ' was added to the queue.')->sendAll();
Hook::fire('MapPoolUpdated');
Hook::add('BeginMatch', function () use ($map) {
$map->update(['enabled' => 0]);
Hook::fire('MapPoolUpdated');
}, true);
} else {
ChatController::message(onlinePlayers(), '_info', 'Vote to add ', secondary($map), ' failed.');
infoMessage('Vote to add ', secondary($map), ' failed.')->sendAll();
}
});
} catch (\Exception $e) {
@@ -263,9 +263,9 @@ public static function playerFinish(Player $player, int $score, string $checkpoi
$dedi->update(['Score' => $score, 'Checkpoints' => $checkpoints, 'New' => 1, 'Rank' => $newRank]);
if ($oldRank == $newRank) {
chatMessage($player, ' secured his/her ', $dedi, ' (-' . formatScore($diff) . ')')->setIcon('')->setColor(config('colors.dedi'))->sendAll();
chatMessage($player, ' secured his/her ', $dedi, ' (' . $oldRank . '. -' . formatScore($diff) . ')')->setIcon('')->setColor(config('colors.dedi'))->sendAll();
} else {
chatMessage($player, ' gained the ', $dedi, ' (-' . formatScore($diff) . ')')->setIcon('')->setColor(config('colors.dedi'))->sendAll();
chatMessage($player, ' gained the ', $dedi, ' (' . $oldRank . '. -' . formatScore($diff) . ')')->setIcon('')->setColor(config('colors.dedi'))->sendAll();
}
self::sendUpdatedDedis($map);
@@ -404,7 +404,6 @@ static function setChallengeTimes(Map $map)
//Request failed
Log::logAddLine('DedimaniaApi', 'Failed to update dedis.', true);
\esc\Controllers\ChatController::message(onlinePlayers(), 'Updating dedis failed');
}
}
}
@@ -461,7 +460,7 @@ public static function playerConnect(Player $player)
]);
if ($player->Banned) {
\esc\Controllers\ChatController::message($player, warning(' is banned from dedimania.'));
warningMessage($player, ' is banned from dedimania.')->sendAll();
}
}
@@ -32,7 +32,7 @@ public function __construct()
}, 'Say Good Game All.', '/');
ChatController::addCommand('bootme', function (Player $player) {
ChatController::message(onlinePlayers(), '_info', $player, ' boots back to the real world!');
infoMessage($player, ' boots back to the real world!')->sendAll();
Server::kick($player->Login, 'cya');
Hook::fire('PlayerDisconnect', $player);
}, 'Boot yourself back to the real world.', '/');
@@ -59,18 +59,18 @@ public static function groupCreate(Player $player, $input)
$groupNameExists = Group::whereName($input)->get()->isNotEmpty();
if ($groupNameExists) {
ChatController::message($player, '_warning', 'Group name ', secondary($input), ' already taken.');
warningMessage('Group name ', secondary($input), ' already taken.')->send($player);
return;
}
$group = Group::create(['Name' => $input]);
if ($group) {
ChatController::message($player, '_info', 'Created new group: ', secondary($input));
infoMessage('Created new group: ', secondary($input))->send($player);
self::showOverview($player);
} else {
ChatController::message($player, '_warning', 'Failed to create group: ', secondary($input));
warningMessage('Failed to create group: ', secondary($input))->send($player);
}
}
@@ -131,9 +131,9 @@ public static function playerFinish(Player $player, int $score, string $checkpoi
$local = self::fixLocalRecordRanks($map, $player);
if ($oldRank == $local->Rank) {
$chatMessage->setParts($player, ' secured his/her ', $local, ' (-' . formatScore($diff) . ')')->sendAll();
$chatMessage->setParts($player, ' secured his/her ', $local, ' ('.$oldRank.'. -' . formatScore($diff) . ')')->sendAll();
} else {
$chatMessage->setParts( $player, ' gained the ', $local, ' (-' . formatScore($diff) . ')')->sendAll();
$chatMessage->setParts( $player, ' gained the ', $local, ' ('.$oldRank.'. -' . formatScore($diff) . ')')->sendAll();
}
Hook::fire('PlayerLocal', $player, $local);
self::sendUpdatedLocals($map);
@@ -76,12 +76,12 @@ public function updateMap(Player $player, string $mapId, string $enabledString)
$mapBranch = $this->xml->addChild('map');
$mapBranch->addChild('file', $map->filename);
$mapBranch->addChild('ident', $map->gbx->MapUid);
ChatController::message($player, '_info', 'Added map ', $map, ' to ', secondary($this->filename));
infoMessage('Added map ', $map, ' to ', secondary($this->filename))->send($player);
} else {
foreach ($this->xml->map as $mapNode) {
if ($mapNode->ident == $map->gbx->MapUid) {
unset($mapNode[0]);
ChatController::message($player, '_info', 'Removed map ', $map, ' from ', secondary($this->filename));
infoMessage('Removed map ', $map, ' from ', secondary($this->filename))->send($player);
}
}
}
@@ -271,7 +271,7 @@ public static function loadMatchSettings(Player $player, string $matchSettingsFi
onlinePlayers()->each([MapList::class, 'sendManialink']);
if (!$silent) {
ChatController::message(onlinePlayers(), $player, ' loads new settings ', secondary($matchSettingsFile));
infoMessage($player, ' loads new settings ', secondary($matchSettingsFile))->sendAll();
}
Log::logAddLine('MatchSettingsManager', "$player loads MatchSettings: $matchSettingsFile");
}
@@ -35,23 +35,23 @@ public static function addMap(Player $player, $cmd, string ...$arguments)
if ($mxId == 0) {
Log::warning("Requested map with invalid id: " . $mxId);
ChatController::message($player, "Requested map with invalid id: " . $mxId);
warningMessage("Requested map with invalid id: $mxId")->send($player);
return;
}
$map = Map::getByMxId($mxId);
if ($map && File::exists(MapController::getMapsPath(), 'MX/' . $map->filename)) {
ChatController::message($player, '_warning', secondary($map), ' already exists');
warningMessage(secondary($map), ' already exists')->send($player);
continue;
}
$response = RestClient::get('http://tm.mania-exchange.com/tracks/download/' . $mxId);
if ($response->getStatusCode() != 200) {
Log::error("ManiaExchange returned with non-success code [" . $response->getStatusCode() . "] " . $response->getReasonPhrase());
ChatController::message($player, "Can not reach mania exchange.");
warningMessage('Can not reach mania exchange.')->send($player);
return;
}
@@ -80,7 +80,7 @@ public static function addMap(Player $player, $cmd, string ...$arguments)
File::put($absolute, $body);
if (!File::exists($absolute)) {
ChatController::message($player, '_warning', "Map download ($mxId) failed.");
warningMessage("Map download ($mxId) failed.")->send($player);
continue;
}
@@ -126,7 +126,7 @@ public static function addMap(Player $player, $cmd, string ...$arguments)
}
ChatController::message(onlinePlayers(), '_info', 'New map added: ', $map);
infoMessage('New map added: ', $map)->sendAll();
}
}
}
@@ -43,7 +43,7 @@ public static function showProfile(Player $player, string $targetLogin)
Template::show($player, 'profile-viewer.window', compact('values', 'zonePath'));
} else {
ChatController::message($player, '_warning', 'Player with login ', secondary($targetLogin), ' not found.');
warningMessage('Player with login ', secondary($targetLogin), ' not found.')->send($player);
}
}
}
Oops, something went wrong.

0 comments on commit 6fd595d

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