Steam cleanup
This commit is contained in:
@@ -10,8 +10,7 @@ import io.anuke.mindustry.net.Net;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.player;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.ui;
|
|
||||||
|
|
||||||
public class HostDialog extends FloatingDialog{
|
public class HostDialog extends FloatingDialog{
|
||||||
float w = 300;
|
float w = 300;
|
||||||
@@ -50,23 +49,29 @@ public class HostDialog extends FloatingDialog{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.loadfrag.show("$hosting");
|
runHost();
|
||||||
Time.runTask(5f, () -> {
|
|
||||||
try{
|
|
||||||
Net.host(Vars.port);
|
|
||||||
player.isAdmin = true;
|
|
||||||
}catch(IOException e){
|
|
||||||
ui.showError(Core.bundle.format("server.error", Strings.parseException(e, true)));
|
|
||||||
}
|
|
||||||
ui.loadfrag.hide();
|
|
||||||
hide();
|
|
||||||
});
|
|
||||||
}).width(w).height(70f);
|
}).width(w).height(70f);
|
||||||
|
|
||||||
cont.addButton("?", () -> ui.showInfo("$host.info")).size(65f, 70f).padLeft(6f);
|
cont.addButton("?", () -> ui.showInfo("$host.info")).size(65f, 70f).padLeft(6f);
|
||||||
|
|
||||||
shown(() -> {
|
shown(() -> {
|
||||||
Core.app.post(() -> Core.settings.getBoolOnce("hostinfo", () -> ui.showInfo("$host.info")));
|
if(!steam){
|
||||||
|
Core.app.post(() -> Core.settings.getBoolOnce("hostinfo", () -> ui.showInfo("$host.info")));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runHost(){
|
||||||
|
ui.loadfrag.show("$hosting");
|
||||||
|
Time.runTask(5f, () -> {
|
||||||
|
try{
|
||||||
|
Net.host(Vars.port);
|
||||||
|
player.isAdmin = true;
|
||||||
|
}catch(IOException e){
|
||||||
|
ui.showError(Core.bundle.format("server.error", Strings.parseException(e, true)));
|
||||||
|
}
|
||||||
|
ui.loadfrag.hide();
|
||||||
|
hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,13 @@ public class PausedDialog extends FloatingDialog{
|
|||||||
|
|
||||||
cont.row();
|
cont.row();
|
||||||
|
|
||||||
cont.addButton("$hostserver", ui.host::show).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
|
cont.addButton("$hostserver", () -> {
|
||||||
|
if(steam){
|
||||||
|
ui.host.runHost();
|
||||||
|
}else{
|
||||||
|
ui.host.show();
|
||||||
|
}
|
||||||
|
}).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
|
||||||
}
|
}
|
||||||
|
|
||||||
cont.row();
|
cont.row();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class DesktopLauncher{
|
|||||||
Platform.instance = new DesktopPlatform(arg);
|
Platform.instance = new DesktopPlatform(arg);
|
||||||
|
|
||||||
if(SteamAPI.isSteamRunning()){
|
if(SteamAPI.isSteamRunning()){
|
||||||
SteamNetImpl net = new SteamNetImpl();
|
SteamCoreNetImpl net = DesktopPlatform.steamCore = new SteamCoreNetImpl();
|
||||||
Net.setClientProvider(net);
|
Net.setClientProvider(net);
|
||||||
Net.setServerProvider(net);
|
Net.setServerProvider(net);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import io.anuke.arc.util.serialization.*;
|
|||||||
import io.anuke.mindustry.*;
|
import io.anuke.mindustry.*;
|
||||||
import io.anuke.mindustry.core.GameState.*;
|
import io.anuke.mindustry.core.GameState.*;
|
||||||
import io.anuke.mindustry.core.*;
|
import io.anuke.mindustry.core.*;
|
||||||
|
import io.anuke.mindustry.desktop.steam.*;
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.net.*;
|
import io.anuke.mindustry.net.*;
|
||||||
@@ -27,7 +28,8 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
|
|
||||||
|
|
||||||
public class DesktopPlatform extends Platform{
|
public class DesktopPlatform extends Platform{
|
||||||
static boolean useDiscord = OS.is64Bit, useSteam = true, showConsole = false;
|
static boolean useDiscord = OS.is64Bit, useSteam = true, showConsole = true;
|
||||||
|
static SteamCoreNetImpl steamCore;
|
||||||
final static String applicationId = "610508934456934412";
|
final static String applicationId = "610508934456934412";
|
||||||
String[] args;
|
String[] args;
|
||||||
|
|
||||||
@@ -50,8 +52,9 @@ public class DesktopPlatform extends Platform{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(useSteam){
|
if(useSteam){
|
||||||
|
|
||||||
if(showConsole){
|
if(showConsole){
|
||||||
Events.on(GameLoadEvent.class, event -> {
|
Events.on(ClientLoadEvent.class, event -> {
|
||||||
Label[] label = {null};
|
Label[] label = {null};
|
||||||
Core.scene.table(t -> {
|
Core.scene.table(t -> {
|
||||||
t.touchable(Touchable.disabled);
|
t.touchable(Touchable.disabled);
|
||||||
@@ -79,15 +82,15 @@ public class DesktopPlatform extends Platform{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Vars.steam = true;
|
|
||||||
try{
|
try{
|
||||||
SteamAPI.loadLibraries();
|
SteamAPI.loadLibraries();
|
||||||
if(!SteamAPI.init()){
|
if(!SteamAPI.init()){
|
||||||
Log.info("Steam client not running. Make sure Steam is running!");
|
Log.info("Steam client not running. Make sure Steam is running!");
|
||||||
}else{
|
}else{
|
||||||
|
Vars.steam = true;
|
||||||
//run steam callbacks
|
//run steam callbacks
|
||||||
Events.on(GameLoadEvent.class, event -> {
|
Events.on(ClientLoadEvent.class, event -> {
|
||||||
|
Core.settings.defaults("name", steamCore.friends.getPersonaName());
|
||||||
//update callbacks
|
//update callbacks
|
||||||
Core.app.addListener(new ApplicationListener(){
|
Core.app.addListener(new ApplicationListener(){
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ 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.*;
|
||||||
import io.anuke.mindustry.net.Packets.*;
|
import io.anuke.mindustry.net.Packets.*;
|
||||||
import net.jpountz.lz4.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
@@ -23,16 +22,14 @@ import java.util.concurrent.*;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, ClientProvider, ServerProvider{
|
public class SteamCoreNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, ClientProvider, ServerProvider{
|
||||||
final SteamNetworking snet = new SteamNetworking(this);
|
public final SteamNetworking snet = new SteamNetworking(this);
|
||||||
final SteamMatchmaking smat = new SteamMatchmaking(this);
|
public final SteamMatchmaking smat = new SteamMatchmaking(this);
|
||||||
final SteamFriends friends = new SteamFriends(this);
|
public final SteamFriends friends = new SteamFriends(this);
|
||||||
|
|
||||||
final PacketSerializer serializer = new PacketSerializer();
|
final PacketSerializer serializer = new PacketSerializer();
|
||||||
final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||||
final ByteBuffer readBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
final ByteBuffer readBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||||
final LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
|
|
||||||
final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
|
||||||
|
|
||||||
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
|
||||||
@@ -42,8 +39,8 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||||||
Consumer<Host> lobbyCallback;
|
Consumer<Host> lobbyCallback;
|
||||||
Runnable lobbyDoneCallback, joinCallback;
|
Runnable lobbyDoneCallback, joinCallback;
|
||||||
|
|
||||||
public SteamNetImpl(){
|
public SteamCoreNetImpl(){
|
||||||
Events.on(GameLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){
|
Events.on(ClientLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){
|
||||||
//read packets
|
//read packets
|
||||||
int length;
|
int length;
|
||||||
SteamID from = new SteamID();
|
SteamID from = new SteamID();
|
||||||
@@ -135,11 +132,6 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] decompressSnapshot(byte[] input, int size){
|
|
||||||
return decompressor.decompress(input, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void discover(Consumer<Host> callback, Runnable done){
|
public void discover(Consumer<Host> callback, Runnable done){
|
||||||
smat.addRequestLobbyListResultCountFilter(32);
|
smat.addRequestLobbyListResultCountFilter(32);
|
||||||
@@ -171,11 +163,6 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||||||
steamConnections.clear();
|
steamConnections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] compressSnapshot(byte[] input){
|
|
||||||
return compressor.compress(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends NetConnection> getConnections(){
|
public Iterable<? extends NetConnection> getConnections(){
|
||||||
return connections;
|
return connections;
|
||||||
@@ -443,13 +430,12 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||||||
@Override
|
@Override
|
||||||
public boolean isConnected(){
|
public boolean isConnected(){
|
||||||
snet.getP2PSessionState(sid, state);
|
snet.getP2PSessionState(sid, state);
|
||||||
return state.isConnectionActive() || state.isConnecting();
|
return state.isConnectionActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(){
|
public void close(){
|
||||||
snet.closeP2PSessionWithUser(sid);
|
snet.closeP2PSessionWithUser(sid);
|
||||||
//smat.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user