Added version check, fixed chat being open in singleplayer
This commit is contained in:
@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.async.AsyncExecutor;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.net.Packets.Connect;
|
||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBuilder;
|
||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||
@@ -19,6 +20,8 @@ import io.anuke.ucore.function.Consumer;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Net{
|
||||
public static final int version = 9;
|
||||
|
||||
private static boolean server;
|
||||
private static boolean active;
|
||||
private static boolean clientLoaded;
|
||||
@@ -79,8 +82,8 @@ public class Net{
|
||||
}
|
||||
|
||||
/**Kick a specified connection from the server.*/
|
||||
public static void kickConnection(int id){
|
||||
serverProvider.kick(id);
|
||||
public static void kickConnection(int id, KickReason reason){
|
||||
serverProvider.kick(id, reason);
|
||||
}
|
||||
|
||||
/**Returns a list of all connections IDs.*/
|
||||
@@ -249,7 +252,7 @@ public class Net{
|
||||
/**Return all connected users.*/
|
||||
Array<? extends NetConnection> getConnections();
|
||||
/**Kick a certain connection.*/
|
||||
void kick(int connection);
|
||||
void kick(int connection, KickReason reason);
|
||||
/**Returns the ping for a certain connection.*/
|
||||
int getPingFor(NetConnection connection);
|
||||
/**Register classes to be sent.*/
|
||||
|
||||
@@ -19,14 +19,10 @@ import io.anuke.ucore.entities.Entities;
|
||||
import java.io.*;
|
||||
|
||||
public class NetworkIO {
|
||||
private static final int fileVersionID = 16;
|
||||
|
||||
public static void write(int playerID, ByteArray upgrades, OutputStream os){
|
||||
|
||||
try(DataOutputStream stream = new DataOutputStream(os)){
|
||||
|
||||
//--META--
|
||||
stream.writeInt(fileVersionID); //version id
|
||||
stream.writeFloat(Timers.time()); //timer time
|
||||
stream.writeLong(TimeUtils.millis()); //timestamp
|
||||
|
||||
@@ -151,17 +147,11 @@ public class NetworkIO {
|
||||
public static void load(InputStream is){
|
||||
|
||||
try(DataInputStream stream = new DataInputStream(is)){
|
||||
|
||||
int version = stream.readInt();
|
||||
float timerTime = stream.readFloat();
|
||||
long timestamp = stream.readLong();
|
||||
|
||||
Timers.resetTime(timerTime + (TimeUtils.timeSinceMillis(timestamp) / 1000f) * 60f);
|
||||
|
||||
if(version != fileVersionID){
|
||||
throw new RuntimeException("Netcode version mismatch!");
|
||||
}
|
||||
|
||||
//general state
|
||||
byte mode = stream.readByte();
|
||||
byte mapid = stream.readByte();
|
||||
|
||||
@@ -44,11 +44,13 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class ConnectPacket implements Packet{
|
||||
public int version;
|
||||
public String name;
|
||||
public boolean android;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(Net.version);
|
||||
buffer.put((byte)name.getBytes().length);
|
||||
buffer.put(name.getBytes());
|
||||
buffer.put(android ? (byte)1 : 0);
|
||||
@@ -56,6 +58,7 @@ public class Packets {
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
version = buffer.getInt();
|
||||
byte length = buffer.get();
|
||||
byte[] bytes = new byte[length];
|
||||
buffer.get(bytes);
|
||||
@@ -394,7 +397,7 @@ public class Packets {
|
||||
}
|
||||
|
||||
public enum KickReason{
|
||||
kick, invalidPassword
|
||||
kick, invalidPassword, outdated
|
||||
}
|
||||
|
||||
public static class UpgradePacket implements Packet{
|
||||
|
||||
Reference in New Issue
Block a user