Minor network packet handling tweaks

This commit is contained in:
Anuken
2021-03-04 17:58:28 -05:00
parent d863c971c2
commit c12b9ee3e3
4 changed files with 18 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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. */