From c12b9ee3e3cb1426404476866a5e1cfcd24746ce Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 4 Mar 2021 17:58:28 -0500 Subject: [PATCH] Minor network packet handling tweaks --- .../java/mindustry/annotations/remote/RemoteProcess.java | 4 ++-- core/src/mindustry/core/NetClient.java | 8 ++++++-- core/src/mindustry/core/NetServer.java | 9 ++++++++- core/src/mindustry/net/NetConnection.java | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/annotations/src/main/java/mindustry/annotations/remote/RemoteProcess.java b/annotations/src/main/java/mindustry/annotations/remote/RemoteProcess.java index b3a473795a..6be9c9c2d2 100644 --- a/annotations/src/main/java/mindustry/annotations/remote/RemoteProcess.java +++ b/annotations/src/main/java/mindustry/annotations/remote/RemoteProcess.java @@ -71,12 +71,12 @@ public class RemoteProcess extends BaseProcessor{ //check for static if(!element.is(Modifier.STATIC) || !element.is(Modifier.PUBLIC)){ - err("All @Remote methods must be public and static: ", element); + err("All @Remote methods must be public and static", element); } //can't generate none methods if(annotation.targets() == Loc.none){ - err("A @Remote method's targets() cannot be equal to 'none':", element); + err("A @Remote method's targets() cannot be equal to 'none'", element); } //get and create class entry if needed diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index 0594c3403a..b9fc8037de 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -86,7 +86,7 @@ public class NetClient implements ApplicationListener{ locale = Locale.getDefault().toString(); } - ConnectPacket c = new ConnectPacket(); + var c = new ConnectPacket(); c.name = player.name; c.locale = locale; c.mods = mods.getModStrings(); @@ -188,6 +188,10 @@ public class NetClient implements ApplicationListener{ //called when a server receives a chat message from a player @Remote(called = Loc.server, targets = Loc.client) public static void sendChatMessage(Player player, String message){ + + //do not receive chat messages from clients that are too young or not registered + if(Time.timeSinceMillis(player.con.connectTime) < 500 || !player.con.hasConnected || !player.isAdded()) return; + if(message.length() > maxTextLength){ throw new ValidateException(player, "Player has sent a message above the text limit."); } @@ -198,7 +202,7 @@ public class NetClient implements ApplicationListener{ CommandResponse response = netServer.clientCommands.handleMessage(message, player); if(response.type == ResponseType.noCommand){ //no command to handle message = netServer.admins.filterMessage(player, message); - //supress chat message if it's filtered out + //suppress chat message if it's filtered out if(message == null){ return; } diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index 5054402310..8747e8f00c 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -93,10 +93,14 @@ public class NetServer implements ApplicationListener{ }); net.handleServer(ConnectPacket.class, (con, packet) -> { + if(con.kicked) return; + if(con.address.startsWith("steam:")){ packet.uuid = con.address.substring("steam:".length()); } + con.connectTime = Time.millis(); + String uuid = packet.uuid; byte[] buuid = Base64Coder.decode(uuid); CRC32 crc = new CRC32(); @@ -249,7 +253,8 @@ public class NetServer implements ApplicationListener{ }); net.handleServer(InvokePacket.class, (con, packet) -> { - if(con.player == null) return; + if(con.player == null || con.kicked) return; + try{ RemoteReadServer.readPacket(packet.reader(), packet.type, con.player); }catch(ValidateException e){ @@ -748,6 +753,8 @@ public class NetServer implements ApplicationListener{ @Remote(targets = Loc.client) public static void connectConfirm(Player player){ + if(player.con.kicked) return; + player.add(); if(player.con == null || player.con.hasConnected) return; diff --git a/core/src/mindustry/net/NetConnection.java b/core/src/mindustry/net/NetConnection.java index cf1e47bbbd..02b1c1649d 100644 --- a/core/src/mindustry/net/NetConnection.java +++ b/core/src/mindustry/net/NetConnection.java @@ -19,6 +19,8 @@ public abstract class NetConnection{ public @Nullable Player player; public boolean kicked = false; + /** When this connection was established. */ + public long connectTime = Time.millis(); /** ID of last received client snapshot. */ public int lastReceivedClientSnapshot = -1; /** Timestamp of last received snapshot. */