Added openServer method

This commit is contained in:
Anuken
2019-12-28 22:18:16 -05:00
parent 8c941c7165
commit df4a0dd5e4
2 changed files with 21 additions and 17 deletions

View File

@ -1,14 +1,14 @@
package mindustry.core;
import arc.*;
import mindustry.annotations.Annotations.*;
import arc.struct.*;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.CommandHandler.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.entities.*;
@ -26,9 +26,11 @@ import mindustry.world.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import java.io.*;
import java.net.*;
import java.nio.*;
import java.util.zip.*;
import static arc.util.Log.*;
import static mindustry.Vars.*;
public class NetServer implements ApplicationListener{
@ -598,6 +600,7 @@ public class NetServer implements ApplicationListener{
return false;
}
@Override
public void update(){
if(!headless && !closing && net.server() && state.is(State.menu)){
@ -615,6 +618,20 @@ public class NetServer implements ApplicationListener{
}
}
/** Should only be used on the headless backend. */
public void openServer(){
try{
net.host(Config.port.num());
info("&lcOpened a server on port {0}.", Config.port.num());
}catch(BindException e){
Log.err("Unable to host: Port already in use! Make sure no other servers are running on the same port in your network.");
state.set(State.menu);
}catch(IOException e){
err(e);
state.set(State.menu);
}
}
public void kickAll(KickReason reason){
for(NetConnection con : net.getConnections()){
con.kick(reason);

View File

@ -251,7 +251,7 @@ public class ServerControl implements ApplicationListener{
info("Map loaded.");
host();
netServer.openServer();
}catch(MapException e){
Log.err(e.map.name() + ": " + e.getMessage());
}
@ -711,8 +711,8 @@ public class ServerControl implements ApplicationListener{
SaveIO.load(file);
state.rules.zone = null;
info("Save loaded.");
host();
state.set(State.playing);
netServer.openServer();
}catch(Throwable t){
err("Failed to load save. Outdated or corrupt file.");
}
@ -869,19 +869,6 @@ public class ServerControl implements ApplicationListener{
}
}
private void host(){
try{
net.host(Config.port.num());
info("&lcOpened a server on port {0}.", Config.port.num());
}catch(BindException e){
Log.err("Unable to host: Port already in use! Make sure no other servers are running on the same port in your network.");
state.set(State.menu);
}catch(IOException e){
err(e);
state.set(State.menu);
}
}
private void logToFile(String text){
if(currentLogFile != null && currentLogFile.length() > maxLogLength){
String date = DateTimeFormatter.ofPattern("MM-dd-yyyy | HH:mm:ss").format(LocalDateTime.now());