Progress
This commit is contained in:
@@ -316,6 +316,5 @@ project(":net"){
|
|||||||
dependencies{
|
dependencies{
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
compile "org.lz4:lz4-java:1.4.1"
|
compile "org.lz4:lz4-java:1.4.1"
|
||||||
compile 'com.github.Anuken:WaifUPnP:05eb46bc577fd7674596946ba288c96c0cedd893'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package io.anuke.mindustry.desktopsdl.steam;
|
||||||
|
|
||||||
|
import com.codedisaster.steamworks.*;
|
||||||
|
import com.codedisaster.steamworks.SteamNetworking.*;
|
||||||
|
import io.anuke.arc.collection.*;
|
||||||
|
import io.anuke.arc.util.*;
|
||||||
|
import io.anuke.mindustry.net.Net.*;
|
||||||
|
import io.anuke.mindustry.net.*;
|
||||||
|
|
||||||
|
import java.nio.*;
|
||||||
|
|
||||||
|
public class ClientSteam implements SteamNetworkingCallback{
|
||||||
|
private SteamNetworking steam;
|
||||||
|
private ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 128);
|
||||||
|
//maps steam ID -> valid net connection
|
||||||
|
private IntMap<SteamConnection> connections = new IntMap<>();
|
||||||
|
|
||||||
|
public ClientSteam(){
|
||||||
|
steam = new SteamNetworking(this);
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
int length;
|
||||||
|
SteamID from = new SteamID();
|
||||||
|
while((length = steam.isP2PPacketAvailable(0)) != 0){
|
||||||
|
try{
|
||||||
|
buffer.position(0);
|
||||||
|
steam.readP2PPacket(from, buffer, 0);
|
||||||
|
}catch(SteamException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}){{
|
||||||
|
setDaemon(true);
|
||||||
|
}}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onP2PSessionConnectFail(SteamID steamIDRemote, P2PSessionError sessionError){
|
||||||
|
Log.info("{0} has disconnected: {1}", steamIDRemote.getAccountID(), sessionError);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onP2PSessionRequest(SteamID steamIDRemote){
|
||||||
|
steam.acceptP2PSessionWithUser(steamIDRemote);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SteamConnection extends NetConnection{
|
||||||
|
public final SteamID connection;
|
||||||
|
|
||||||
|
public SteamConnection(int id, String address, SteamID connection){
|
||||||
|
super(id, address);
|
||||||
|
this.connection = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConnected(){
|
||||||
|
return false;//connection.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(Object object, SendMode mode){
|
||||||
|
//TODO
|
||||||
|
/*
|
||||||
|
try{
|
||||||
|
if(mode == SendMode.tcp){
|
||||||
|
connection.sendTCP(object);
|
||||||
|
}else{
|
||||||
|
connection.sendUDP(object);
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
Log.err(e);
|
||||||
|
Log.info("Error sending packet. Disconnecting invalid client!");
|
||||||
|
connection.close();
|
||||||
|
|
||||||
|
ArcNetServer.KryoConnection k = getByKryoID(connection.getID());
|
||||||
|
if(k != null) connections.remove(k);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(){
|
||||||
|
//TODO
|
||||||
|
//if(connection.isConnected()) connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package io.anuke.mindustry.net;
|
package io.anuke.mindustry.net;
|
||||||
|
|
||||||
import com.dosse.upnp.*;
|
|
||||||
import io.anuke.arc.*;
|
import io.anuke.arc.*;
|
||||||
import io.anuke.arc.collection.*;
|
import io.anuke.arc.collection.*;
|
||||||
import io.anuke.arc.net.*;
|
import io.anuke.arc.net.*;
|
||||||
import io.anuke.arc.util.*;
|
import io.anuke.arc.util.*;
|
||||||
import io.anuke.mindustry.*;
|
|
||||||
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 net.jpountz.lz4.*;
|
||||||
@@ -121,18 +119,6 @@ public class ArcNetServer implements ServerProvider{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void host(int port) throws IOException{
|
public void host(int port) throws IOException{
|
||||||
//attempt to open default ports if they're not already open
|
|
||||||
//this only opens the default port due to security concerns (?)
|
|
||||||
if(port == Vars.port){
|
|
||||||
async(() -> {
|
|
||||||
try{
|
|
||||||
if(!UPnP.isMappedTCP(port)) UPnP.openPortTCP(port);
|
|
||||||
if(!UPnP.isMappedUDP(port)) UPnP.openPortUDP(port);
|
|
||||||
}catch(Throwable ignored){
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
lastconnection = 0;
|
lastconnection = 0;
|
||||||
connections.clear();
|
connections.clear();
|
||||||
missing.clear();
|
missing.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user