Bugfixes, game startup connection

This commit is contained in:
Anuken
2019-09-15 12:44:30 -04:00
parent 8480e656b9
commit 369c3b569c
11 changed files with 80 additions and 18 deletions

View File

@@ -563,7 +563,7 @@ setting.crashreport.name = Send Anonymous Crash Reports
setting.savecreate.name = Auto-Create Saves setting.savecreate.name = Auto-Create Saves
setting.publichost.name = Public Game Visibility setting.publichost.name = Public Game Visibility
setting.chatopacity.name = Chat Opacity setting.chatopacity.name = Chat Opacity
setting.playerchat.name = Display In-Game Chat setting.playerchat.name = Display Player Bubble Chat
uiscale.reset = UI scale has been changed.\nPress "OK" to confirm this scale.\n[scarlet]Reverting and exiting in[accent] {0}[] seconds... uiscale.reset = UI scale has been changed.\nPress "OK" to confirm this scale.\n[scarlet]Reverting and exiting in[accent] {0}[] seconds...
uiscale.cancel = Cancel & Exit uiscale.cancel = Cancel & Exit
setting.bloom.name = Bloom setting.bloom.name = Bloom

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.net; package io.anuke.mindustry.net;
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.function.*; import io.anuke.arc.function.*;
@@ -20,6 +21,7 @@ public class Net{
private boolean server; private boolean server;
private boolean active; private boolean active;
private boolean clientLoaded; private boolean clientLoaded;
private @Nullable StreamBuilder currentStream;
private final Array<Object> packetQueue = new Array<>(); private final Array<Object> packetQueue = new Array<>();
private final ObjectMap<Class<?>, Consumer> clientListeners = new ObjectMap<>(); private final ObjectMap<Class<?>, Consumer> clientListeners = new ObjectMap<>();
@@ -196,6 +198,10 @@ public class Net{
} }
} }
public @Nullable StreamBuilder getCurrentStream(){
return currentStream;
}
/** /**
* Registers a client listener for when an object is recieved. * Registers a client listener for when an object is recieved.
*/ */
@@ -217,7 +223,8 @@ public class Net{
if(object instanceof StreamBegin){ if(object instanceof StreamBegin){
StreamBegin b = (StreamBegin)object; StreamBegin b = (StreamBegin)object;
streams.put(b.id, new StreamBuilder(b)); streams.put(b.id, currentStream = new StreamBuilder(b));
}else if(object instanceof StreamChunk){ }else if(object instanceof StreamChunk){
StreamChunk c = (StreamChunk)object; StreamChunk c = (StreamChunk)object;
StreamBuilder builder = streams.get(c.id); StreamBuilder builder = streams.get(c.id);
@@ -228,6 +235,7 @@ public class Net{
if(builder.isDone()){ if(builder.isDone()){
streams.remove(builder.id); streams.remove(builder.id);
handleClientReceived(builder.build()); handleClientReceived(builder.build());
currentStream = null;
} }
}else if(clientListeners.get(object.getClass()) != null){ }else if(clientListeners.get(object.getClass()) != null){

View File

@@ -30,7 +30,7 @@ public abstract class NetConnection{
} }
public void kick(KickReason reason){ public void kick(KickReason reason){
Log.info("Kicking connection {0}; Reason: {2}", address, reason.name()); Log.info("Kicking connection {0}; Reason: {1}", address, reason.name());
if(player != null && (reason == KickReason.kick || reason == KickReason.banned || reason == KickReason.vote) && player.uuid != null){ if(player != null && (reason == KickReason.kick || reason == KickReason.banned || reason == KickReason.vote) && player.uuid != null){
PlayerInfo info = netServer.admins.getInfo(player.uuid); PlayerInfo info = netServer.admins.getInfo(player.uuid);

View File

@@ -16,13 +16,16 @@ public class Streamable implements Packet{
public final int id; public final int id;
public final byte type; public final byte type;
public final int total; public final int total;
public final ByteArrayOutputStream stream; public final ByteArrayOutputStream stream = new ByteArrayOutputStream();
public StreamBuilder(StreamBegin begin){ public StreamBuilder(StreamBegin begin){
id = begin.id; id = begin.id;
type = begin.type; type = begin.type;
total = begin.total; total = begin.total;
stream = new ByteArrayOutputStream(); }
public float progress(){
return (float)stream.size() / total;
} }
public void add(byte[] bytes){ public void add(byte[] bytes){

View File

@@ -310,8 +310,8 @@ public class JoinDialog extends FloatingDialog{
buildServer(host, button); buildServer(host, button);
} }
void connect(String ip, int port){ public void connect(String ip, int port){
if(Core.settings.getString("name").trim().isEmpty()){ if(player.name.trim().isEmpty()){
ui.showInfo("$noname"); ui.showInfo("$noname");
return; return;
} }

View File

@@ -9,6 +9,7 @@ import io.anuke.arc.backends.sdl.jni.*;
import io.anuke.arc.collection.*; import io.anuke.arc.collection.*;
import io.anuke.arc.function.*; import io.anuke.arc.function.*;
import io.anuke.arc.input.*; import io.anuke.arc.input.*;
import io.anuke.arc.math.*;
import io.anuke.arc.scene.event.*; import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.ui.*; import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
@@ -112,7 +113,7 @@ public class DesktopLauncher extends ClientLauncher{
Log.err("Steam client not running."); Log.err("Steam client not running.");
}else{ }else{
Vars.steam = true; Vars.steam = true;
initSteam(); initSteam(args);
} }
}catch(Exception e){ }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.net = new SNet(new ArcNetImpl());
SVars.stats = new SStats(); SVars.stats = new SStats();
SVars.workshop = new SWorkshop(); SVars.workshop = new SWorkshop();
SVars.user = new SUser();
Events.on(ClientLoadEvent.class, event -> { Events.on(ClientLoadEvent.class, event -> {
Core.settings.defaults("name", SVars.net.friends.getPersonaName()); 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 //steam shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(SteamAPI::shutdown)); Runtime.getRuntime().addShutdownHook(new Thread(SteamAPI::shutdown));
@@ -227,6 +241,16 @@ public class DesktopLauncher extends ClientLauncher{
@Override @Override
public String getUUID(){ 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{ try{
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
NetworkInterface out; NetworkInterface out;

View File

@@ -37,7 +37,6 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>(); final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
final CopyOnWriteArrayList<NetConnection> connectionsOut = new CopyOnWriteArrayList<>(); final CopyOnWriteArrayList<NetConnection> connectionsOut = 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; Consumer<Host> lobbyCallback;
@@ -92,10 +91,13 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
public void connectClient(String ip, int port, Runnable success) throws IOException{ public void connectClient(String ip, int port, Runnable success) throws IOException{
if(ip.startsWith("steam:")){ if(ip.startsWith("steam:")){
String lobbyname = ip.substring("steam:".length()); String lobbyname = ip.substring("steam:".length());
SteamID lobby = lobbyIDs.get(lobbyname); try{
if(lobby == null) throw new IOException("Lobby not found."); SteamID lobby = SteamID.createFromNativeHandle(Long.parseLong(lobbyname));
joinCallback = success; joinCallback = success;
smat.joinLobby(lobby); smat.joinLobby(lobby);
}catch(NumberFormatException e){
throw new IOException("Invalid Steam ID: " + lobbyname);
}
}else{ }else{
provider.connectClient(ip, port, success); provider.connectClient(ip, port, success);
} }
@@ -251,7 +253,6 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
disconnectSteamUser(who); disconnectSteamUser(who);
} }
} }
} }
@Override @Override
@@ -284,7 +285,6 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
smat.getLobbyMemberLimit(lobby) smat.getLobbyMemberLimit(lobby)
); );
lobbyIDs.put(lobby.getAccountID() + "", lobby);
lobbyCallback.accept(out); lobbyCallback.accept(out);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
@@ -447,7 +447,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
@Override @Override
public void close(){ public void close(){
snet.closeP2PSessionWithUser(sid); disconnectSteamUser(sid);
} }
} }
} }

View 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){
}
}

View File

@@ -6,4 +6,5 @@ public class SVars{
public static SNet net; public static SNet net;
public static SStats stats; public static SStats stats;
public static SWorkshop workshop; public static SWorkshop workshop;
public static SUser user;
} }

View File

@@ -45,6 +45,9 @@ public class SWorkshop implements SteamUGCCallback{
@Override @Override
public void onSubscribeItem(SteamPublishedFileID publishedFileID, SteamResult result){ 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(); SAchievement.downloadMapWorkshop.complete();
} }

View File

@@ -532,7 +532,7 @@ public class ServerControl implements ApplicationListener{
Player target = playerGroup.find(p -> p.name.equals(arg[0])); Player target = playerGroup.find(p -> p.name.equals(arg[0]));
if(target != null){ if(target != null){
Call.sendMessage("[scarlet] " + target.name + " has been kicked by the server."); Call.sendMessage("[scarlet] " + target.name + "[scarlet] has been kicked by the server.");
target.con.kick(KickReason.kick); target.con.kick(KickReason.kick);
info("It is done."); info("It is done.");
}else{ }else{