mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-07-01 10:18:26 +00:00
shit
This commit is contained in:
@@ -27,7 +27,6 @@ import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
import dev.brighten.ac.utils.world.WorldInfo;
|
||||
import dev.brighten.loader.LoaderPlugin;
|
||||
import dev.brighten.log.socket.LogSocketManager;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.PackagePrivate;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -62,7 +61,6 @@ public class Anticheat extends LoaderPlugin {
|
||||
private KeepaliveProcessor keepaliveProcessor;
|
||||
private PacketHandler packetHandler;
|
||||
private LoggerManager logManager;
|
||||
public LogSocketManager socketManager;
|
||||
private int currentTick;
|
||||
private Deque<Runnable> onTickEnd = new LinkedList<>();
|
||||
private ServerInjector injector;
|
||||
@@ -118,8 +116,6 @@ public class Anticheat extends LoaderPlugin {
|
||||
this.checkManager = new CheckManager();
|
||||
this.playerRegistry = new PlayerRegistry();
|
||||
this.packetHandler = new PacketHandler();
|
||||
this.socketManager = new LogSocketManager();
|
||||
socketManager.startSockets();
|
||||
logManager = new LoggerManager();
|
||||
|
||||
keepaliveProcessor.start();
|
||||
@@ -158,8 +154,6 @@ public class Anticheat extends LoaderPlugin {
|
||||
ProtocolAPI.INSTANCE = null;
|
||||
tps = null;
|
||||
|
||||
socketManager.shutdownSockets();
|
||||
|
||||
logManager.shutDown();
|
||||
|
||||
Bukkit.getScheduler().cancelTasks(getPluginInstance());
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package dev.brighten.ac.command;
|
||||
|
||||
import co.aikar.commands.*;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import co.aikar.commands.bukkit.contexts.OnlinePlayer;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.logging.Log;
|
||||
import dev.brighten.ac.logging.sql.Query;
|
||||
import dev.brighten.ac.messages.Messages;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
import dev.brighten.ac.utils.Color;
|
||||
@@ -40,6 +38,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -222,51 +221,31 @@ public class AnticheatCommand extends BaseCommand {
|
||||
List<String> logs = new ArrayList<>();
|
||||
|
||||
if(check.equals("none")) {
|
||||
Query.prepare("select * from `logs` where `uuid` = ? limit 500").append(uuid.hashCode()).execute(rs -> {
|
||||
dev.brighten.ac.logging.Log log = Log.builder()
|
||||
.uuid(uuid)
|
||||
.checkId(rs.getString("check"))
|
||||
.data(rs.getString("data"))
|
||||
.vl(rs.getFloat("vl"))
|
||||
.time(rs.getTimestamp("time").getTime())
|
||||
.build();
|
||||
Anticheat.INSTANCE.getLogManager().getLogs(uuid, logsList -> {
|
||||
logsList.forEach(log -> {
|
||||
logs.add("[" + new Timestamp(log.getTime()).toLocalDateTime()
|
||||
.format(DateTimeFormatter.ISO_DATE_TIME) + "] funkemunky failed "
|
||||
+ Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + "(VL: " + log.getVl() + ") {" + log.getData() + "}");
|
||||
});
|
||||
if(logs.size() == 0) {
|
||||
if(check.equals("none")) {
|
||||
sender.sendMessage(Color.Gray + "There are no logs for player \"" + playername + "\"");
|
||||
} else {
|
||||
sender.sendMessage(Color.Gray + " does not have any violations for check \"" + check + "\"");
|
||||
}
|
||||
} else {
|
||||
String url = null;
|
||||
try {
|
||||
url = Pastebin.makePaste(String.join("\n", logs), playername + "'s Logs", Pastebin.Privacy.UNLISTED);
|
||||
|
||||
logs.add("[" + rs.getTimestamp("time").toLocalDateTime()
|
||||
.format(DateTimeFormatter.ISO_DATE_TIME) + "] funkemunky failed "
|
||||
+ Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + "(VL: " + log.getVl() + ") {" + log.getData() + "}");
|
||||
sender.sendMessage(Color.Green + "Logs for " + playername + ": " + Color.White + url);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Query.prepare("select * from `logs` where `uuid` = ? and `check` = ? limit 500")
|
||||
.append(uuid.hashCode()).append(check).execute(rs -> {
|
||||
dev.brighten.ac.logging.Log log = Log.builder()
|
||||
.uuid(uuid)
|
||||
.checkId(rs.getString("check"))
|
||||
.data(rs.getString("data"))
|
||||
.vl(rs.getFloat("vl"))
|
||||
.time(rs.getTimestamp("time").getTime())
|
||||
.build();
|
||||
|
||||
logs.add("[" + rs.getTimestamp("time").toLocalDateTime()
|
||||
.format(DateTimeFormatter.ISO_DATE_TIME) + "] funkemunky failed "
|
||||
+ Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + "(VL: " + log.getVl() + ") {" + log.getData() + "}");
|
||||
});
|
||||
}
|
||||
|
||||
if(logs.size() == 0) {
|
||||
if(check.equals("none")) {
|
||||
sender.sendMessage(Color.Gray + "There are no logs for player \"" + playername + "\"");
|
||||
} else {
|
||||
sender.sendMessage(Color.Gray + " does not have any violations for check \"" + check + "\"");
|
||||
}
|
||||
} else {
|
||||
String url = null;
|
||||
try {
|
||||
url = Pastebin.makePaste(String.join("\n", logs), playername + "'s Logs", Pastebin.Privacy.UNLISTED);
|
||||
|
||||
sender.sendMessage(Color.Green + "Logs for " + playername + ": " + Color.White + url);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package dev.brighten.ac.logging;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import me.mat1337.loader.utils.json.JSONException;
|
||||
import me.mat1337.loader.utils.json.JSONObject;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -13,4 +15,19 @@ public class Log {
|
||||
private long time;
|
||||
private String data;
|
||||
private String checkId;
|
||||
public String toJson() {
|
||||
JSONObject object = new JSONObject();
|
||||
|
||||
try {
|
||||
object.put("uuid", uuid.toString());
|
||||
object.put("vl", vl);
|
||||
object.put("time", time);
|
||||
object.put("data", data);
|
||||
object.put("checkId", checkId);
|
||||
|
||||
return object.toString();
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,24 @@
|
||||
package dev.brighten.ac.logging;
|
||||
|
||||
import com.neovisionaries.ws.client.WebSocket;
|
||||
import com.neovisionaries.ws.client.WebSocketAdapter;
|
||||
import com.neovisionaries.ws.client.WebSocketException;
|
||||
import com.neovisionaries.ws.client.WebSocketFactory;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.logging.sql.Query;
|
||||
import dev.brighten.ac.logging.sql.ResultSetIterator;
|
||||
import dev.brighten.ac.utils.RunUtils;
|
||||
import dev.brighten.log.socket.OutRequest;
|
||||
import dev.brighten.log.socket.RequestType;
|
||||
import dev.brighten.log.utils.EncryptionUtils;
|
||||
import me.mat1337.loader.utils.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Base64;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public class LoggerManager {
|
||||
|
||||
private final Deque<Log> logList = new LinkedList<>();
|
||||
private KeyPair keys;
|
||||
private PublicKey encryptKey;
|
||||
private String license;
|
||||
|
||||
/*
|
||||
* Structure of Log
|
||||
@@ -31,68 +26,41 @@ public class LoggerManager {
|
||||
*/
|
||||
public void init() {
|
||||
// Starting up H2
|
||||
Anticheat.INSTANCE.getLogger().info("Generating RSA...");
|
||||
keys = EncryptionUtils.Companion.geneateRsa();
|
||||
try {
|
||||
Anticheat.INSTANCE.getLogger().info("Sending init request to log server...");
|
||||
OutRequest request = new OutRequest(RequestType.INITIALIZE.toString(), "localhost", null);
|
||||
license = Anticheat.INSTANCE.getPluginInstance().getConfig().getString("license");
|
||||
|
||||
String encoded = Base64.getEncoder().encodeToString(keys.getPublic().getEncoded());
|
||||
System.out.println(encoded);
|
||||
request.getObjects().writeUTF(encoded);
|
||||
|
||||
request.write();
|
||||
|
||||
Anticheat.INSTANCE.getLogger().info("Sent!");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Anticheat.INSTANCE.getSocketManager().onInputReceived(event -> {
|
||||
if(event.getRequest().getHeader().equals(RequestType.INITIALIZE.toString())) {
|
||||
System.out.println("Received key from server!");
|
||||
ObjectInputStream objectStream = event.getRequest().getObjects();
|
||||
Anticheat.INSTANCE.getScheduler().scheduleAtFixedRate(() -> {
|
||||
if(logList.size() > 0) {
|
||||
try {
|
||||
String publicKeyString = objectStream.readUTF();
|
||||
WebSocket socket = new WebSocketFactory().createSocket("ws://port.funkemunky.cc/chat").connect();
|
||||
|
||||
encryptKey = EncryptionUtils.Companion.publicKeyFromString(publicKeyString);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Writing logs");
|
||||
Log log;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
|
||||
oos.writeUTF("LOG_WRITE");
|
||||
oos.writeUTF(license());
|
||||
|
||||
int i = 0;
|
||||
while((log = logList.poll()) != null && i++ < 100) {
|
||||
oos.writeUTF(log.toJson());
|
||||
}
|
||||
|
||||
System.out.println("Wrote " + i + " logs");
|
||||
oos.close();
|
||||
socket.sendBinary(baos.toByteArray());
|
||||
baos.close();
|
||||
|
||||
socket.disconnect();
|
||||
} catch (IOException | WebSocketException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
RunUtils.taskTimerAsync(() -> {
|
||||
System.out.println("Running ping!");
|
||||
|
||||
OutRequest request = new OutRequest(RequestType.PING.toString(),
|
||||
"localhost",
|
||||
encryptKey);
|
||||
|
||||
try {
|
||||
request.getObjects().writeLong(System.currentTimeMillis());
|
||||
request.write();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, 80, 40);
|
||||
|
||||
Anticheat.INSTANCE.socketManager.onInputReceived(event -> {
|
||||
if(event.getRequest().getHeader().equals(RequestType.PING.toString())) {
|
||||
ObjectInputStream objects = event.getRequest().getObjects(keys.getPrivate());
|
||||
|
||||
try {
|
||||
long serverTime = objects.readLong();
|
||||
long extense = objects.readLong();
|
||||
|
||||
long ping = System.currentTimeMillis() - serverTime + extense;
|
||||
|
||||
System.out.println("Ping: " + ping + "ms");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
private String license() {
|
||||
return license;
|
||||
}
|
||||
|
||||
public void insertLog(APlayer player, CheckData checkData, float vl, long time, String data) {
|
||||
@@ -105,8 +73,52 @@ public class LoggerManager {
|
||||
.build());
|
||||
}
|
||||
|
||||
public void runQuery(String query, ResultSetIterator iterator) {
|
||||
Query.prepare(query).execute(iterator);
|
||||
public void getLogs(UUID uuid, Consumer<List<Log>> logsConsumer) {
|
||||
try {
|
||||
WebSocket socket = new WebSocketFactory().createSocket("ws://port.funkemunky.cc/chat").connect();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
|
||||
oos.writeUTF("LOG_REQ_UUID");
|
||||
oos.writeUTF(license());
|
||||
|
||||
oos.writeUTF(uuid.toString());
|
||||
oos.close();
|
||||
System.out.println("Sending binary");
|
||||
socket.sendBinary(baos.toByteArray()).addListener(new WebSocketAdapter() {
|
||||
|
||||
@Override
|
||||
public void onBinaryMessage(WebSocket websocket, byte[] data) throws Exception {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
|
||||
List<Log> logs = new ArrayList<>();
|
||||
while(ois.available() > 0) {
|
||||
String logString = ois.readUTF();
|
||||
JSONObject logObject = new JSONObject(logString);
|
||||
|
||||
logs.add(Log.builder()
|
||||
.vl((float)logObject.getDouble("vl"))
|
||||
.checkId(logObject.getString("checkId"))
|
||||
.data(logObject.getString("data"))
|
||||
.time(logObject.getLong("time"))
|
||||
.uuid(UUID.fromString(logObject.getString("uuid"))).build());
|
||||
}
|
||||
|
||||
logsConsumer.accept(logs);
|
||||
websocket.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
if(socket.isOpen()) System.out.println("Open");
|
||||
else System.out.println("Not open!");
|
||||
} catch(WebSocketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package dev.brighten.ac.packet.handler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.PacketType;
|
||||
import dev.brighten.ac.packet.wrapper.WPacket;
|
||||
import dev.brighten.ac.packet.wrapper.login.WPacketHandshakingInSetProtocol;
|
||||
import dev.brighten.ac.utils.reflections.impl.CraftReflection;
|
||||
import dev.brighten.ac.utils.reflections.impl.MinecraftReflection;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import io.netty.channel.*;
|
||||
import net.minecraft.server.v1_8_R3.PacketLoginInStart;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ModernHandler extends HandlerAbstract {
|
||||
@@ -26,6 +28,7 @@ public class ModernHandler extends HandlerAbstract {
|
||||
private ChannelInboundHandlerAdapter serverChannelHandler;
|
||||
private ChannelInitializer<Channel> beginInitProtocol;
|
||||
private ChannelInitializer<Channel> endInitProtocol;
|
||||
private List<Channel> serverChannels = Lists.newArrayList();
|
||||
|
||||
public ModernHandler() {
|
||||
endInitProtocol = new ChannelInitializer<Channel>() {
|
||||
@@ -64,6 +67,42 @@ public class ModernHandler extends HandlerAbstract {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object mcServer = CraftReflection.getMinecraftServer();
|
||||
Object serverConnection = MinecraftReflection.getServerConnection(mcServer);
|
||||
boolean looking = true;
|
||||
|
||||
// We need to synchronize against this list
|
||||
for (Method m : mcServer.getClass().getMethods()) {
|
||||
if (m.getParameterTypes().length == 0 && m.getReturnType()
|
||||
.isAssignableFrom(MinecraftReflection.serverConnection.getParent())) {
|
||||
try {
|
||||
Object result = m.invoke(mcServer);
|
||||
if (result != null) serverConnection = result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; looking; i++) {
|
||||
List<Object> list = new WrappedClass(serverConnection.getClass()).getFieldByType(List.class, i)
|
||||
.get(serverConnection);
|
||||
|
||||
for (Object item : list) {
|
||||
//if (!ChannelFuture.class.isInstance(item))
|
||||
// break;
|
||||
|
||||
// Channel future that contains the server connection
|
||||
Channel serverChannel = ((ChannelFuture) item).channel();
|
||||
|
||||
serverChannels.add(serverChannel);
|
||||
serverChannel.pipeline().addFirst(serverChannelHandler);
|
||||
Bukkit.getLogger().info("Server channel handler injected (" + serverChannel + ")");
|
||||
looking = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,9 +186,7 @@ public class ModernHandler extends HandlerAbstract {
|
||||
} else if(type == PacketType.LOGIN_HANDSHAKE) {
|
||||
WPacketHandshakingInSetProtocol packet = (WPacketHandshakingInSetProtocol) PacketType.processType(type, msg);
|
||||
|
||||
System.out.println("Received handshake");
|
||||
if(packet.getProtocol() == WPacketHandshakingInSetProtocol.EnumProtocol.LOGIN) {
|
||||
System.out.println("Setting protocol version number " + packet.getVersionNumber());
|
||||
protocolLookup.put(ctx.channel(), packet.getVersionNumber());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user