mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 11:29:48 +07:00
Added custom port support
This commit is contained in:
parent
19979dec55
commit
864c4f6bc3
@ -83,7 +83,6 @@ public class Control extends Module{
|
||||
|
||||
Settings.defaultList(
|
||||
"ip", "localhost",
|
||||
"port", port + "",
|
||||
"color-0", Color.rgba8888(playerColors[8]),
|
||||
"color-1", Color.rgba8888(playerColors[11]),
|
||||
"color-2", Color.rgba8888(playerColors[13]),
|
||||
|
@ -21,6 +21,7 @@ import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.port;
|
||||
|
||||
public class JoinDialog extends FloatingDialog{
|
||||
Array<Server> servers = new Array<>();
|
||||
@ -58,13 +59,14 @@ public class JoinDialog extends FloatingDialog{
|
||||
add.buttons().addButton("$text.cancel", add::hide);
|
||||
add.buttons().addButton("$text.ok", () -> {
|
||||
if(renaming == null){
|
||||
Server server = new Server(Settings.getString("ip"), Strings.parseInt(Settings.getString("port")));
|
||||
Server server = new Server();
|
||||
server.setIP(Settings.getString("ip"));
|
||||
servers.add(server);
|
||||
saveServers();
|
||||
setupRemote();
|
||||
refreshRemote();
|
||||
}else{
|
||||
renaming.ip = Settings.getString("ip");
|
||||
renaming.setIP(Settings.getString("ip"));
|
||||
saveServers();
|
||||
setupRemote();
|
||||
refreshRemote();
|
||||
@ -75,7 +77,7 @@ public class JoinDialog extends FloatingDialog{
|
||||
add.shown(() -> {
|
||||
add.getTitleLabel().setText(renaming != null ? "$text.server.edit" : "$text.server.add");
|
||||
if(renaming != null){
|
||||
field.setText(renaming.ip);
|
||||
field.setText(renaming.displayIP());
|
||||
}
|
||||
});
|
||||
|
||||
@ -94,8 +96,10 @@ public class JoinDialog extends FloatingDialog{
|
||||
//why are java lambdas this bad
|
||||
TextButton[] buttons = {null};
|
||||
|
||||
TextButton button = buttons[0] = remote.addButton("[accent]" + server.ip, "clear", () -> {
|
||||
if(!buttons[0].childrenPressed()) connect(server.ip, Vars.port);
|
||||
TextButton button = buttons[0] = remote.addButton("[accent]" + server.displayIP(), "clear", () -> {
|
||||
if(!buttons[0].childrenPressed()){
|
||||
connect(server.ip, server.port);
|
||||
}
|
||||
}).width(targetWidth()).height(150f).pad(4f).get();
|
||||
|
||||
button.getLabel().setWrap(true);
|
||||
@ -228,7 +232,7 @@ public class JoinDialog extends FloatingDialog{
|
||||
button.update(() -> button.getStyle().imageUpColor = player.color);
|
||||
}).width(w).height(70f).pad(4);
|
||||
content().row();
|
||||
content().add(pane).width(w + 34).pad(0);
|
||||
content().add(pane).width(w + 38).pad(0).padRight(22);
|
||||
content().row();
|
||||
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14 * 3, () -> {
|
||||
renaming = null;
|
||||
@ -262,9 +266,8 @@ public class JoinDialog extends FloatingDialog{
|
||||
local.addImageButton("icon-loading", 16 * 2f, this::refreshLocal).pad(-10f).padLeft(0).padTop(-6).size(70f, 74f);
|
||||
}else{
|
||||
for(Host a : array){
|
||||
TextButton button = local.addButton("[accent]" + a.name, "clear", () -> {
|
||||
connect(a.address, Vars.port);
|
||||
}).width(w).height(80f).pad(4f).get();
|
||||
TextButton button = local.addButton("[accent]" + a.name, "clear", () -> connect(a.address, port))
|
||||
.width(w).height(80f).pad(4f).get();
|
||||
button.left();
|
||||
button.row();
|
||||
button.add("[lightgray]" + (a.players != 1 ? Bundles.format("text.players", a.players) :
|
||||
@ -338,12 +341,25 @@ public class JoinDialog extends FloatingDialog{
|
||||
transient Host host;
|
||||
transient Table content;
|
||||
|
||||
Server(String ip, int port){
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
void setIP(String ip){
|
||||
//parse ip:port, if unsuccessful, use default values
|
||||
if(ip.lastIndexOf(':') != -1 && ip.lastIndexOf(':') != ip.length()-1){
|
||||
try{
|
||||
int idx = ip.lastIndexOf(':');
|
||||
this.ip = ip.substring(0, idx);
|
||||
this.port = Integer.parseInt(ip.substring(idx + 1));
|
||||
}catch(Exception e){
|
||||
this.ip = ip;
|
||||
this.port = Vars.port;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Server(){
|
||||
String displayIP(){
|
||||
return ip + (port != Vars.port ? ":" + port : "");
|
||||
}
|
||||
|
||||
Server(){}
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,13 @@ public class ServerControl extends Module{
|
||||
"bans", "",
|
||||
"admins", "",
|
||||
"sector_x", 0,
|
||||
"sector_y", 1
|
||||
"sector_y", 1,
|
||||
"port", port
|
||||
);
|
||||
|
||||
mode = ShuffleMode.valueOf(Settings.getString("shufflemode"));
|
||||
|
||||
Timers.setDeltaProvider(() -> Gdx.graphics.getDeltaTime() * 60f);
|
||||
Effects.setScreenShakeProvider((a, b) -> {});
|
||||
Effects.setEffectProvider((a, b, c, d, e, f) -> {});
|
||||
Sounds.setHeadless(true);
|
||||
@ -206,7 +208,7 @@ public class ServerControl extends Module{
|
||||
logic.play();
|
||||
|
||||
}else{
|
||||
Log.info("&ly&fiNo map specified. Loading sector {0}, {1}.", Settings.getInt("sector_x"), Settings.getInt("sector_y"));
|
||||
info("&ly&fiNo map specified. Loading sector {0}, {1}.", Settings.getInt("sector_x"), Settings.getInt("sector_y"));
|
||||
playSectorMap(false);
|
||||
}
|
||||
|
||||
@ -215,10 +217,25 @@ public class ServerControl extends Module{
|
||||
host();
|
||||
});
|
||||
|
||||
handler.register("port", "[port]", "Sets or displays the port for hosting the server.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("&lyPort: &lc{0}", Settings.getInt("port"));
|
||||
}else{
|
||||
int port = Strings.parseInt(arg[0]);
|
||||
if(port < 0 || port > 65535){
|
||||
err("Port must be a number between 0 and 65535.");
|
||||
return;
|
||||
}
|
||||
info("&lyPort set to {0}.", port);
|
||||
Settings.putInt("port", port);
|
||||
Settings.save();
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("maps", "Display all available maps.", arg -> {
|
||||
Log.info("Maps:");
|
||||
info("Maps:");
|
||||
for(Map map : world.maps().all()){
|
||||
Log.info(" &ly{0}: &lb&fi{1} / {2}x{3}", map.name, map.custom ? "Custom" : "Default", map.meta.width, map.meta.height);
|
||||
info(" &ly{0}: &lb&fi{1} / {2}x{3}", map.name, map.custom ? "Custom" : "Default", map.meta.width, map.meta.height);
|
||||
}
|
||||
});
|
||||
|
||||
@ -897,7 +914,8 @@ public class ServerControl extends Module{
|
||||
|
||||
private void host(){
|
||||
try{
|
||||
Net.host(port);
|
||||
Net.host(Settings.getInt("port"));
|
||||
info("&lcOpened a server on port {0}.", Settings.getInt("port"));
|
||||
}catch(IOException e){
|
||||
Log.err(e);
|
||||
state.set(State.menu);
|
||||
@ -926,13 +944,14 @@ public class ServerControl extends Module{
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
if(state.is(State.playing) && world.getSector() != null){
|
||||
if(state.is(State.playing) && world.getSector() != null && !inExtraRound && !debug){
|
||||
//all assigned missions are complete
|
||||
if(world.getSector().completedMissions >= world.getSector().missions.size){
|
||||
Log.info("Mission complete.");
|
||||
world.sectors().completeSector(world.getSector().x, world.getSector().y);
|
||||
world.sectors().save();
|
||||
gameOvers = 0;
|
||||
inExtraRound = true;
|
||||
Settings.putInt("sector_x", world.getSector().x + world.getSector().size);
|
||||
Settings.save();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user