diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 9fe58d1b1b..2fd454ee3a 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -84,6 +84,7 @@ host = Host hosting = [accent]Opening server... hosts.refresh = Refresh hosts.discovering = Discovering LAN games +hosts.discovering.any = Discovering games server.refreshing = Refreshing server hosts.none = [lightgray]No local games found! host.invalid = [scarlet]Can't connect to host. diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 8d210cb930..79b7d82116 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -85,6 +85,7 @@ public class NetServer implements ApplicationListener{ String uuid = packet.uuid; NetConnection connection = Net.getConnection(id); + Log.info("\n\nGET CONNECT\n\n"); if(connection == null || admins.isIPBanned(connection.address)) return; @@ -138,8 +139,6 @@ public class NetServer implements ApplicationListener{ return; } - Log.debug("Recieved connect packet for player '{0}' / UUID {1} / IP {2}", packet.name, uuid, connection.address); - String ip = Net.getConnection(id).address; admins.updatePlayerJoined(uuid, ip, packet.name); diff --git a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java index 7b1486c270..0ec2b8c8b2 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java @@ -4,6 +4,7 @@ import io.anuke.annotations.Annotations.*; import io.anuke.arc.*; import io.anuke.arc.collection.*; import io.anuke.arc.graphics.*; +import io.anuke.arc.input.*; import io.anuke.arc.math.*; import io.anuke.arc.scene.style.*; import io.anuke.arc.scene.ui.*; @@ -77,6 +78,11 @@ public class JoinDialog extends FloatingDialog{ } }); + keyDown(KeyCode.F5, () -> { + refreshLocal(); + refreshRemote(); + }); + shown(() -> { setup(); refreshLocal(); @@ -267,7 +273,7 @@ public class JoinDialog extends FloatingDialog{ local.clear(); local.background((Drawable)null); - local.table("button", t -> t.label(() -> "[accent]" + Core.bundle.get("hosts.discovering") + Strings.animated(Time.time(), 4, 10f, ".")).pad(10f)).growX(); + local.table("button", t -> t.label(() -> "[accent]" + Core.bundle.get("hosts.discovering.any") + Strings.animated(Time.time(), 4, 10f, ".")).pad(10f)).growX(); Net.discoverServers(this::addLocalHost, this::finishLocalHosts); } diff --git a/desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java b/desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java index edbb0d7ae0..9ba2b3e6d4 100644 --- a/desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java +++ b/desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java @@ -27,7 +27,7 @@ import static io.anuke.mindustry.Vars.*; public class DesktopPlatform extends Platform{ - static boolean useDiscord = OS.is64Bit, useSteam = true; + static boolean useDiscord = OS.is64Bit, useSteam = true, showConsole = false; final static String applicationId = "610508934456934412"; String[] args; @@ -49,34 +49,36 @@ public class DesktopPlatform extends Platform{ } if(useSteam){ - Events.on(GameLoadEvent.class, event -> { - Label[] label = {null}; - Core.scene.table(t -> { - t.touchable(Touchable.disabled); - t.top().left(); - t.update(t::toFront); - t.table("guideDim", f -> { - label[0] = f.add("").get(); + if(showConsole){ + Events.on(GameLoadEvent.class, event -> { + Label[] label = {null}; + Core.scene.table(t -> { + t.touchable(Touchable.disabled); + t.top().left(); + t.update(t::toFront); + t.table("guideDim", f -> { + label[0] = f.add("").get(); + }); + }); + + Log.setLogger(new LogHandler(){ + @Override + public void print(String text, Object... args){ + super.print(text, args); + String out = Log.format(text, false, args); + + int maxlen = 2048; + + if(label[0].getText().length() > maxlen){ + label[0].setText(label[0].getText().substring(label[0].getText().length() - maxlen)); + } + + label[0].getText().append(out).append("\n"); + label[0].invalidateHierarchy(); + } }); }); - - Log.setLogger(new LogHandler(){ - @Override - public void print(String text, Object... args){ - super.print(text, args); - String out = Log.format(text, false, args); - - int maxlen = 2048; - - if(label[0].getText().length() > maxlen){ - label[0].setText(label[0].getText().substring(label[0].getText().length() - maxlen)); - } - - label[0].getText().append(out).append("\n"); - label[0].invalidateHierarchy(); - } - }); - }); + } Vars.steam = true; try{ diff --git a/desktop/src/io/anuke/mindustry/desktop/steam/SteamNetImpl.java b/desktop/src/io/anuke/mindustry/desktop/steam/SteamNetImpl.java index ea008663ae..3e45a2dbf5 100644 --- a/desktop/src/io/anuke/mindustry/desktop/steam/SteamNetImpl.java +++ b/desktop/src/io/anuke/mindustry/desktop/steam/SteamNetImpl.java @@ -10,6 +10,7 @@ import io.anuke.arc.function.*; import io.anuke.arc.util.*; import io.anuke.arc.util.pooling.*; import io.anuke.mindustry.game.EventType.*; +import io.anuke.mindustry.game.Version; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.*; import io.anuke.mindustry.net.Net.*; @@ -20,7 +21,7 @@ import java.io.*; import java.nio.*; import java.util.concurrent.*; -import static io.anuke.mindustry.Vars.ui; +import static io.anuke.mindustry.Vars.*; public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, ClientProvider, ServerProvider{ final SteamNetworking snet = new SteamNetworking(this); @@ -35,8 +36,11 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa final CopyOnWriteArrayList connections = new CopyOnWriteArrayList<>(); final IntMap steamConnections = new IntMap<>(); //maps steam ID -> valid net connection + final ObjectMap lobbyIDs = new ObjectMap<>(); SteamID currentLobby, currentServer; + Consumer lobbyCallback; + Runnable lobbyDoneCallback, joinCallback; public SteamNetImpl(){ Events.on(GameLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){ @@ -69,11 +73,24 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa } } })); + + Events.on(WaveEvent.class, e -> { + if(currentLobby != null && Net.server()){ + smat.setLobbyData(currentLobby, "wave", state.wave + ""); + } + }); } @Override public void connect(String ip, int port, Runnable success) throws IOException{ - //no + if(ip.startsWith("steam:")){ + String lobbyname = ip.substring("steam:".length()); + SteamID lobby = lobbyIDs.get(lobbyname); + if(lobby == null) throw new IOException("Lobby not found."); + joinCallback = success; + smat.joinLobby(lobby); + } + //else, no } @Override @@ -114,6 +131,7 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa snet.closeP2PSessionWithUser(currentServer); currentServer = null; currentLobby = null; + Net.handleClientReceived(new Disconnect()); } } @@ -124,7 +142,9 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa @Override public void discover(Consumer callback, Runnable done){ - //no + smat.requestLobbyList(); + lobbyCallback = callback; + lobbyDoneCallback = done; } @Override @@ -204,15 +224,20 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa @Override public void onLobbyEnter(SteamID steamIDLobby, int chatPermissions, boolean blocked, ChatRoomEnterResponse response){ + Log.info("enter lobby {0} {1}", steamIDLobby.getAccountID(), response); currentLobby = steamIDLobby; currentServer = smat.getLobbyOwner(steamIDLobby); + if(joinCallback != null){ + joinCallback.run(); + joinCallback = null; + } + Connect con = new Connect(); con.addressTCP = "steam:" + currentServer.getAccountID(); Net.setClientConnected(); Net.handleClientReceived(con); - Log.info("enter lobby {0} {1}", steamIDLobby.getAccountID(), response); } @Override @@ -225,6 +250,7 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa Log.info("lobby {0}: {1} caused {2}'s change: {3}", lobby.getAccountID(), who.getAccountID(), changer.getAccountID(), change); if(change == ChatMemberStateChange.Disconnected || change == ChatMemberStateChange.Left){ if(Net.client()){ + Log.info("Current host left."); //host left, leave as well if(who == currentServer){ disconnect(); @@ -248,7 +274,26 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa } @Override - public void onLobbyMatchList(int i){ + public void onLobbyMatchList(int matches){ + if(lobbyDoneCallback != null){ + for(int i = 0; i < matches; i++){ + SteamID lobby = smat.getLobbyByIndex(i); + Host out = new Host( + smat.getLobbyData(lobby, "name"), + "steam:" + lobby.getAccountID(), + smat.getLobbyData(lobby, "mapname"), + Strings.parseInt(smat.getLobbyData(lobby, "wave"), -1), + smat.getNumLobbyMembers(lobby), + Strings.parseInt(smat.getLobbyData(lobby, "name"), -1), + smat.getLobbyData(lobby, "versionType")); + + lobbyIDs.put(lobby.getAccountID() + "", lobby); + + lobbyCallback.accept(out); + } + + lobbyDoneCallback.run(); + } } @Override @@ -268,6 +313,13 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa Log.info("Lobby {1} created? {0}", result, steamID.getAccountID()); if(result == SteamResult.OK){ currentLobby = steamID; + + smat.setLobbyData(steamID, "name", player.name); + smat.setLobbyData(steamID, "mapname", world.getMap() == null ? "Unknown" : world.getMap().name()); + smat.setLobbyData(steamID, "version", Version.build + ""); + smat.setLobbyData(steamID, "versionType", Version.type); + smat.setLobbyData(steamID, "wave", state.wave + ""); + friends.activateGameOverlayInviteDialog(currentLobby); Log.info("Activating overlay dialog"); } @@ -359,6 +411,7 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa public class SteamConnection extends NetConnection{ final SteamID sid; + final P2PSessionState state = new P2PSessionState(); public SteamConnection(SteamID sid){ super(sid.getAccountID() + ""); @@ -372,7 +425,6 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa writeBuffer.position(0); serializer.write(writeBuffer, object); writeBuffer.flip(); - //Log.info("Send {0} to {1} mode {2}", object, sid.getAccountID(), mode); snet.sendP2PPacket(sid, writeBuffer, mode == SendMode.tcp ? object instanceof StreamChunk ? P2PSend.ReliableWithBuffering : P2PSend.Reliable : P2PSend.UnreliableNoDelay, 0); }catch(Exception e){ @@ -385,6 +437,12 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa } } + @Override + public boolean isConnected(){ + snet.getP2PSessionState(sid, state); + return state.isConnectionActive() || state.isConnecting(); + } + @Override public void close(){ snet.closeP2PSessionWithUser(sid);