mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2026-06-05 17:46:53 +00:00
Replace IP-based auth with XenForo OAuth2
Also, resolves the long standing issues #2 and #3
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package dev.plex.request.impl;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.plex.HTTPDModule;
|
||||
import dev.plex.authentication.AuthenticatedUser;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.request.AbstractServlet;
|
||||
@@ -9,40 +9,31 @@ import dev.plex.request.GetMapping;
|
||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class PunishmentsEndpoint extends AbstractServlet
|
||||
{
|
||||
@GetMapping(endpoint = "/api/punishments/")
|
||||
public String getPunishments(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
String ipAddress = request.getRemoteAddr();
|
||||
if (ipAddress == null)
|
||||
{
|
||||
return punishmentsHTML("An IP address could not be detected. Please ensure you are connecting using IPv4.");
|
||||
}
|
||||
if (request.getPathInfo() == null || request.getPathInfo().equals("/"))
|
||||
{
|
||||
return readFile(this.getClass().getResourceAsStream("/httpd/punishments.html"));
|
||||
}
|
||||
UUID pathUUID;
|
||||
String pathPlexPlayer;
|
||||
|
||||
PlexPlayer punishedPlayer;
|
||||
try
|
||||
{
|
||||
pathUUID = UUID.fromString(request.getPathInfo().replace("/", ""));
|
||||
UUID pathUUID = UUID.fromString(request.getPathInfo().replace("/", ""));
|
||||
punishedPlayer = DataUtils.getPlayer(pathUUID);
|
||||
}
|
||||
catch (java.lang.IllegalArgumentException ignored)
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
pathPlexPlayer = request.getPathInfo().replace("/", "");
|
||||
punishedPlayer = DataUtils.getPlayer(pathPlexPlayer);
|
||||
punishedPlayer = DataUtils.getPlayer(request.getPathInfo().replace("/", ""));
|
||||
}
|
||||
|
||||
final PlexPlayer player = DataUtils.getPlayerByIP(ipAddress);
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
return punishmentsHTML("This player has never joined the server before.");
|
||||
@@ -51,19 +42,13 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
{
|
||||
return punishmentsGoodHTML("This player has been a good boy. They have no punishments!");
|
||||
}
|
||||
if (player == null)
|
||||
{
|
||||
// If the player is null, give it to them without the IPs
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
}
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUuid());
|
||||
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.punishments.access"))
|
||||
{
|
||||
// If the person doesn't have permission, don't return IPs
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
}
|
||||
|
||||
AuthenticatedUser viewer = currentStaff(request);
|
||||
response.setHeader("content-type", "application/json");
|
||||
if (viewer == null)
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
}
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user