mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-07 17:34:13 +07:00
steam debugging
This commit is contained in:
parent
3294f800be
commit
32abd991e7
@ -46,7 +46,7 @@ task dist(type: Jar, dependsOn: classes){
|
||||
}
|
||||
}
|
||||
|
||||
task steamdist(dependsOn: dist){
|
||||
task steamtest(dependsOn: dist){
|
||||
doLast{
|
||||
copy{
|
||||
from "build/libs/Mindustry-linux-release.jar"
|
||||
@ -60,8 +60,6 @@ task steamdist(dependsOn: dist){
|
||||
|
||||
PackrConfig.Platform.values().each{ platform ->
|
||||
task "packr${platform.toString()}"{
|
||||
def platformName = platform.toString().replace('64', '').replace('32', '').replace('MacOS', 'Mac')
|
||||
|
||||
dependsOn dist
|
||||
|
||||
doLast{
|
||||
@ -134,6 +132,11 @@ PackrConfig.Platform.values().each{ platform ->
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
copy{
|
||||
from "build/packr/output"
|
||||
into "../deploy/${platform.toString()}"
|
||||
}
|
||||
}
|
||||
|
||||
task "zip${platform.toString()}"(type: Zip){
|
||||
@ -149,5 +152,6 @@ PackrConfig.Platform.values().each{ platform ->
|
||||
}
|
||||
|
||||
finalizedBy "zip${platform.toString()}"
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.desktop;
|
||||
|
||||
import com.codedisaster.steamworks.*;
|
||||
import io.anuke.arc.Files.*;
|
||||
import io.anuke.arc.backends.sdl.*;
|
||||
import io.anuke.mindustry.*;
|
||||
@ -13,8 +14,13 @@ public class DesktopLauncher{
|
||||
try{
|
||||
Platform.instance = new DesktopPlatform(arg);
|
||||
|
||||
Net.setClientProvider(new ArcNetClient());
|
||||
Net.setServerProvider(new SteamServerImpl(new ArcNetServer()));
|
||||
if(SteamAPI.isSteamRunning()){
|
||||
Net.setClientProvider(new ArcNetClient());
|
||||
Net.setServerProvider(new SteamServerImpl(new ArcNetServer()));
|
||||
}else{
|
||||
Net.setClientProvider(new ArcNetClient());
|
||||
Net.setServerProvider(new ArcNetServer());
|
||||
}
|
||||
|
||||
new SdlApplication(new Mindustry(), new SdlConfig(){{
|
||||
title = "Mindustry";
|
||||
|
@ -7,7 +7,9 @@ import io.anuke.arc.backends.sdl.jni.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.Log.*;
|
||||
import io.anuke.arc.util.serialization.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.core.GameState.*;
|
||||
@ -46,6 +48,31 @@ public class DesktopPlatform extends Platform{
|
||||
}
|
||||
|
||||
if(useSteam){
|
||||
|
||||
|
||||
Events.on(GameLoadEvent.class, event -> {
|
||||
Label[] label = {null};
|
||||
Core.scene.table(t -> {
|
||||
t.top().left();
|
||||
t.update(() -> t.toFront());
|
||||
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);
|
||||
label[0].getText().append(out).append("\n");
|
||||
label[0].invalidateHierarchy();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
Vars.steam = true;
|
||||
try{
|
||||
SteamAPI.loadLibraries();
|
||||
|
@ -158,6 +158,7 @@ public class SteamClientImpl implements SteamNetworkingCallback, SteamMatchmakin
|
||||
|
||||
@Override
|
||||
public void onLobbyInvite(SteamID steamIDUser, SteamID steamIDLobby, long gameID){
|
||||
Log.info("lobby invite {0} {1} {2}", steamIDLobby.getAccountID(), steamIDUser.getAccountID(), gameID);
|
||||
ui.showConfirm("Someone has invited you to a game.", "But do you accept?", () -> {
|
||||
smat.joinLobby(steamIDLobby);
|
||||
});
|
||||
@ -172,6 +173,7 @@ public class SteamClientImpl implements SteamNetworkingCallback, SteamMatchmakin
|
||||
con.addressTCP = "steam:" + currentServer.getAccountID();
|
||||
|
||||
Net.handleClientReceived(con);
|
||||
Log.info("enter lobby {0} {1}", steamIDLobby.getAccountID(), response);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,28 +11,31 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.*;
|
||||
import io.anuke.mindustry.net.*;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import net.jpountz.lz4.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class SteamServerImpl implements ServerProvider, SteamNetworkingCallback, SteamMatchmakingCallback{
|
||||
private final static int maxLobbyPlayers = 32;
|
||||
|
||||
private final PacketSerializer serializer = new PacketSerializer();
|
||||
private final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||
private final ByteBuffer readBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||
private final SteamNetworking snet = new SteamNetworking(this);
|
||||
private final SteamMatchmaking smat = new SteamMatchmaking(this);
|
||||
private final SteamFriendsImpl friends = new SteamFriendsImpl();
|
||||
private final ServerProvider server;
|
||||
final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
||||
final PacketSerializer serializer = new PacketSerializer();
|
||||
final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||
final ByteBuffer readBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||
final SteamNetworking snet = new SteamNetworking(this);
|
||||
final SteamMatchmaking smat = new SteamMatchmaking(this);
|
||||
final SteamFriendsImpl friends = new SteamFriendsImpl();
|
||||
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
|
||||
//private final ServerProvider server;
|
||||
|
||||
//maps steam ID -> valid net connection
|
||||
private IntMap<SteamConnection> steamConnections = new IntMap<>();
|
||||
|
||||
private SteamID currentLobby;
|
||||
IntMap<SteamConnection> steamConnections = new IntMap<>();
|
||||
SteamID currentLobby;
|
||||
|
||||
public SteamServerImpl(ServerProvider server){
|
||||
this.server = server;
|
||||
//this.server = server;
|
||||
|
||||
//start recieving packets
|
||||
Threads.daemon(() -> {
|
||||
@ -68,13 +71,13 @@ public class SteamServerImpl implements ServerProvider, SteamNetworkingCallback,
|
||||
|
||||
@Override
|
||||
public void host(int port) throws IOException{
|
||||
server.host(port);
|
||||
//server.host(port);
|
||||
smat.createLobby(LobbyType.values()[Core.settings.getInt("lobbytype", 1)], maxLobbyPlayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
server.close();
|
||||
// server.close();
|
||||
if(currentLobby != null){
|
||||
smat.leaveLobby(currentLobby);
|
||||
for(SteamConnection con : steamConnections.values()){
|
||||
@ -88,17 +91,24 @@ public class SteamServerImpl implements ServerProvider, SteamNetworkingCallback,
|
||||
|
||||
@Override
|
||||
public byte[] compressSnapshot(byte[] input){
|
||||
return server.compressSnapshot(input);
|
||||
return compressor.compress(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NetConnection> getConnections(){
|
||||
return server.getConnections();
|
||||
return connections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetConnection getByID(int id){
|
||||
return server.getByID(id);
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
SteamConnection con = connections.get(i);
|
||||
if(con.id == id){
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//steam lobby overrides
|
||||
@ -183,6 +193,17 @@ public class SteamServerImpl implements ServerProvider, SteamNetworkingCallback,
|
||||
public void onP2PSessionRequest(SteamID steamIDRemote){
|
||||
//accept users on request
|
||||
snet.acceptP2PSessionWithUser(steamIDRemote);
|
||||
if(!steamConnections.containsKey(steamIDRemote.getAccountID())){
|
||||
SteamConnection con = new SteamConnection(steamIDRemote);
|
||||
Connect c = new Connect();
|
||||
c.id = con.id;
|
||||
c.addressTCP = "steam:" + steamIDRemote.getAccountID();
|
||||
|
||||
Log.debug("&bRecieved connection: {0}", c.addressTCP);
|
||||
|
||||
connections.add(con);
|
||||
Core.app.post(() -> Net.handleServerReceived(c.id, c));
|
||||
}
|
||||
}
|
||||
|
||||
public class SteamConnection extends NetConnection{
|
||||
|
@ -50,7 +50,7 @@ public class ArcNetServer implements ServerProvider{
|
||||
|
||||
@Override
|
||||
public void disconnected(Connection connection){
|
||||
ArcConnection k = getByKryoID(connection.getID());
|
||||
ArcConnection k = getByArcID(connection.getID());
|
||||
if(k == null) return;
|
||||
|
||||
Disconnect c = new Disconnect();
|
||||
@ -64,7 +64,7 @@ public class ArcNetServer implements ServerProvider{
|
||||
|
||||
@Override
|
||||
public void received(Connection connection, Object object){
|
||||
ArcConnection k = getByKryoID(connection.getID());
|
||||
ArcConnection k = getByArcID(connection.getID());
|
||||
if(object instanceof FrameworkMessage || k == null) return;
|
||||
|
||||
Core.app.post(() -> {
|
||||
@ -131,7 +131,7 @@ public class ArcNetServer implements ServerProvider{
|
||||
Threads.daemon(server::stop);
|
||||
}
|
||||
|
||||
ArcConnection getByKryoID(int id){
|
||||
ArcConnection getByArcID(int id){
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
ArcConnection con = connections.get(i);
|
||||
if(con.connection != null && con.connection.getID() == id){
|
||||
@ -164,7 +164,7 @@ public class ArcNetServer implements ServerProvider{
|
||||
Log.info("Error sending packet. Disconnecting invalid client!");
|
||||
connection.close();
|
||||
|
||||
ArcConnection k = getByKryoID(connection.getID());
|
||||
ArcConnection k = getByArcID(connection.getID());
|
||||
if(k != null) connections.remove(k);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user