Skip to content

Commit 2e01891

Browse files
committed
Account for natural event naming
1 parent 1eee55b commit 2e01891

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

app/Http/Controllers/Api/Remote/ActivityProcessingController.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Carbon\Carbon;
7+
use Illuminate\Support\Str;
78
use Pterodactyl\Models\User;
89
use Webmozart\Assert\Assert;
910
use Pterodactyl\Models\Server;
@@ -31,7 +32,7 @@ public function __invoke(ActivityEventRequest $request)
3132
foreach ($request->input('data') as $datum) {
3233
/** @var \Pterodactyl\Models\Server|null $server */
3334
$server = $servers->get($datum['server']);
34-
if (is_null($server) || is_null($event = $this->event($datum['event']))) {
35+
if (is_null($server) || !Str::startsWith($datum['event'], 'server:')) {
3536
continue;
3637
}
3738

@@ -53,7 +54,7 @@ public function __invoke(ActivityEventRequest $request)
5354

5455
$log = [
5556
'ip' => empty($datum['ip']) ? '127.0.0.1' : $datum['ip'],
56-
'event' => $event,
57+
'event' => $datum['event'],
5758
'properties' => json_encode($datum['metadata'] ?? []),
5859
// We have to change the time to the current timezone due to the way Laravel is handling
5960
// the date casting internally. If we just leave it in UTC it ends up getting double-cast
@@ -89,27 +90,4 @@ public function __invoke(ActivityEventRequest $request)
8990
ActivityLogSubject::insert($batch);
9091
}
9192
}
92-
93-
/**
94-
* Takes an event from Wings and converts it into the expected event type on
95-
* the Panel. If no matching event type can be deduced, null is returned and
96-
* the event won't be logged.
97-
*/
98-
protected function event(string $input): ?string
99-
{
100-
switch ($input) {
101-
case 'console_command':
102-
return 'server:console.command';
103-
case 'power_start':
104-
return 'server:power.start';
105-
case 'power_stop':
106-
return 'server:power.stop';
107-
case 'power_restart':
108-
return 'server:power.restart';
109-
case 'power_kill':
110-
return 'server:power.kill';
111-
default:
112-
return null;
113-
}
114-
}
11593
}

0 commit comments

Comments
 (0)