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.publichost.name = Public Game Visibility
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.cancel = Cancel & Exit
setting.bloom.name = Bloom

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.net;
import io.anuke.annotations.Annotations.*;
import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.function.*;
@ -20,6 +21,7 @@ public class Net{
private boolean server;
private boolean active;
private boolean clientLoaded;
private @Nullable StreamBuilder currentStream;
private final Array<Object> packetQueue = new Array<>();
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.
*/
@ -217,7 +223,8 @@ public class Net{
if(object instanceof StreamBegin){
StreamBegin b = (StreamBegin)object;
streams.put(b.id, new StreamBuilder(b));
streams.put(b.id, currentStream = new StreamBuilder(b));
}else if(object instanceof StreamChunk){
StreamChunk c = (StreamChunk)object;
StreamBuilder builder = streams.get(c.id);
@ -228,6 +235,7 @@ public class Net{
if(builder.isDone()){
streams.remove(builder.id);
handleClientReceived(builder.build());
currentStream = null;
}
}else if(clientListeners.get(object.getClass()) != null){

View File

@ -30,7 +30,7 @@ public abstract class NetConnection{
}
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){
PlayerInfo info = netServer.admins.getInfo(player.uuid);

View File

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

View File

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

View File

@ -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;

View File

@ -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);
}
}
}

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 SStats stats;
public static SWorkshop workshop;
public static SUser user;
}

View File

@ -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();
}

View File

@ -532,7 +532,7 @@ public class ServerControl implements ApplicationListener{
Player target = playerGroup.find(p -> p.name.equals(arg[0]));
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);
info("It is done.");
}else{