diff --git a/.github/release-notes.md b/.github/release-notes.md index 2cac040..a4e7356 100644 --- a/.github/release-notes.md +++ b/.github/release-notes.md @@ -8,6 +8,11 @@ Download `custom-links-${VERSION}.pteroext` below, then upload it under **Admin php artisan p:extension:install /path/to/custom-links-${VERSION}.pteroext --enable ``` +### What's new in ${VERSION} + +- New `{server.domain}` placeholder, filled with the server's domain from the Domains extension or its IP when it has none. +- Links look like the panel's own buttons and line up with the other extensions above the console. + Requires Pterodactyl Panel 2.0 (2.0-develop or later) and PHP 8.3+. See the README for features and settings. This is a community extension and is not affiliated with or endorsed by Pterodactyl. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9993786..d676e24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.1.0 + +- New `{server.domain}` placeholder: the server's domain from the Domains extension, or its IP when it has no working domain (or Domains is not installed). +- Links now look exactly like the panel's own outlined buttons, with their icon, so they match the Join and Copy buttons from Connect Buttons and the rest of the console. They are still normal links, so middle-click and open in new tab work. +- The console row has the same 12px gap below it as the other extensions above the console. + ## 1.0.0 - First release. diff --git a/README.md b/README.md index 31ba3d0..2d93311 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Add your own buttons and links to server pages and the dashboard: wikis, Discord - **Three places to show links**: a button row above the server console, extra tabs in the server's menu, and a button row above the server list on the dashboard. - **Per-egg targeting**: show a link on every server, or only on servers using chosen eggs (a map viewer for Rust, a mod list for Minecraft). -- **Placeholders** filled in for each server: `{server.name}`, `{server.ip}`, `{server.port}`, `{server.uuid}`, `{server.identifier}` and `{user.username}`. Values are URL-encoded, so a server name can't change where a link goes. +- **Placeholders** filled in for each server: `{server.name}`, `{server.domain}`, `{server.ip}`, `{server.port}`, `{server.uuid}`, `{server.identifier}` and `{user.username}`. Values are URL-encoded, so a server name can't change where a link goes. +- **`{server.domain}`** is the server's domain from the [Domains](https://github.com/Rustix-Development/pterodactyl-domains) extension, such as `play.example.com`. When the server has no working domain, or Domains is not installed, it is the same as `{server.ip}`. - **Safe links only**: http, https and `steam://` (for one-click joins like `steam://connect/{server.ip}:{server.port}`). Anything else is rejected when saving and again after placeholders are filled in. - **Any icon** from the panel's icon set, an order number, and a choice of opening in a new tab. - **Admin page** at **Admin → Custom Links**. diff --git a/extension.json b/extension.json index 62889c8..fd1d5c9 100644 --- a/extension.json +++ b/extension.json @@ -2,7 +2,7 @@ "$schema": "./node_modules/@pterodactyl/sdk/manifest.schema.json", "id": "custom-links", "name": "Custom Links", - "version": "1.0.0", + "version": "1.1.0", "description": "Add your own buttons and links to server pages and the dashboard: wikis, Discord, map viewers, store pages. Show them on every server or only on chosen eggs.", "author": "RustixDev", "icon": "link", diff --git a/package-lock.json b/package-lock.json index feb3bbd..55be61f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "custom-links", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "custom-links", - "version": "1.0.0", + "version": "1.1.0", "devDependencies": { "@base-ui/react": "^1.6.0", "@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.4.tgz", diff --git a/package.json b/package.json index 55e9292..2b7b0c4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "custom-links", "private": true, - "version": "1.0.0", + "version": "1.1.0", "type": "module", "scripts": { "build": "vite build", diff --git a/src/Models/CustomLink.php b/src/Models/CustomLink.php index 1a43a9e..55db57d 100644 --- a/src/Models/CustomLink.php +++ b/src/Models/CustomLink.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Pterodactyl\Models\Server; use Pterodactyl\Models\User; +use RustixDev\CustomLinks\Support\ServerDomain; /** * @property int $id @@ -59,11 +60,13 @@ public function resolveUrl(User $user, ?Server $server = null): ?string if ($server !== null) { $allocation = $server->allocation; + $ip = $allocation ? ($allocation->ip_alias ?: $allocation->ip) : ''; $values += [ '{server.name}' => $server->name, '{server.uuid}' => $server->uuid, '{server.identifier}' => config('pterodactyl.features.new_server_identifiers') ? $server->identifier : $server->uuidShort, - '{server.ip}' => $allocation ? ($allocation->ip_alias ?: $allocation->ip) : '', + '{server.domain}' => $allocation ? (ServerDomain::forAllocation($server, $allocation) ?? $ip) : '', + '{server.ip}' => $ip, '{server.port}' => $allocation ? (string) $allocation->port : '', ]; } diff --git a/src/Support/ServerDomain.php b/src/Support/ServerDomain.php new file mode 100644 index 0000000..59d1da4 --- /dev/null +++ b/src/Support/ServerDomain.php @@ -0,0 +1,64 @@ +id, $known)) { + $known[$allocation->id] = self::lookup($server, $allocation); + self::$cache[$server] = $known; + } + + return $known[$allocation->id]; + } + + private static function lookup(Server $server, Allocation $allocation): ?string + { + try { + if (! Schema::hasTable(self::TABLE)) { + return null; + } + + $name = DB::table(self::TABLE) + ->where('server_id', $server->id) + ->whereIn('dns_status', self::LIVE) + ->where(function ($query) use ($server, $allocation) { + $query->where('allocation_id', $allocation->id); + if ($allocation->id === $server->allocation_id) { + $query->orWhereNull('allocation_id'); + } + }) + ->orderBy('id') + ->value('name'); + } catch (\Throwable) { + return null; + } + + return is_string($name) && $name !== '' ? $name : null; + } +} diff --git a/src/client/components/LinkRow.tsx b/src/client/components/LinkRow.tsx index 02af943..1ffd607 100644 --- a/src/client/components/LinkRow.tsx +++ b/src/client/components/LinkRow.tsx @@ -1,21 +1,27 @@ import { NamedIcon } from '@pterodactyl/sdk'; import type { ClientLink } from '../api'; -/** A wrapping row of button-styled links. Renders nothing when there are none. */ +/** The core secondary Button's look, on a real link so it can be middle-clicked, copied or opened in a new tab. */ +const SECONDARY_LINK = + 'rxcl:relative rxcl:inline-block rxcl:rounded-sm rxcl:border rxcl:px-4 rxcl:py-2 rxcl:text-sm rxcl:uppercase rxcl:tracking-wide rxcl:no-underline rxcl:transition-colors rxcl:duration-150 rxcl:border-border rxcl:bg-transparent rxcl:text-foreground rxcl:[&:hover]:border-primary rxcl:[&:hover]:bg-primary rxcl:[&:hover]:text-primary-foreground'; + +/** A wrapping row of links styled as secondary buttons. Renders nothing when there are none. */ export default function LinkRow({ links, className = '' }: { links: ClientLink[]; className?: string }) { if (links.length === 0) return null; return ( -