Skip to content

Commit

Permalink
Add feature to pardon player from web
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Jan 12, 2025
1 parent 1eb0981 commit d858db8
Show file tree
Hide file tree
Showing 201 changed files with 2,230 additions and 2,085 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/CommandQueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function index()
])),
])
->allowedSorts($fields)
->defaultSort('-updated_at')
->defaultSort('-created_at')
->simplePaginate($perPage)
->through(function ($commandQueue) {
if ($commandQueue->tag === 'player_password_reset') {
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/BanWardenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Spatie\QueryBuilder\QueryBuilder;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;

class BanWardenController extends Controller
{
Expand Down Expand Up @@ -326,15 +327,15 @@ public function deleteEvidence(PlayerPunishment $playerPunishment, $evidence)
public function pardon(PlayerPunishment $playerPunishment, Request $request)
{
$request->validate([
'reason' => 'nullable|string|max:255',
'reason' => 'nullable|string|max:100',
]);

$this->authorize('delete', $playerPunishment);

try {
PardonPlayerPunishmentJob::dispatchSync($playerPunishment, $request->input('reason'));
PardonPlayerPunishmentJob::dispatchSync($playerPunishment, $request->input('reason'), $request->user()->username);
} catch (\Exception $e) {
\Log::error($e);
Log::error($e);
return redirect()->back()
->with(['toast' => ['type' => 'error', 'title' => __('Pardon Failed'), 'body' => 'Failed to execute pardon job to due webquery issue.']]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/GeneratePunishmentInsightsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function handle(AiService $aiService): void
]);

// Details
$this->punishment->victimPlayer->makeHidden([
$this->punishment->victimPlayer?->makeHidden([
'skin_texture_id',
'avatar_url',
]);
Expand Down
8 changes: 4 additions & 4 deletions app/Jobs/PardonPlayerPunishmentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PardonPlayerPunishmentJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function __construct(public PlayerPunishment $playerPunishment, public $reason)
public function __construct(public PlayerPunishment $playerPunishment, public $reason, public $admin = null)
{
//
}
Expand All @@ -27,12 +27,11 @@ public function handle(): void
// 1. If we have origin_server_id & that server has webquery, use that server.
// 2. else, send to all servers that have webquery.
if ($this->playerPunishment->origin_server_id && $this->playerPunishment->originServer?->webquery_port) {
$server = [$this->playerPunishment->originServer];
$servers = [$this->playerPunishment->originServer];
} else {
$servers = Server::select(['id', 'name', 'hostname'])->whereNotNull('webquery_port')->get();
}


foreach ($servers as $server) {
$this->pardonPlayerPunishment($server);
}
Expand All @@ -44,9 +43,10 @@ private function pardonPlayerPunishment(Server $server): void

$victim = $this->playerPunishment->uuid ?? $this->playerPunishment->ip_address;
$webQuery->banwardenPardon(
$this->playerPunishment->type->value,
$this->playerPunishment->type,
$victim,
$this->reason,
$this->admin,
);
}
}
10 changes: 8 additions & 2 deletions app/Utils/MinecraftQuery/MinecraftWebQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public function __construct(public $HOST, public $PORT)
{
}

public function banwardenPardon(PlayerPunishmentType $type, string $victim, string $reason = null)
public function banwardenPardon(PlayerPunishmentType $type, string $victim, string $reason = null, string $admin = null)
{
$payload = [
'type' => $type->value,
'punishment_type' => $type->value,
'victim' => $victim,
'reason' => $reason,
'admin' => $admin,
];
$status = $this->sendQuery('banwarden-pardon', $payload);

Expand Down Expand Up @@ -150,6 +151,11 @@ public function sendQuery($type, array $data = [])

public function makePayload($type, array $data = [])
{
// In data, make sure type and timestamp are not present as they are reserved throw exception if they are.
if (array_key_exists('type', $data) || array_key_exists('timestamp', $data)) {
throw new \Exception('type and timestamp are reserved keys and cannot be used in data.');
}

// Get the API Key and Secret from the plugin settings.
$pluginSettings = app(PluginSettings::class);
$apiKey = $pluginSettings->plugin_api_key;
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"license": "MIT",
"require": {
"php": ">=8.2",
"php": ">=8.3",
"ext-json": "*",
"ext-sockets": "*",
"ext-zip": "*",
Expand Down Expand Up @@ -59,13 +59,14 @@
"require-dev": {
"barryvdh/laravel-debugbar": "^3.14",
"barryvdh/laravel-ide-helper": "^3.2",
"nunomaduro/phpinsights": "^2.12",
"fakerphp/faker": "^1.24",
"laravel/pint": "^1.18",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.5",
"nunomaduro/phpinsights": "^2.12",
"pestphp/pest": "^3.0",
"pestphp/pest-plugin-laravel": "^3.0",
"rector/rector": "^2.0",
"spatie/laravel-ignition": "^2.9"
},
"autoload": {
Expand Down
Loading

0 comments on commit d858db8

Please sign in to comment.