diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index df24a53b4a..6aa07521ab 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -232,7 +232,7 @@ server.kicked.customClient = This server does not support custom builds. Downloa server.kicked.gameover = Game over! server.kicked.serverRestarting = The server is restarting. server.versions = Your version:[accent] {0}[]\nServer version:[accent] {1}[] -host.info = The [accent]host[] button hosts a server on port [scarlet]6567[]. \nAnybody on the same [lightgray]wifi or local network[] should be able to see your server in their server list.\n\nIf you want people to be able to connect from anywhere by IP, [accent]port forwarding[] is required.\n\n[lightgray]Note: If someone is experiencing trouble connecting to your LAN game, make sure you have allowed Mindustry access to your local network in your firewall settings. Note that public networks sometimes do not allow server discovery. +host.info = The [accent]host[] button hosts a server on specified port.\nAnybody on the same [lightgray]wifi or local network[] should be able to see your server in their server list.\n\nIf you want people to be able to connect from anywhere by IP, [accent]port forwarding[] is required.\n\n[lightgray]Note: If someone is experiencing trouble connecting to your LAN game, make sure you have allowed Mindustry access to your local network in your firewall settings. Note that public networks sometimes do not allow server discovery. join.info = Here, you can enter a [accent]server IP[] to connect to, or discover [accent]local network[] or [accent]global[] servers to connect to.\nBoth LAN and WAN multiplayer is supported.\n\n[lightgray]If you want to connect to someone by IP, you would need to ask the host for their IP, which can be found by googling "my ip" from their device. hostserver = Host Multiplayer Game invitefriends = Invite Friends diff --git a/core/assets/bundles/bundle_ru.properties b/core/assets/bundles/bundle_ru.properties index 3dfef2ea64..782e704037 100644 --- a/core/assets/bundles/bundle_ru.properties +++ b/core/assets/bundles/bundle_ru.properties @@ -229,7 +229,7 @@ server.kicked.customClient = Этот сервер не поддерживает server.kicked.gameover = Игра окончена! server.kicked.serverRestarting = Сервер перезапускается. server.versions = Ваша версия:[accent] {0}[]\nВерсия сервера:[accent] {1}[] -host.info = Кнопка [accent]Открыть сервер[] запускает сервер на порте [scarlet]6567[].\nЛюбой пользователь в той же [lightgray]локальной сети или WiFi[] должен увидеть ваш сервер в своём списке серверов.\n\nЕсли вы хотите, чтобы люди могли подключаться откуда угодно по IP, то требуется [accent]переадресация (проброс) портов[] и наличие [red]ВНЕШНЕГО[] WAN адреса (WAN адрес [red]НЕ должен[] начинаться с [red]10[][lightgray].x.x.x[], [red]100.64[][lightgray].x.x[], [red]172.16[][lightgray].x.x[], [red]192.168[][lightgray].x.x[], [red]127[][lightgray].x.x.x[])!\nКлиентам мобильных операторов нужно уточнять информацию в личном кабинете на сайте вашего оператора!\n\n[lightgray]Примечание: Если у кого-то возникают проблемы с подключением к вашей игре по локальной сети, убедитесь, что вы разрешили доступ Mindustry к вашей локальной сети в настройках брандмауэра. Обратите внимание, что публичные сети иногда не позволяют обнаружение сервера. +host.info = Кнопка [accent]Открыть сервер[] запускает сервер на указанном порте.\nЛюбой пользователь в той же [lightgray]локальной сети или WiFi[] должен увидеть ваш сервер в своём списке серверов.\n\nЕсли вы хотите, чтобы люди могли подключаться откуда угодно по IP, то требуется [accent]переадресация (проброс) портов[] и наличие [red]ВНЕШНЕГО[] WAN адреса (WAN адрес [red]НЕ должен[] начинаться с [red]10[][lightgray].x.x.x[], [red]100.64[][lightgray].x.x[], [red]172.16[][lightgray].x.x[], [red]192.168[][lightgray].x.x[], [red]127[][lightgray].x.x.x[])!\nКлиентам мобильных операторов нужно уточнять информацию в личном кабинете на сайте вашего оператора!\n\n[lightgray]Примечание: Если у кого-то возникают проблемы с подключением к вашей игре по локальной сети, убедитесь, что вы разрешили доступ Mindustry к вашей локальной сети в настройках брандмауэра. Обратите внимание, что публичные сети иногда не позволяют обнаружение сервера. join.info = Здесь вы можете ввести [accent]IP-адрес сервера[], найти доступные [accent]локальные[] и [accent]глобальные[] серверы для подключения.\nПоддерживаются оба многопользовательских режима: LAN и WAN.\n\n[lightgray]Если вы хотите подключиться к кому-то по IP-адресу, Вам нужно будет попросить IP-адрес у самого хоста. Хост может узнать IP-адрес своего устройства через Google запрос [accent]"my ip"[]. hostserver = Запустить многопользовательский сервер invitefriends = Пригласить друзей diff --git a/core/src/mindustry/net/Host.java b/core/src/mindustry/net/Host.java index f6124be052..41f8c8811e 100644 --- a/core/src/mindustry/net/Host.java +++ b/core/src/mindustry/net/Host.java @@ -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); + } } diff --git a/core/src/mindustry/net/NetworkIO.java b/core/src/mindustry/net/NetworkIO.java index 3dac108090..779d832c72 100644 --- a/core/src/mindustry/net/NetworkIO.java +++ b/core/src/mindustry/net/NetworkIO.java @@ -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){ diff --git a/core/src/mindustry/ui/dialogs/HostDialog.java b/core/src/mindustry/ui/dialogs/HostDialog.java index 5f8f143498..13d5a9fc40 100644 --- a/core/src/mindustry/ui/dialogs/HostDialog.java +++ b/core/src/mindustry/ui/dialogs/HostDialog.java @@ -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());