Bugfixes, game startup connection
This commit is contained in:
@@ -9,6 +9,7 @@ import io.anuke.arc.backends.sdl.jni.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.input.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.scene.event.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.util.*;
|
||||
@@ -112,7 +113,7 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
Log.err("Steam client not running.");
|
||||
}else{
|
||||
Vars.steam = true;
|
||||
initSteam();
|
||||
initSteam(args);
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
@@ -122,10 +123,11 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
}
|
||||
}
|
||||
|
||||
void initSteam(){
|
||||
void initSteam(String[] args){
|
||||
SVars.net = new SNet(new ArcNetImpl());
|
||||
SVars.stats = new SStats();
|
||||
SVars.workshop = new SWorkshop();
|
||||
SVars.user = new SUser();
|
||||
|
||||
Events.on(ClientLoadEvent.class, event -> {
|
||||
Core.settings.defaults("name", SVars.net.friends.getPersonaName());
|
||||
@@ -138,6 +140,18 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Core.app.post(() -> {
|
||||
if(args.length >= 2 && args[0].equals("+connect_lobby")){
|
||||
try{
|
||||
long id = Long.parseLong(args[1]);
|
||||
ui.join.connect("steam:" + id, port);
|
||||
}catch(Exception e){
|
||||
Log.err("Failed to parse steam lobby ID: {0}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
//steam shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(SteamAPI::shutdown));
|
||||
@@ -227,6 +241,16 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
|
||||
@Override
|
||||
public String getUUID(){
|
||||
if(steam){
|
||||
try{
|
||||
byte[] result = new byte[8];
|
||||
new RandomXS128(SVars.user.user.getSteamID().getAccountID()).nextBytes(result);
|
||||
return new String(Base64Coder.encode(result));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
NetworkInterface out;
|
||||
|
||||
@@ -37,7 +37,6 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
|
||||
final CopyOnWriteArrayList<NetConnection> connectionsOut = new CopyOnWriteArrayList<>();
|
||||
final IntMap<SteamConnection> steamConnections = new IntMap<>(); //maps steam ID -> valid net connection
|
||||
final ObjectMap<String, SteamID> lobbyIDs = new ObjectMap<>();
|
||||
|
||||
SteamID currentLobby, currentServer;
|
||||
Consumer<Host> lobbyCallback;
|
||||
@@ -92,10 +91,13 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
public void connectClient(String ip, int port, Runnable success) throws IOException{
|
||||
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);
|
||||
try{
|
||||
SteamID lobby = SteamID.createFromNativeHandle(Long.parseLong(lobbyname));
|
||||
joinCallback = success;
|
||||
smat.joinLobby(lobby);
|
||||
}catch(NumberFormatException e){
|
||||
throw new IOException("Invalid Steam ID: " + lobbyname);
|
||||
}
|
||||
}else{
|
||||
provider.connectClient(ip, port, success);
|
||||
}
|
||||
@@ -251,7 +253,6 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
disconnectSteamUser(who);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -284,7 +285,6 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
smat.getLobbyMemberLimit(lobby)
|
||||
);
|
||||
|
||||
lobbyIDs.put(lobby.getAccountID() + "", lobby);
|
||||
lobbyCallback.accept(out);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
@@ -447,7 +447,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
snet.closeP2PSessionWithUser(sid);
|
||||
disconnectSteamUser(sid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
desktop/src/io/anuke/mindustry/desktop/steam/SUser.java
Normal file
23
desktop/src/io/anuke/mindustry/desktop/steam/SUser.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package io.anuke.mindustry.desktop.steam;
|
||||
|
||||
import com.codedisaster.steamworks.*;
|
||||
import com.codedisaster.steamworks.SteamAuth.*;
|
||||
|
||||
public class SUser implements SteamUserCallback{
|
||||
public final SteamUser user = new SteamUser(this);
|
||||
|
||||
@Override
|
||||
public void onValidateAuthTicket(SteamID steamID, AuthSessionResponse authSessionResponse, SteamID ownerSteamID){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMicroTxnAuthorization(int appID, long orderID, boolean authorized){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEncryptedAppTicket(SteamResult result){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@ public class SVars{
|
||||
public static SNet net;
|
||||
public static SStats stats;
|
||||
public static SWorkshop workshop;
|
||||
public static SUser user;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public class SWorkshop implements SteamUGCCallback{
|
||||
|
||||
@Override
|
||||
public void onSubscribeItem(SteamPublishedFileID publishedFileID, SteamResult result){
|
||||
ItemInstallInfo info = new ItemInstallInfo();
|
||||
ugc.getItemInstallInfo(publishedFileID, info);
|
||||
Log.info("Item subscribed from {0}", info.getFolder());
|
||||
SAchievement.downloadMapWorkshop.complete();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user