Minor network packet handling tweaks
This commit is contained in:
@@ -71,12 +71,12 @@ public class RemoteProcess extends BaseProcessor{
|
|||||||
|
|
||||||
//check for static
|
//check for static
|
||||||
if(!element.is(Modifier.STATIC) || !element.is(Modifier.PUBLIC)){
|
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
|
//can't generate none methods
|
||||||
if(annotation.targets() == Loc.none){
|
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
|
//get and create class entry if needed
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class NetClient implements ApplicationListener{
|
|||||||
locale = Locale.getDefault().toString();
|
locale = Locale.getDefault().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectPacket c = new ConnectPacket();
|
var c = new ConnectPacket();
|
||||||
c.name = player.name;
|
c.name = player.name;
|
||||||
c.locale = locale;
|
c.locale = locale;
|
||||||
c.mods = mods.getModStrings();
|
c.mods = mods.getModStrings();
|
||||||
@@ -188,6 +188,10 @@ public class NetClient implements ApplicationListener{
|
|||||||
//called when a server receives a chat message from a player
|
//called when a server receives a chat message from a player
|
||||||
@Remote(called = Loc.server, targets = Loc.client)
|
@Remote(called = Loc.server, targets = Loc.client)
|
||||||
public static void sendChatMessage(Player player, String message){
|
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){
|
if(message.length() > maxTextLength){
|
||||||
throw new ValidateException(player, "Player has sent a message above the text limit.");
|
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);
|
CommandResponse response = netServer.clientCommands.handleMessage(message, player);
|
||||||
if(response.type == ResponseType.noCommand){ //no command to handle
|
if(response.type == ResponseType.noCommand){ //no command to handle
|
||||||
message = netServer.admins.filterMessage(player, message);
|
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){
|
if(message == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,10 +93,14 @@ public class NetServer implements ApplicationListener{
|
|||||||
});
|
});
|
||||||
|
|
||||||
net.handleServer(ConnectPacket.class, (con, packet) -> {
|
net.handleServer(ConnectPacket.class, (con, packet) -> {
|
||||||
|
if(con.kicked) return;
|
||||||
|
|
||||||
if(con.address.startsWith("steam:")){
|
if(con.address.startsWith("steam:")){
|
||||||
packet.uuid = con.address.substring("steam:".length());
|
packet.uuid = con.address.substring("steam:".length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
con.connectTime = Time.millis();
|
||||||
|
|
||||||
String uuid = packet.uuid;
|
String uuid = packet.uuid;
|
||||||
byte[] buuid = Base64Coder.decode(uuid);
|
byte[] buuid = Base64Coder.decode(uuid);
|
||||||
CRC32 crc = new CRC32();
|
CRC32 crc = new CRC32();
|
||||||
@@ -249,7 +253,8 @@ public class NetServer implements ApplicationListener{
|
|||||||
});
|
});
|
||||||
|
|
||||||
net.handleServer(InvokePacket.class, (con, packet) -> {
|
net.handleServer(InvokePacket.class, (con, packet) -> {
|
||||||
if(con.player == null) return;
|
if(con.player == null || con.kicked) return;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
RemoteReadServer.readPacket(packet.reader(), packet.type, con.player);
|
RemoteReadServer.readPacket(packet.reader(), packet.type, con.player);
|
||||||
}catch(ValidateException e){
|
}catch(ValidateException e){
|
||||||
@@ -748,6 +753,8 @@ public class NetServer implements ApplicationListener{
|
|||||||
|
|
||||||
@Remote(targets = Loc.client)
|
@Remote(targets = Loc.client)
|
||||||
public static void connectConfirm(Player player){
|
public static void connectConfirm(Player player){
|
||||||
|
if(player.con.kicked) return;
|
||||||
|
|
||||||
player.add();
|
player.add();
|
||||||
|
|
||||||
if(player.con == null || player.con.hasConnected) return;
|
if(player.con == null || player.con.hasConnected) return;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public abstract class NetConnection{
|
|||||||
public @Nullable Player player;
|
public @Nullable Player player;
|
||||||
public boolean kicked = false;
|
public boolean kicked = false;
|
||||||
|
|
||||||
|
/** When this connection was established. */
|
||||||
|
public long connectTime = Time.millis();
|
||||||
/** ID of last received client snapshot. */
|
/** ID of last received client snapshot. */
|
||||||
public int lastReceivedClientSnapshot = -1;
|
public int lastReceivedClientSnapshot = -1;
|
||||||
/** Timestamp of last received snapshot. */
|
/** Timestamp of last received snapshot. */
|
||||||
|
|||||||
Reference in New Issue
Block a user