Minor network packet handling tweaks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user