Added custom port support
This commit is contained in:
@@ -83,7 +83,6 @@ public class Control extends Module{
|
|||||||
|
|
||||||
Settings.defaultList(
|
Settings.defaultList(
|
||||||
"ip", "localhost",
|
"ip", "localhost",
|
||||||
"port", port + "",
|
|
||||||
"color-0", Color.rgba8888(playerColors[8]),
|
"color-0", Color.rgba8888(playerColors[8]),
|
||||||
"color-1", Color.rgba8888(playerColors[11]),
|
"color-1", Color.rgba8888(playerColors[11]),
|
||||||
"color-2", Color.rgba8888(playerColors[13]),
|
"color-2", Color.rgba8888(playerColors[13]),
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import io.anuke.ucore.util.Log;
|
|||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
import static io.anuke.mindustry.Vars.port;
|
||||||
|
|
||||||
public class JoinDialog extends FloatingDialog{
|
public class JoinDialog extends FloatingDialog{
|
||||||
Array<Server> servers = new Array<>();
|
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.cancel", add::hide);
|
||||||
add.buttons().addButton("$text.ok", () -> {
|
add.buttons().addButton("$text.ok", () -> {
|
||||||
if(renaming == null){
|
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);
|
servers.add(server);
|
||||||
saveServers();
|
saveServers();
|
||||||
setupRemote();
|
setupRemote();
|
||||||
refreshRemote();
|
refreshRemote();
|
||||||
}else{
|
}else{
|
||||||
renaming.ip = Settings.getString("ip");
|
renaming.setIP(Settings.getString("ip"));
|
||||||
saveServers();
|
saveServers();
|
||||||
setupRemote();
|
setupRemote();
|
||||||
refreshRemote();
|
refreshRemote();
|
||||||
@@ -75,7 +77,7 @@ public class JoinDialog extends FloatingDialog{
|
|||||||
add.shown(() -> {
|
add.shown(() -> {
|
||||||
add.getTitleLabel().setText(renaming != null ? "$text.server.edit" : "$text.server.add");
|
add.getTitleLabel().setText(renaming != null ? "$text.server.edit" : "$text.server.add");
|
||||||
if(renaming != null){
|
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
|
//why are java lambdas this bad
|
||||||
TextButton[] buttons = {null};
|
TextButton[] buttons = {null};
|
||||||
|
|
||||||
TextButton button = buttons[0] = remote.addButton("[accent]" + server.ip, "clear", () -> {
|
TextButton button = buttons[0] = remote.addButton("[accent]" + server.displayIP(), "clear", () -> {
|
||||||
if(!buttons[0].childrenPressed()) connect(server.ip, Vars.port);
|
if(!buttons[0].childrenPressed()){
|
||||||
|
connect(server.ip, server.port);
|
||||||
|
}
|
||||||
}).width(targetWidth()).height(150f).pad(4f).get();
|
}).width(targetWidth()).height(150f).pad(4f).get();
|
||||||
|
|
||||||
button.getLabel().setWrap(true);
|
button.getLabel().setWrap(true);
|
||||||
@@ -228,7 +232,7 @@ public class JoinDialog extends FloatingDialog{
|
|||||||
button.update(() -> button.getStyle().imageUpColor = player.color);
|
button.update(() -> button.getStyle().imageUpColor = player.color);
|
||||||
}).width(w).height(70f).pad(4);
|
}).width(w).height(70f).pad(4);
|
||||||
content().row();
|
content().row();
|
||||||
content().add(pane).width(w + 34).pad(0);
|
content().add(pane).width(w + 38).pad(0).padRight(22);
|
||||||
content().row();
|
content().row();
|
||||||
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14 * 3, () -> {
|
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14 * 3, () -> {
|
||||||
renaming = null;
|
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);
|
local.addImageButton("icon-loading", 16 * 2f, this::refreshLocal).pad(-10f).padLeft(0).padTop(-6).size(70f, 74f);
|
||||||
}else{
|
}else{
|
||||||
for(Host a : array){
|
for(Host a : array){
|
||||||
TextButton button = local.addButton("[accent]" + a.name, "clear", () -> {
|
TextButton button = local.addButton("[accent]" + a.name, "clear", () -> connect(a.address, port))
|
||||||
connect(a.address, Vars.port);
|
.width(w).height(80f).pad(4f).get();
|
||||||
}).width(w).height(80f).pad(4f).get();
|
|
||||||
button.left();
|
button.left();
|
||||||
button.row();
|
button.row();
|
||||||
button.add("[lightgray]" + (a.players != 1 ? Bundles.format("text.players", a.players) :
|
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 Host host;
|
||||||
transient Table content;
|
transient Table content;
|
||||||
|
|
||||||
Server(String ip, int port){
|
void setIP(String ip){
|
||||||
this.ip = ip;
|
//parse ip:port, if unsuccessful, use default values
|
||||||
this.port = port;
|
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", "",
|
"bans", "",
|
||||||
"admins", "",
|
"admins", "",
|
||||||
"sector_x", 0,
|
"sector_x", 0,
|
||||||
"sector_y", 1
|
"sector_y", 1,
|
||||||
|
"port", port
|
||||||
);
|
);
|
||||||
|
|
||||||
mode = ShuffleMode.valueOf(Settings.getString("shufflemode"));
|
mode = ShuffleMode.valueOf(Settings.getString("shufflemode"));
|
||||||
|
|
||||||
|
Timers.setDeltaProvider(() -> Gdx.graphics.getDeltaTime() * 60f);
|
||||||
Effects.setScreenShakeProvider((a, b) -> {});
|
Effects.setScreenShakeProvider((a, b) -> {});
|
||||||
Effects.setEffectProvider((a, b, c, d, e, f) -> {});
|
Effects.setEffectProvider((a, b, c, d, e, f) -> {});
|
||||||
Sounds.setHeadless(true);
|
Sounds.setHeadless(true);
|
||||||
@@ -206,7 +208,7 @@ public class ServerControl extends Module{
|
|||||||
logic.play();
|
logic.play();
|
||||||
|
|
||||||
}else{
|
}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);
|
playSectorMap(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,10 +217,25 @@ public class ServerControl extends Module{
|
|||||||
host();
|
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 -> {
|
handler.register("maps", "Display all available maps.", arg -> {
|
||||||
Log.info("Maps:");
|
info("Maps:");
|
||||||
for(Map map : world.maps().all()){
|
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(){
|
private void host(){
|
||||||
try{
|
try{
|
||||||
Net.host(port);
|
Net.host(Settings.getInt("port"));
|
||||||
|
info("&lcOpened a server on port {0}.", Settings.getInt("port"));
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
Log.err(e);
|
Log.err(e);
|
||||||
state.set(State.menu);
|
state.set(State.menu);
|
||||||
@@ -926,13 +944,14 @@ public class ServerControl extends Module{
|
|||||||
@Override
|
@Override
|
||||||
public void update(){
|
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
|
//all assigned missions are complete
|
||||||
if(world.getSector().completedMissions >= world.getSector().missions.size){
|
if(world.getSector().completedMissions >= world.getSector().missions.size){
|
||||||
Log.info("Mission complete.");
|
Log.info("Mission complete.");
|
||||||
world.sectors().completeSector(world.getSector().x, world.getSector().y);
|
world.sectors().completeSector(world.getSector().x, world.getSector().y);
|
||||||
world.sectors().save();
|
world.sectors().save();
|
||||||
gameOvers = 0;
|
gameOvers = 0;
|
||||||
|
inExtraRound = true;
|
||||||
Settings.putInt("sector_x", world.getSector().x + world.getSector().size);
|
Settings.putInt("sector_x", world.getSector().x + world.getSector().size);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user