mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-11 00:07:46 +07:00
Added openServer method
This commit is contained in:
@ -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);
|
||||
|
@ -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());
|
||||
|
Reference in New Issue
Block a user