Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Show a countdown to each server's next wipe on its console page, with an optional public page for Discord and websites.

When Wipe & Season Manager is installed and a server has an enabled wipe plan, the countdown, the public page and its Discord preview follow that plan. Each schedule has its own time zone, so wipes stay at the same local time across daylight saving. See the changelog for everything in this release.

## Install

Download `next-wipe-${VERSION}.pteroext` below, then upload it under **Admin → Extensions** and enable it. From a terminal instead:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.1.0

- Works with Wipe & Season Manager. When that extension is installed and the server has an enabled plan, the countdown, the public page and its Discord link preview show that plan's next wipe, name and time zone, so they always match the Wipes tab. Skipping a wipe or changing a plan there updates them too. Without a plan, Next Wipe uses its own schedule as before.
- While a plan drives the countdown, the Edit button is replaced by a Wipes button that opens the server's Wipes tab, and a Public page button that turns the public page on or off.
- Each schedule now has a time zone. A 19:00 London wipe stays at 19:00 London time when the clocks change. New schedules start in your browser's time zone; existing schedules keep UTC until you change them.
- Subusers with Wipe & Season Manager's manage permission can now change the wipe schedule too.
- The console card matches the other console blocks: one row, standard buttons and spacing.
- The public page shows the wipe time in the server's time zone as well as the visitor's, and includes a link preview for Discord. Its JSON adds `timezone` and `next_local`.

## 1.0.0

- First release.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ Show a countdown to each server's next wipe on its console page, with an optiona

## Features

- **Countdown on the console page**: "Map wipe · Every week, in 3d 4h 12m" with the date in each viewer's own time zone. Everyone who can see the server sees it.
- **Countdown on the console page**: "Map wipe · Every week · Europe/London, in 3d 4h 12m" with the date in each viewer's own time zone, and in the schedule's time zone when that is different. Everyone who can see the server sees it.
- **Repeating schedules**: once, every week, every two weeks, every month on the same day, or the first Thursday of each month (Rust's forced wipe). The next wipe is worked out automatically.
- **Subuser permission**: owners can manage the schedule, and subusers need the **Next Wipe → manage** permission to change it.
- **Public page (opt-in)**: a link anyone can open, for Discord or your website, showing only the server name and wipe time. It can be embedded in an iframe, and adding `?format=json` returns the time for bots. Turning the page off makes the link stop working; turning it back on restores the same link.
- **Time zones**: each schedule has its own time zone (new ones start in your browser's), and the wipe stays at the same local time when the clocks change for daylight saving.
- **Works with Wipe & Season Manager**: when that extension is installed and the server has an enabled wipe plan, the countdown, the public page and its Discord preview follow the plan's next wipe (the earliest one when there are several), with its name and time zone. Skipping or running a wipe there updates them. The Edit button becomes a **Wipes** button that opens the server's Wipes tab, and a **Public page** button turns the public page on or off. With no plan, Next Wipe uses its own schedule.
- **Subuser permission**: owners can manage the schedule, and subusers need the **Next Wipe → manage** or **Wipe & Season Manager → manage** permission to change it.
- **Public page (opt-in)**: a link anyone can open, for Discord or your website, showing only the server name and wipe time. Pasted into Discord it shows a preview with the next wipe. It can be embedded in an iframe, and adding `?format=json` returns the time for bots (`next_at`, `next_unix`, `timezone`, `next_local`). Turning the page off makes the link stop working; turning it back on restores the same link.

## API

| Method | Path | Who |
|---|---|---|
| GET | `/api/client/servers/{server}/extensions/next-wipe/wipe` | Anyone who can see the server |
| PUT, DELETE | `/api/client/servers/{server}/extensions/next-wipe/wipe` | Owner, admins, subusers with `ext.next-wipe.manage` |
| PUT, DELETE | `/api/client/servers/{server}/extensions/next-wipe/wipe` | Owner, admins, subusers with `ext.next-wipe.manage` or `ext.wipe-season-manager.manage` |
| PUT | `/api/client/servers/{server}/extensions/next-wipe/wipe/public` | Same as above; turns only the public page on or off |
| GET | `/extensions/next-wipe/s/{token}` | Anyone, when the server's public page is on (`?format=json` for JSON) |

## Requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('ext_next_wipe_schedules', function (Blueprint $table) {
// The calendar is read in this zone, so a 19:00 wipe stays at 19:00 local time across daylight saving.
$table->string('timezone', 64)->default('UTC')->after('repeat');
});
}

public function down(): void
{
Schema::table('ext_next_wipe_schedules', function (Blueprint $table) {
$table->dropColumn('timezone');
});
}
};
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "./node_modules/@pterodactyl/sdk/manifest.schema.json",
"id": "next-wipe",
"name": "Next Wipe",
"version": "1.0.0",
"version": "1.1.0",
"description": "Show a countdown to each server's next wipe on its console page, with an optional public page for Discord and websites.",
"author": "RustixDev",
"icon": "calendar-clock",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "next-wipe",
"private": true,
"version": "1.0.0",
"version": "1.1.0",
"type": "module",
"scripts": {
"build": "vite build",
Expand Down
15 changes: 13 additions & 2 deletions resources/views/public.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $label }} · {{ $server }}</title>
@php($summary = $next_local ? 'Next wipe: '.$next_local : 'No wipe scheduled')
<meta name="description" content="{{ $summary }}">
{{-- Discord and other sites build their link preview from these. --}}
<meta property="og:type" content="website">
<meta property="og:title" content="{{ $server }} · {{ $label }}">
<meta property="og:description" content="{{ $summary }}">
<meta name="theme-color" content="#3b82f6">
<style>
:root { color-scheme: light dark; --bg: #f4f5f7; --fg: #1d2330; --muted: #5d6576; --card: #ffffff; --line: #dfe2e8; }
@media (prefers-color-scheme: dark) { :root { --bg: #1b1f27; --fg: #eef0f4; --muted: #9aa3b2; --card: #252a34; --line: #343a46; } }
Expand All @@ -12,6 +19,7 @@
main { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; text-align: center; }
h1 { margin: 0 0 4px; font-size: 1rem; font-weight: 600; overflow-wrap: anywhere; }
p { margin: 0; color: var(--muted); font-size: .9rem; }
.zone { margin-top: 4px; font-size: .8rem; }
.count { margin: 16px 0 8px; font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 700; font-variant-numeric: tabular-nums; }
</style>
</head>
Expand All @@ -21,7 +29,8 @@
<p>{{ $label }}</p>
@if ($next_unix)
<div class="count" id="count" data-at="{{ $next_unix }}">{{ $next_at }}</div>
<p id="when">{{ $next_at }} UTC</p>
<p id="when">{{ $next_local }}</p>
<p class="zone" id="zone" hidden>{{ $next_local }}</p>
@else
<div class="count">No wipe scheduled</div>
@endif
Expand All @@ -31,7 +40,9 @@
(function () {
var el = document.getElementById('count');
var at = Number(el.dataset.at) * 1000;
document.getElementById('when').textContent = new Date(at).toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'short' });
// The visitor's own time; the line under it keeps the server's time zone.
document.getElementById('when').textContent = new Date(at).toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'short' }) + ' (your time)';
document.getElementById('zone').hidden = false;
function tick() {
var s = Math.max(0, Math.floor((at - Date.now()) / 1000));
var d = Math.floor(s / 86400), h = Math.floor(s % 86400 / 3600), m = Math.floor(s % 3600 / 60);
Expand Down
4 changes: 3 additions & 1 deletion routes/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use Illuminate\Support\Facades\Route;
use RustixDev\NextWipe\Http\Controllers\ServerWipeController;

// Anyone who can see the server sees the countdown; changing it needs ext.next-wipe.manage.
// Anyone who can see the server sees the countdown; changing it needs
// ext.next-wipe.manage or ext.wipe-season-manager.manage.
Route::get('/wipe', [ServerWipeController::class, 'show']);
Route::put('/wipe', [ServerWipeController::class, 'update']);
Route::put('/wipe/public', [ServerWipeController::class, 'updatePublic']);
Route::delete('/wipe', [ServerWipeController::class, 'destroy']);
15 changes: 11 additions & 4 deletions src/Http/Controllers/PublicWipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use RustixDev\NextWipe\Models\WipeSchedule;
use RustixDev\NextWipe\Support\UpcomingWipe;
use Symfony\Component\HttpFoundation\Response;

/** The opt-in public page, for Discord bots and websites. Shows the server name and wipe time only. */
/**
* The opt-in public page, for Discord and websites. Shows the server name and wipe
* time only. When Wipe & Season Manager has a plan for the server, its next wipe is shown.
*/
class PublicWipeController
{
public function show(Request $request, string $token): Response
{
$schedule = WipeSchedule::query()->with('server:id,name')->where('public_token', $token)->where('public', true)->firstOrFail();
$next = $schedule->next();
$upcoming = UpcomingWipe::forServer($schedule->server_id, $schedule);
$next = $upcoming?->nextAt;

$payload = [
'server' => $schedule->server->name,
'label' => $schedule->label,
'label' => $upcoming->label ?? $schedule->label,
'next_at' => $next?->toIso8601String(),
'next_unix' => $next?->getTimestamp(),
'repeat' => $schedule->repeat,
'repeat' => $upcoming->repeat ?? $schedule->repeat,
'timezone' => $upcoming->timezone ?? 'UTC',
'next_local' => $upcoming?->localDescription(),
];

$headers = ['Cache-Control' => 'public, max-age=60', 'Access-Control-Allow-Origin' => '*'];
Expand Down
87 changes: 76 additions & 11 deletions src/Http/Controllers/ServerWipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace RustixDev\NextWipe\Http\Controllers;

use Carbon\CarbonImmutable;
use DateTimeZone;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand All @@ -10,50 +12,113 @@
use Pterodactyl\Models\Server;
use RustixDev\NextWipe\Models\WipeSchedule;
use RustixDev\NextWipe\Support\NextOccurrence;
use RustixDev\NextWipe\Support\UpcomingWipe;
use RustixDev\NextWipe\Support\WipeSeasonManager;

class ServerWipeController
{
public const string PERMISSION = 'ext.next-wipe.manage';

public function show(Request $request, Server $server): JsonResponse
{
$schedule = WipeSchedule::query()->where('server_id', $server->id)->first();
$canManage = $request->user()->can('ext.next-wipe.manage', $server);

return new JsonResponse([
'data' => $schedule?->toPayload($canManage),
'can_manage' => $canManage,
]);
return new JsonResponse($this->payload($request, $server, $schedule));
}

public function update(Request $request, Server $server): JsonResponse
{
abort_unless($request->user()->can('ext.next-wipe.manage', $server), 403);
$this->authorize($request, $server);

$data = $request->validate([
'label' => ['required', 'string', 'max:60'],
'anchor_at' => ['required', 'date'],
// The wall-clock time in `timezone`; `anchor_at` (an exact time) is still accepted from older clients.
'anchor_local' => ['required_without:anchor_at', 'date_format:Y-m-d\TH:i'],
'anchor_at' => ['required_without:anchor_local', 'date'],
'timezone' => ['nullable', 'string', 'max:64', 'timezone:all_with_bc'],
'repeat' => ['required', Rule::in(NextOccurrence::REPEATS)],
'public' => ['boolean'],
], [], ['anchor_at' => 'next wipe', 'repeat' => 'repeat']);
], [], ['anchor_local' => 'next wipe', 'anchor_at' => 'next wipe', 'repeat' => 'repeat', 'timezone' => 'time zone']);

$timezone = $data['timezone'] ?? 'UTC';
$anchor = isset($data['anchor_local'])
? CarbonImmutable::createFromFormat('Y-m-d\TH:i', $data['anchor_local'], new DateTimeZone($timezone))
: CarbonImmutable::parse($data['anchor_at']);

$schedule = WipeSchedule::query()->firstOrNew(['server_id' => $server->id]);
$schedule->fill([
'label' => $data['label'],
'anchor_at' => $data['anchor_at'],
'anchor_at' => $anchor->utc(),
'repeat' => $data['repeat'],
'timezone' => $timezone,
'public' => (bool) ($data['public'] ?? false),
]);
$schedule->public_token ??= Str::random(32);
$schedule->save();

return new JsonResponse(['data' => $schedule->toPayload(true), 'can_manage' => true]);
return new JsonResponse($this->payload($request, $server, $schedule));
}

/** Turn the public page on or off on its own, for servers whose wipes come from Wipe & Season Manager. */
public function updatePublic(Request $request, Server $server): JsonResponse
{
$this->authorize($request, $server);
$data = $request->validate(['public' => ['required', 'boolean']]);

$schedule = WipeSchedule::query()->firstOrNew(['server_id' => $server->id]);
if (! $schedule->exists) {
// Only the public page is used while Wipe & Season Manager has a plan.
$schedule->fill(['label' => 'Wipe', 'anchor_at' => CarbonImmutable::now()->startOfMinute(), 'repeat' => 'none', 'timezone' => 'UTC']);
}
$schedule->public = (bool) $data['public'];
$schedule->public_token ??= Str::random(32);
$schedule->save();

return new JsonResponse($this->payload($request, $server, $schedule));
}

public function destroy(Request $request, Server $server): Response
{
abort_unless($request->user()->can('ext.next-wipe.manage', $server), 403);
$this->authorize($request, $server);

WipeSchedule::query()->where('server_id', $server->id)->delete();

return response()->noContent();
}

/** @return array<string, mixed> */
private function payload(Request $request, Server $server, ?WipeSchedule $schedule): array
{
$canManage = $this->canManage($request, $server);
$upcoming = UpcomingWipe::forServer($server->id, $schedule);

return [
'data' => $upcoming ? [
'source' => $upcoming->source,
'label' => $upcoming->label,
'repeat' => $upcoming->repeat,
'timezone' => $upcoming->timezone,
'next_at' => $upcoming->nextAt?->toIso8601String(),
] : null,
'schedule' => $canManage ? $schedule?->toSettings() : null,
'public' => (bool) $schedule?->public,
'public_url' => $canManage ? $schedule?->publicUrl() : null,
'can_manage' => $canManage,
// Whether this user can open the server's Wipes tab.
'can_manage_plans' => WipeSeasonManager::available() && $request->user()->can(WipeSeasonManager::PERMISSION, $server),
];
}

/** Next Wipe's own permission, or Wipe & Season Manager's, lets a subuser change the schedule. */
private function canManage(Request $request, Server $server): bool
{
$user = $request->user();

return $user->can(self::PERMISSION, $server) || $user->can(WipeSeasonManager::PERMISSION, $server);
}

private function authorize(Request $request, Server $server): void
{
abort_unless($this->canManage($request, $server), 403);
}
}
27 changes: 18 additions & 9 deletions src/Models/WipeSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @property string $label
* @property CarbonImmutable $anchor_at
* @property string $repeat
* @property string $timezone
* @property bool $public
* @property string|null $public_token
* @property Server $server
Expand All @@ -22,7 +23,9 @@ class WipeSchedule extends Model
{
protected $table = 'ext_next_wipe_schedules';

protected $fillable = ['server_id', 'label', 'anchor_at', 'repeat', 'public', 'public_token'];
protected $fillable = ['server_id', 'label', 'anchor_at', 'repeat', 'timezone', 'public', 'public_token'];

protected $attributes = ['timezone' => 'UTC'];

protected function casts(): array
{
Expand All @@ -39,21 +42,27 @@ public function server(): BelongsTo

public function next(?CarbonImmutable $now = null): ?CarbonImmutable
{
return NextOccurrence::after($this->anchor_at->utc(), $this->repeat, ($now ?? CarbonImmutable::now())->utc());
return NextOccurrence::after($this->anchor_at->utc(), $this->repeat, ($now ?? CarbonImmutable::now())->utc(), $this->timezone ?: 'UTC');
}

/** @return array<string, mixed> */
public function toPayload(bool $withToken): array
/** The schedule's own settings, for the edit form. */
public function toSettings(): array
{
$zone = $this->timezone ?: 'UTC';
// The form shows the next wipe (or the first one) in the schedule's own zone.
$at = ($this->next() ?? $this->anchor_at)->setTimezone($zone);

return [
'label' => $this->label,
'anchor_at' => $this->anchor_at->utc()->toIso8601String(),
'anchor_local' => $at->format('Y-m-d\TH:i'),
'repeat' => $this->repeat,
'next_at' => $this->next()?->toIso8601String(),
'public' => $this->public,
'public_url' => $withToken && $this->public && $this->public_token
? url('/extensions/next-wipe/s/'.$this->public_token)
: null,
'timezone' => $zone,
];
}

public function publicUrl(): ?string
{
return $this->public && $this->public_token ? url('/extensions/next-wipe/s/'.$this->public_token) : null;
}
}
1 change: 1 addition & 0 deletions src/NextWipeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function boot(): void
$this->loadExtensionViews();

$this->registerPermissions('Next Wipe', [
// Subusers with Wipe & Season Manager's manage permission can change it too.
'manage' => 'Set the server\'s wipe schedule and turn its public page on or off.',
]);
}
Expand Down
Loading
Loading