Added more output types for the uuid endpoint.

This commit is contained in:
flash 2023-08-23 18:06:47 +00:00
parent e31c17dba2
commit 3fde4fab90

View file

@ -36,7 +36,7 @@ final class MojangInterop {
}
public static function registerRoutes(IRouter $router): void {
$router->get('/uuid', fn($response, $request) => self::uuidResolver($request));
$router->get('/uuid', fn($response, $request) => self::uuidResolver($response, $request));
$router->get('/blockedservers', fn($response, $request) => self::proxyBlockServers($response, $request));
// figure out how to proxy these someday to keep online mode working transparently
@ -44,8 +44,17 @@ final class MojangInterop {
$router->post('/session/minecraft/join', fn() => 501);
}
public static function uuidResolver(HttpRequest $request): string {
return (string)self::createOfflinePlayerUUID((string)$request->getParam('name'))->getHex();
public static function uuidResolver(HttpResponseBuilder $response, HttpRequest $request): string {
$response->setTypePlain();
$uuid = self::createOfflinePlayerUUID((string)$request->getParam('name'));
return (string)match((string)$request->getParam('mode')) {
'str' => $uuid->toString(),
'urn' => $uuid->getUrn(),
'raw' => $uuid->getBytes(),
'int' => $uuid->getInteger(),
default => $uuid->getHex(),
};
}
public static function getRequest(string $url, string $userAgent): object {