Merge remote-tracking branch 'origin/steam' into steam

# Conflicts:
#	desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java
This commit is contained in:
Anuken
2019-08-22 20:50:43 -04:00
5 changed files with 102 additions and 36 deletions

View File

@@ -84,6 +84,7 @@ host = Host
hosting = [accent]Opening server... hosting = [accent]Opening server...
hosts.refresh = Refresh hosts.refresh = Refresh
hosts.discovering = Discovering LAN games hosts.discovering = Discovering LAN games
hosts.discovering.any = Discovering games
server.refreshing = Refreshing server server.refreshing = Refreshing server
hosts.none = [lightgray]No local games found! hosts.none = [lightgray]No local games found!
host.invalid = [scarlet]Can't connect to host. host.invalid = [scarlet]Can't connect to host.

View File

@@ -85,6 +85,7 @@ public class NetServer implements ApplicationListener{
String uuid = packet.uuid; String uuid = packet.uuid;
NetConnection connection = Net.getConnection(id); NetConnection connection = Net.getConnection(id);
Log.info("\n\nGET CONNECT\n\n");
if(connection == null || if(connection == null ||
admins.isIPBanned(connection.address)) return; admins.isIPBanned(connection.address)) return;
@@ -138,8 +139,6 @@ public class NetServer implements ApplicationListener{
return; return;
} }
Log.debug("Recieved connect packet for player '{0}' / UUID {1} / IP {2}", packet.name, uuid, connection.address);
String ip = Net.getConnection(id).address; String ip = Net.getConnection(id).address;
admins.updatePlayerJoined(uuid, ip, packet.name); admins.updatePlayerJoined(uuid, ip, packet.name);

View File

@@ -4,6 +4,7 @@ import io.anuke.annotations.Annotations.*;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.collection.*; import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.*;
import io.anuke.arc.input.*;
import io.anuke.arc.math.*; import io.anuke.arc.math.*;
import io.anuke.arc.scene.style.*; import io.anuke.arc.scene.style.*;
import io.anuke.arc.scene.ui.*; import io.anuke.arc.scene.ui.*;
@@ -77,6 +78,11 @@ public class JoinDialog extends FloatingDialog{
} }
}); });
keyDown(KeyCode.F5, () -> {
refreshLocal();
refreshRemote();
});
shown(() -> { shown(() -> {
setup(); setup();
refreshLocal(); refreshLocal();
@@ -267,7 +273,7 @@ public class JoinDialog extends FloatingDialog{
local.clear(); local.clear();
local.background((Drawable)null); 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); Net.discoverServers(this::addLocalHost, this::finishLocalHosts);
} }

View File

@@ -27,7 +27,7 @@ import static io.anuke.mindustry.Vars.*;
public class DesktopPlatform extends Platform{ 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"; final static String applicationId = "610508934456934412";
String[] args; String[] args;
@@ -49,34 +49,36 @@ public class DesktopPlatform extends Platform{
} }
if(useSteam){ if(useSteam){
Events.on(GameLoadEvent.class, event -> { if(showConsole){
Label[] label = {null}; Events.on(GameLoadEvent.class, event -> {
Core.scene.table(t -> { Label[] label = {null};
t.touchable(Touchable.disabled); Core.scene.table(t -> {
t.top().left(); t.touchable(Touchable.disabled);
t.update(t::toFront); t.top().left();
t.table("guideDim", f -> { t.update(t::toFront);
label[0] = f.add("").get(); 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; Vars.steam = true;
try{ try{

View File

@@ -10,6 +10,7 @@ import io.anuke.arc.function.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.arc.util.pooling.*; import io.anuke.arc.util.pooling.*;
import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.*; import io.anuke.mindustry.net.*;
import io.anuke.mindustry.net.Net.*; import io.anuke.mindustry.net.Net.*;
@@ -20,7 +21,7 @@ import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.concurrent.*; 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{ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, ClientProvider, ServerProvider{
final SteamNetworking snet = new SteamNetworking(this); final SteamNetworking snet = new SteamNetworking(this);
@@ -35,8 +36,11 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>(); final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
final IntMap<SteamConnection> steamConnections = new IntMap<>(); //maps steam ID -> valid net connection final IntMap<SteamConnection> steamConnections = new IntMap<>(); //maps steam ID -> valid net connection
final ObjectMap<String, SteamID> lobbyIDs = new ObjectMap<>();
SteamID currentLobby, currentServer; SteamID currentLobby, currentServer;
Consumer<Host> lobbyCallback;
Runnable lobbyDoneCallback, joinCallback;
public SteamNetImpl(){ public SteamNetImpl(){
Events.on(GameLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){ 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 @Override
public void connect(String ip, int port, Runnable success) throws IOException{ 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 @Override
@@ -114,6 +131,7 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
snet.closeP2PSessionWithUser(currentServer); snet.closeP2PSessionWithUser(currentServer);
currentServer = null; currentServer = null;
currentLobby = null; currentLobby = null;
Net.handleClientReceived(new Disconnect());
} }
} }
@@ -124,7 +142,9 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
@Override @Override
public void discover(Consumer<Host> callback, Runnable done){ public void discover(Consumer<Host> callback, Runnable done){
//no smat.requestLobbyList();
lobbyCallback = callback;
lobbyDoneCallback = done;
} }
@Override @Override
@@ -204,15 +224,20 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
@Override @Override
public void onLobbyEnter(SteamID steamIDLobby, int chatPermissions, boolean blocked, ChatRoomEnterResponse response){ public void onLobbyEnter(SteamID steamIDLobby, int chatPermissions, boolean blocked, ChatRoomEnterResponse response){
Log.info("enter lobby {0} {1}", steamIDLobby.getAccountID(), response);
currentLobby = steamIDLobby; currentLobby = steamIDLobby;
currentServer = smat.getLobbyOwner(steamIDLobby); currentServer = smat.getLobbyOwner(steamIDLobby);
if(joinCallback != null){
joinCallback.run();
joinCallback = null;
}
Connect con = new Connect(); Connect con = new Connect();
con.addressTCP = "steam:" + currentServer.getAccountID(); con.addressTCP = "steam:" + currentServer.getAccountID();
Net.setClientConnected(); Net.setClientConnected();
Net.handleClientReceived(con); Net.handleClientReceived(con);
Log.info("enter lobby {0} {1}", steamIDLobby.getAccountID(), response);
} }
@Override @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); 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(change == ChatMemberStateChange.Disconnected || change == ChatMemberStateChange.Left){
if(Net.client()){ if(Net.client()){
Log.info("Current host left.");
//host left, leave as well //host left, leave as well
if(who == currentServer){ if(who == currentServer){
disconnect(); disconnect();
@@ -248,7 +274,26 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
} }
@Override @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 @Override
@@ -268,6 +313,13 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
Log.info("Lobby {1} created? {0}", result, steamID.getAccountID()); Log.info("Lobby {1} created? {0}", result, steamID.getAccountID());
if(result == SteamResult.OK){ if(result == SteamResult.OK){
currentLobby = steamID; 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); friends.activateGameOverlayInviteDialog(currentLobby);
Log.info("Activating overlay dialog"); Log.info("Activating overlay dialog");
} }
@@ -359,6 +411,7 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
public class SteamConnection extends NetConnection{ public class SteamConnection extends NetConnection{
final SteamID sid; final SteamID sid;
final P2PSessionState state = new P2PSessionState();
public SteamConnection(SteamID sid){ public SteamConnection(SteamID sid){
super(sid.getAccountID() + ""); super(sid.getAccountID() + "");
@@ -372,7 +425,6 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
writeBuffer.position(0); writeBuffer.position(0);
serializer.write(writeBuffer, object); serializer.write(writeBuffer, object);
writeBuffer.flip(); 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); snet.sendP2PPacket(sid, writeBuffer, mode == SendMode.tcp ? object instanceof StreamChunk ? P2PSend.ReliableWithBuffering : P2PSend.Reliable : P2PSend.UnreliableNoDelay, 0);
}catch(Exception e){ }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 @Override
public void close(){ public void close(){
snet.closeP2PSessionWithUser(sid); snet.closeP2PSessionWithUser(sid);