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