mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 20:21:45 +01:00
Compresses the data before it's sent with GZIP, does not support browsers who don't support GZIP, because every browser which was downloaded in the last 10 years supports it
This commit is contained in:
parent
3fc0abc4f1
commit
7e1e7d80e9
@ -42,9 +42,12 @@ public class PlanGamemodeChangeListener implements Listener {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = event.getPlayer();
|
||||
UUID uuid = p.getUniqueId();
|
||||
String gameMode = event.getNewGameMode().name();
|
||||
long time = MiscUtils.getTime();
|
||||
|
||||
handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.GM, time, event.getNewGameMode().name(), p.getWorld().getName()));
|
||||
}
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ public class PlanPlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.endSession(uuid);
|
||||
|
||||
Log.debug(uuid + ": PlayerQuitEvent");
|
||||
long time = MiscUtils.getTime();
|
||||
boolean banned = player.isBanned();
|
||||
@ -116,6 +117,7 @@ public class PlanPlayerListener implements Listener {
|
||||
|
||||
handler.addToPool(new LogoutInfo(uuid, time, banned, gm.name(), handler.getSession(uuid), worldName));
|
||||
handler.saveCachedData(uuid);
|
||||
|
||||
Log.debug(uuid + ": PlayerQuitEvent_END");
|
||||
}
|
||||
|
||||
@ -131,10 +133,13 @@ public class PlanPlayerListener implements Listener {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
handler.endSession(uuid);
|
||||
Log.debug(uuid + ": PlayerKickEvent");
|
||||
|
||||
long time = MiscUtils.getTime();
|
||||
boolean banned = player.isBanned();
|
||||
Gamemode gm = Gamemode.wrap(player.getGameMode());
|
||||
@ -143,6 +148,7 @@ public class PlanPlayerListener implements Listener {
|
||||
handler.addToPool(new LogoutInfo(uuid, time, banned, gm.name(), handler.getSession(uuid), worldName));
|
||||
handler.addToPool(new KickInfo(uuid));
|
||||
handler.saveCachedData(uuid);
|
||||
|
||||
Log.debug(uuid + ": PlayerKickEvent_END");
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,17 @@ public class PlanWorldChangeListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
|
||||
String previousWorld = event.getFrom().getName();
|
||||
String worldName = p.getWorld().getName();
|
||||
if (previousWorld.equals(worldName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID uuid = p.getUniqueId();
|
||||
String gameMode = p.getGameMode().name();
|
||||
long time = MiscUtils.getTime();
|
||||
handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.WORLD, time, p.getGameMode().name(), p.getWorld().getName()));
|
||||
|
||||
handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.WORLD, time, gameMode, worldName));
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -65,6 +66,7 @@ public class WebServer {
|
||||
if (enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.info(Phrase.WEBSERVER_INIT.toString());
|
||||
try {
|
||||
usingHttps = startHttpsServer();
|
||||
@ -82,24 +84,28 @@ public class WebServer {
|
||||
try {
|
||||
URI uri = exchange.getRequestURI();
|
||||
String target = uri.toString();
|
||||
|
||||
Headers responseHeaders = exchange.getResponseHeaders();
|
||||
responseHeaders.set("Content-Type", "text/html;");
|
||||
WebUser user = null;
|
||||
|
||||
if (usingHttps) {
|
||||
user = getUser(exchange.getRequestHeaders());
|
||||
|
||||
// Prompt authorization
|
||||
if (user == null) {
|
||||
|
||||
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
|
||||
}
|
||||
}
|
||||
|
||||
responseHeaders.set("Content-Encoding", "gzip");
|
||||
|
||||
Response response = getResponse(target, user);
|
||||
|
||||
String content = response.getContent();
|
||||
exchange.sendResponseHeaders(response.getCode(), 0);
|
||||
|
||||
try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody());
|
||||
try (GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
|
||||
byte[] buffer = new byte[2048];
|
||||
int count;
|
||||
@ -115,6 +121,7 @@ public class WebServer {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
|
||||
server.start();
|
||||
|
||||
@ -133,18 +140,21 @@ public class WebServer {
|
||||
if (Verify.isEmpty(authorization)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String auth = authorization.get(0);
|
||||
if (auth.contains("Basic ")) {
|
||||
auth = auth.split(" ")[1];
|
||||
} else {
|
||||
throw new IllegalArgumentException("Wrong format of Auth");
|
||||
}
|
||||
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
byte[] decoded = decoder.decode(auth);
|
||||
String[] userInfo = new String(decoded).split(":");
|
||||
if (userInfo.length != 2) {
|
||||
throw new IllegalArgumentException("User and Password not specified");
|
||||
}
|
||||
|
||||
String user = userInfo[0];
|
||||
String passwordRaw = userInfo[1];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user