Merge branch 'port-field' of https://github.com/antsif-a/Mindustry into antsif-a-port-field

This commit is contained in:
Anuken
2025-02-08 23:26:40 -05:00
5 changed files with 38 additions and 10 deletions

View File

@@ -14,20 +14,25 @@ public class Host{
public final String versionType;
public final Gamemode mode;
public final @Nullable String modeName;
public int ping, port = Vars.port;
public int ping, port;
public Host(int ping, String name, String address, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description, String modeName){
public Host(int ping, String name, String address, int port, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description, String modeName){
this.ping = ping;
this.name = name;
this.address = address;
this.players = players;
this.port = port;
this.mapname = mapname;
this.wave = wave;
this.players = players;
this.version = version;
this.versionType = versionType;
this.playerLimit = playerLimit;
this.mode = mode;
this.playerLimit = playerLimit;
this.description = description;
this.modeName = modeName;
}
public Host(int ping, String name, String address, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description, String modeName){
this(ping, name, address, Vars.port, mapname, wave, players, version, versionType, mode, playerLimit, description, modeName);
}
}

View File

@@ -3,6 +3,8 @@ package mindustry.net;
import arc.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.ctype.*;
import mindustry.game.*;
@@ -111,6 +113,7 @@ public class NetworkIO{
buffer.put((byte)state.rules.mode().ordinal());
buffer.putInt(netServer.admins.getPlayerLimit());
buffer.putInt(Core.settings.getInt("port", port));
writeString(buffer, description, 100);
if(state.rules.modeName != null){
@@ -130,8 +133,10 @@ public class NetworkIO{
int limit = buffer.getInt();
String description = readString(buffer);
String modeName = readString(buffer);
int hostPort = buffer.getInt();
hostPort = hostPort != 0 ? hostPort : Vars.port;
return new Host(ping, host, hostAddress, map, wave, players, version, vertype, gamemode, limit, description, modeName.isEmpty() ? null : modeName);
return new Host(ping, host, hostAddress, hostPort, map, wave, players, version, vertype, gamemode, limit, description, modeName.isEmpty() ? null : modeName);
}
private static void writeString(ByteBuffer buffer, String string, int maxlen){

View File

@@ -3,7 +3,6 @@ package mindustry.ui.dialogs;
import arc.*;
import arc.scene.ui.*;
import arc.util.*;
import mindustry.*;
import mindustry.core.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
@@ -15,6 +14,7 @@ import static mindustry.Vars.*;
public class HostDialog extends BaseDialog{
float w = 300;
TextField portField;
public HostDialog(){
super("@hostserver");
@@ -49,6 +49,24 @@ public class HostDialog extends BaseDialog{
cont.row();
cont.table(t -> {
t.add("@server.port").padRight(10);
portField = t.field(String.valueOf(Core.settings.getInt("port", port)), text -> {
Core.settings.put("port", Integer.parseInt(text));
}).pad(8).grow().get();
portField.setMaxLength(5);
portField.setValidator(text -> {
try {
int port = Integer.parseInt(text);
return port >= 1 && port <= 65535;
} catch(NumberFormatException e){
return false;
}
});
}).width(w).height(70f).pad(4).colspan(3);
cont.row();
cont.add().width(65f);
cont.button("@host", () -> {
@@ -58,7 +76,7 @@ public class HostDialog extends BaseDialog{
}
runHost();
}).width(w).height(70f);
}).width(w).height(70f).disabled(b -> !portField.isValid());
if(!steam){
cont.button("?", () -> ui.showInfo("@host.info")).size(65f, 70f).padLeft(6f);
@@ -77,7 +95,7 @@ public class HostDialog extends BaseDialog{
ui.loadfrag.show("@hosting");
Time.runTask(5f, () -> {
try{
net.host(Vars.port);
net.host(Core.settings.getInt("port", port));
player.admin = true;
Events.fire(new HostEvent());