mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-10 15:57:37 +07:00
Added openServer method
This commit is contained in:
@ -1,14 +1,14 @@
|
|||||||
package mindustry.core;
|
package mindustry.core;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
|
||||||
import arc.struct.*;
|
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.CommandHandler.*;
|
import arc.util.CommandHandler.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.core.GameState.*;
|
import mindustry.core.GameState.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
@ -26,9 +26,11 @@ import mindustry.world.*;
|
|||||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
|
|
||||||
|
import static arc.util.Log.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class NetServer implements ApplicationListener{
|
public class NetServer implements ApplicationListener{
|
||||||
@ -598,6 +600,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
if(!headless && !closing && net.server() && state.is(State.menu)){
|
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){
|
public void kickAll(KickReason reason){
|
||||||
for(NetConnection con : net.getConnections()){
|
for(NetConnection con : net.getConnections()){
|
||||||
con.kick(reason);
|
con.kick(reason);
|
||||||
|
@ -251,7 +251,7 @@ public class ServerControl implements ApplicationListener{
|
|||||||
|
|
||||||
info("Map loaded.");
|
info("Map loaded.");
|
||||||
|
|
||||||
host();
|
netServer.openServer();
|
||||||
}catch(MapException e){
|
}catch(MapException e){
|
||||||
Log.err(e.map.name() + ": " + e.getMessage());
|
Log.err(e.map.name() + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -711,8 +711,8 @@ public class ServerControl implements ApplicationListener{
|
|||||||
SaveIO.load(file);
|
SaveIO.load(file);
|
||||||
state.rules.zone = null;
|
state.rules.zone = null;
|
||||||
info("Save loaded.");
|
info("Save loaded.");
|
||||||
host();
|
|
||||||
state.set(State.playing);
|
state.set(State.playing);
|
||||||
|
netServer.openServer();
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
err("Failed to load save. Outdated or corrupt file.");
|
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){
|
private void logToFile(String text){
|
||||||
if(currentLogFile != null && currentLogFile.length() > maxLogLength){
|
if(currentLogFile != null && currentLogFile.length() > maxLogLength){
|
||||||
String date = DateTimeFormatter.ofPattern("MM-dd-yyyy | HH:mm:ss").format(LocalDateTime.now());
|
String date = DateTimeFormatter.ofPattern("MM-dd-yyyy | HH:mm:ss").format(LocalDateTime.now());
|
||||||
|
Reference in New Issue
Block a user