mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-04 15:27:19 +07:00
Fixed port bug, possible random disconnect fix
This commit is contained in:
@ -70,6 +70,7 @@ text.joingame.byip=Join by IP...
|
||||
text.joingame.title=Join Game
|
||||
text.joingame.ip=IP:
|
||||
text.disconnect=Disconnected.
|
||||
text.disconnect.data=Failed to load world data!
|
||||
text.connecting=[accent]Connecting...
|
||||
text.connecting.data=[accent]Loading world data...
|
||||
text.connectfail=[crimson]Failed to connect to server: [orange]{0}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#Autogenerated file. Do not modify.
|
||||
#Thu Mar 15 12:29:06 EDT 2018
|
||||
#Thu Mar 15 12:52:13 EDT 2018
|
||||
version=release
|
||||
androidBuildCode=388
|
||||
name=Mindustry
|
||||
|
@ -40,10 +40,10 @@ public class NetClient extends Module {
|
||||
|
||||
private Timer timer = new Timer(5);
|
||||
private boolean connecting = false;
|
||||
private boolean gotData = false;
|
||||
private boolean kicked = false;
|
||||
private IntSet recieved = new IntSet();
|
||||
private IntMap<Entity> recent = new IntMap<>();
|
||||
private float timeoutTime = 0f; //data timeout counter
|
||||
|
||||
public NetClient(){
|
||||
|
||||
@ -53,8 +53,8 @@ public class NetClient extends Module {
|
||||
Net.setClientLoaded(false);
|
||||
recieved.clear();
|
||||
recent.clear();
|
||||
timeoutTime = 0f;
|
||||
connecting = true;
|
||||
gotData = false;
|
||||
kicked = false;
|
||||
|
||||
ui.chatfrag.clearMessages();
|
||||
@ -77,14 +77,6 @@ public class NetClient extends Module {
|
||||
}
|
||||
|
||||
Net.send(c, SendMode.tcp);
|
||||
|
||||
Timers.runTask(dataTimeout, () -> {
|
||||
if (!gotData) {
|
||||
Log.err("Failed to load data!");
|
||||
ui.loadfrag.hide();
|
||||
Net.disconnect();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Net.handleClient(Disconnect.class, packet -> {
|
||||
@ -105,8 +97,6 @@ public class NetClient extends Module {
|
||||
NetworkIO.loadWorld(data.stream);
|
||||
player.set(world.getSpawnX(), world.getSpawnY());
|
||||
|
||||
gotData = true;
|
||||
|
||||
finishConnecting();
|
||||
});
|
||||
|
||||
@ -123,7 +113,7 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handleClient(SyncPacket.class, packet -> {
|
||||
if (!gotData) return;
|
||||
if (connecting) return;
|
||||
int players = 0;
|
||||
int enemies = 0;
|
||||
|
||||
@ -180,9 +170,8 @@ public class NetClient extends Module {
|
||||
}
|
||||
});
|
||||
|
||||
Net.handleClient(BreakPacket.class, (packet) -> {
|
||||
Placement.breakBlock(packet.x, packet.y, true, Timers.get("breakblocksound", 10));
|
||||
});
|
||||
Net.handleClient(BreakPacket.class, (packet) ->
|
||||
Placement.breakBlock(packet.x, packet.y, true, Timers.get("breakblocksound", 10)));
|
||||
|
||||
Net.handleClient(EntitySpawnPacket.class, packet -> {
|
||||
EntityGroup group = packet.group;
|
||||
@ -246,7 +235,7 @@ public class NetClient extends Module {
|
||||
kicked = true;
|
||||
Net.disconnect();
|
||||
state.set(State.menu);
|
||||
ui.showError("$text.server.kicked." + packet.reason.name());
|
||||
if(!packet.reason.quiet) ui.showError("$text.server.kicked." + packet.reason.name());
|
||||
ui.loadfrag.hide();
|
||||
});
|
||||
|
||||
@ -316,16 +305,22 @@ public class NetClient extends Module {
|
||||
if(!Net.client()) return;
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
if(gotData) sync();
|
||||
if(!connecting) sync();
|
||||
}else if(!connecting){
|
||||
Net.disconnect();
|
||||
}else{ //...must be connecting
|
||||
timeoutTime += Timers.delta();
|
||||
if(timeoutTime > dataTimeout){
|
||||
Log.err("Failed to load data!");
|
||||
ui.loadfrag.hide();
|
||||
kicked = true;
|
||||
ui.showError("$text.disconnect.data");
|
||||
Net.disconnect();
|
||||
timeoutTime = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasData(){
|
||||
return gotData;
|
||||
}
|
||||
|
||||
public boolean isConnecting(){
|
||||
return connecting;
|
||||
}
|
||||
|
@ -377,7 +377,14 @@ public class Packets {
|
||||
}
|
||||
|
||||
public enum KickReason{
|
||||
kick, invalidPassword, clientOutdated, serverOutdated, banned
|
||||
kick, invalidPassword, clientOutdated, serverOutdated, banned, gameover(true);
|
||||
public final boolean quiet;
|
||||
|
||||
KickReason(){ quiet = false; }
|
||||
|
||||
KickReason(boolean quiet){
|
||||
this.quiet = quiet;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpgradePacket implements Packet{
|
||||
|
@ -130,8 +130,7 @@ public class DebugFragment implements Fragment {
|
||||
Net.client() ?
|
||||
"chat.open: " + ui.chatfrag.chatOpen() + "\n" +
|
||||
"chat.messages: " + ui.chatfrag.getMessagesSize() + "\n" +
|
||||
"client.connecting: " + netClient.isConnecting() + "\n" +
|
||||
"client.hasdata: " + netClient.hasData() : "",
|
||||
"client.connecting: " + netClient.isConnecting() + "\n" : "",
|
||||
"players: " + playerGroup.size(),
|
||||
"enemies: " + enemyGroup.size(),
|
||||
"tiles: " + tileGroup.size(),
|
||||
|
@ -11,6 +11,7 @@ import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.net.Packets.ChatPacket;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
@ -75,25 +76,26 @@ public class ServerControl extends Module {
|
||||
Events.on(GameOverEvent.class, () -> {
|
||||
info("Game over!");
|
||||
|
||||
Timers.runTask(10f, () -> {
|
||||
for(NetConnection connection : Net.getConnections()){
|
||||
Net.kickConnection(connection.id, KickReason.gameover);
|
||||
}
|
||||
|
||||
if (mode != ShuffleMode.off) {
|
||||
Array<Map> maps = mode == ShuffleMode.both ? world.maps().getAllMaps() :
|
||||
mode == ShuffleMode.normal ? world.maps().getDefaultMaps() : world.maps().getCustomMaps();
|
||||
|
||||
Map previous = world.getMap();
|
||||
Map map = previous;
|
||||
while (map == previous || !map.visible) map = maps.random();
|
||||
|
||||
info("Selected next map to be {0}.", map.name);
|
||||
state.set(State.playing);
|
||||
logic.reset();
|
||||
world.loadMap(map);
|
||||
}else{
|
||||
state.set(State.menu);
|
||||
Net.closeServer();
|
||||
|
||||
if (mode != ShuffleMode.off) {
|
||||
Array<Map> maps = mode == ShuffleMode.both ? world.maps().getAllMaps() :
|
||||
mode == ShuffleMode.normal ? world.maps().getDefaultMaps() : world.maps().getCustomMaps();
|
||||
|
||||
Map previous = world.getMap();
|
||||
Map map = previous;
|
||||
while (map == previous || !map.visible) map = maps.random();
|
||||
|
||||
info("Selected next map to be {0}.", map.name);
|
||||
state.set(State.playing);
|
||||
logic.reset();
|
||||
world.loadMap(map);
|
||||
host();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
info("&lcServer loaded. Type &ly'help'&lc for help.");
|
||||
|
Reference in New Issue
Block a user