mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-12 03:37:27 +07:00
Formatting / Removed mobile map screenshots due to crashes
This commit is contained in:
parent
b24770629e
commit
94665e8055
@ -375,7 +375,7 @@ public class Control extends Module{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyTap("screenshot") && !ui.chatfrag.chatOpen()){
|
if(!mobile && Inputs.keyTap("screenshot") && !ui.chatfrag.chatOpen()){
|
||||||
renderer.takeMapScreenshot();
|
renderer.takeMapScreenshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,26 +165,17 @@ public class Saves{
|
|||||||
|
|
||||||
public void save(){
|
public void save(){
|
||||||
long time = totalPlaytime;
|
long time = totalPlaytime;
|
||||||
|
renderer.fog.writeFog();
|
||||||
|
long prev = totalPlaytime;
|
||||||
|
totalPlaytime = time;
|
||||||
|
|
||||||
threads.runGraphics(() -> {
|
SaveIO.saveToSlot(index);
|
||||||
//Renderer fog needs to be written on graphics thread, but save() can run on logic thread
|
meta = SaveIO.getData(index);
|
||||||
//thus, runGraphics is required here
|
if(!state.is(State.menu)){
|
||||||
renderer.fog.writeFog();
|
current = this;
|
||||||
|
}
|
||||||
|
|
||||||
//save on the logic thread
|
totalPlaytime = prev;
|
||||||
threads.run(() -> {
|
|
||||||
long prev = totalPlaytime;
|
|
||||||
totalPlaytime = time;
|
|
||||||
|
|
||||||
SaveIO.saveToSlot(index);
|
|
||||||
meta = SaveIO.getData(index);
|
|
||||||
if(!state.is(State.menu)){
|
|
||||||
current = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
totalPlaytime = prev;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHidden(){
|
public boolean isHidden(){
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
sourceSets.main.java.srcDirs = ["src/"]
|
||||||
|
@ -10,18 +10,18 @@ import io.anuke.ucore.util.Pooling;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ByteSerializer implements Serialization {
|
public class ByteSerializer implements Serialization{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer byteBuffer, Object o) {
|
public void write(ByteBuffer byteBuffer, Object o){
|
||||||
if(o instanceof FrameworkMessage){
|
if(o instanceof FrameworkMessage){
|
||||||
byteBuffer.put((byte)-2); //code for framework message
|
byteBuffer.put((byte) -2); //code for framework message
|
||||||
FrameworkSerializer.write(byteBuffer, (FrameworkMessage)o);
|
FrameworkSerializer.write(byteBuffer, (FrameworkMessage) o);
|
||||||
}else {
|
}else{
|
||||||
if (!(o instanceof Packet))
|
if(!(o instanceof Packet))
|
||||||
throw new RuntimeException("All sent objects must implement be Packets! Class: " + o.getClass());
|
throw new RuntimeException("All sent objects must implement be Packets! Class: " + o.getClass());
|
||||||
byte id = Registrator.getID(o.getClass());
|
byte id = Registrator.getID(o.getClass());
|
||||||
if (id == -1)
|
if(id == -1)
|
||||||
throw new RuntimeException("Unregistered class: " + o.getClass());
|
throw new RuntimeException("Unregistered class: " + o.getClass());
|
||||||
byteBuffer.put(id);
|
byteBuffer.put(id);
|
||||||
((Packet) o).write(byteBuffer);
|
((Packet) o).write(byteBuffer);
|
||||||
@ -29,10 +29,10 @@ public class ByteSerializer implements Serialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(ByteBuffer byteBuffer) {
|
public Object read(ByteBuffer byteBuffer){
|
||||||
byte id = byteBuffer.get();
|
byte id = byteBuffer.get();
|
||||||
if(id == -2){
|
if(id == -2){
|
||||||
return FrameworkSerializer.read(byteBuffer);
|
return FrameworkSerializer.read(byteBuffer);
|
||||||
}else{
|
}else{
|
||||||
Packet packet = Pooling.obtain((Class<Packet>) Registrator.getByID(id).type, (Supplier<Packet>) Registrator.getByID(id).constructor);
|
Packet packet = Pooling.obtain((Class<Packet>) Registrator.getByID(id).type, (Supplier<Packet>) Registrator.getByID(id).constructor);
|
||||||
packet.read(byteBuffer);
|
packet.read(byteBuffer);
|
||||||
@ -41,17 +41,17 @@ public class ByteSerializer implements Serialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLengthLength() {
|
public int getLengthLength(){
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLength(ByteBuffer byteBuffer, int i) {
|
public void writeLength(ByteBuffer byteBuffer, int i){
|
||||||
byteBuffer.putShort((short)i);
|
byteBuffer.putShort((short) i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readLength(ByteBuffer byteBuffer) {
|
public int readLength(ByteBuffer byteBuffer){
|
||||||
return byteBuffer.getShort();
|
return byteBuffer.getShort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,32 +5,32 @@ import com.esotericsoftware.kryonet.FrameworkMessage.*;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class FrameworkSerializer {
|
public class FrameworkSerializer{
|
||||||
|
|
||||||
public static void write(ByteBuffer buffer, FrameworkMessage message){
|
public static void write(ByteBuffer buffer, FrameworkMessage message){
|
||||||
if(message instanceof Ping){
|
if(message instanceof Ping){
|
||||||
Ping p = (Ping)message;
|
Ping p = (Ping) message;
|
||||||
|
|
||||||
buffer.put((byte)0);
|
buffer.put((byte) 0);
|
||||||
buffer.putInt(p.id);
|
buffer.putInt(p.id);
|
||||||
buffer.put(p.isReply ? 1 : (byte)0);
|
buffer.put(p.isReply ? 1 : (byte) 0);
|
||||||
}else if(message instanceof DiscoverHost){
|
}else if(message instanceof DiscoverHost){
|
||||||
DiscoverHost p = (DiscoverHost)message;
|
DiscoverHost p = (DiscoverHost) message;
|
||||||
|
|
||||||
buffer.put((byte)1);
|
buffer.put((byte) 1);
|
||||||
}else if(message instanceof KeepAlive){
|
}else if(message instanceof KeepAlive){
|
||||||
KeepAlive p = (KeepAlive)message;
|
KeepAlive p = (KeepAlive) message;
|
||||||
|
|
||||||
buffer.put((byte)2);
|
buffer.put((byte) 2);
|
||||||
}else if(message instanceof RegisterUDP){
|
}else if(message instanceof RegisterUDP){
|
||||||
RegisterUDP p = (RegisterUDP)message;
|
RegisterUDP p = (RegisterUDP) message;
|
||||||
|
|
||||||
buffer.put((byte)3);
|
buffer.put((byte) 3);
|
||||||
buffer.putInt(p.connectionID);
|
buffer.putInt(p.connectionID);
|
||||||
}else if(message instanceof RegisterTCP){
|
}else if(message instanceof RegisterTCP){
|
||||||
RegisterTCP p = (RegisterTCP)message;
|
RegisterTCP p = (RegisterTCP) message;
|
||||||
|
|
||||||
buffer.put((byte)4);
|
buffer.put((byte) 4);
|
||||||
buffer.putInt(p.connectionID);
|
buffer.putInt(p.connectionID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,14 @@ public class KryoClient implements ClientProvider{
|
|||||||
public KryoClient(){
|
public KryoClient(){
|
||||||
KryoCore.init();
|
KryoCore.init();
|
||||||
|
|
||||||
handler = new ClientDiscoveryHandler() {
|
handler = new ClientDiscoveryHandler(){
|
||||||
@Override
|
@Override
|
||||||
public DatagramPacket onRequestNewDatagramPacket() {
|
public DatagramPacket onRequestNewDatagramPacket(){
|
||||||
return new DatagramPacket(new byte[128], 128);
|
return new DatagramPacket(new byte[128], 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDiscoveredHost(DatagramPacket datagramPacket) {
|
public void onDiscoveredHost(DatagramPacket datagramPacket){
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(datagramPacket.getData());
|
ByteBuffer buffer = ByteBuffer.wrap(datagramPacket.getData());
|
||||||
Host host = NetworkIO.readServerData(datagramPacket.getAddress().getHostAddress(), buffer);
|
Host host = NetworkIO.readServerData(datagramPacket.getAddress().getHostAddress(), buffer);
|
||||||
for(InetAddress address : foundAddresses){
|
for(InetAddress address : foundAddresses){
|
||||||
@ -55,7 +55,7 @@ public class KryoClient implements ClientProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinally() {
|
public void onFinally(){
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -65,7 +65,7 @@ public class KryoClient implements ClientProvider{
|
|||||||
|
|
||||||
Listener listener = new Listener(){
|
Listener listener = new Listener(){
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected(Connection connection){
|
||||||
Connect c = new Connect();
|
Connect c = new Connect();
|
||||||
c.addressTCP = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
c.addressTCP = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
||||||
c.id = connection.getID();
|
c.id = connection.getID();
|
||||||
@ -75,7 +75,7 @@ public class KryoClient implements ClientProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected (Connection connection) {
|
public void disconnected(Connection connection){
|
||||||
if(connection.getLastProtocolError() != null){
|
if(connection.getLastProtocolError() != null){
|
||||||
netClient.setQuiet();
|
netClient.setQuiet();
|
||||||
}
|
}
|
||||||
@ -85,13 +85,13 @@ public class KryoClient implements ClientProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, Object object) {
|
public void received(Connection connection, Object object){
|
||||||
if(object instanceof FrameworkMessage) return;
|
if(object instanceof FrameworkMessage) return;
|
||||||
|
|
||||||
threads.runDelay(() -> {
|
threads.runDelay(() -> {
|
||||||
try{
|
try{
|
||||||
Net.handleClientReceived(object);
|
Net.handleClientReceived(object);
|
||||||
}catch (Exception e){
|
}catch(Exception e){
|
||||||
handleException(e);
|
handleException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -106,12 +106,12 @@ public class KryoClient implements ClientProvider{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isLocal(InetAddress addr) {
|
private static boolean isLocal(InetAddress addr){
|
||||||
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true;
|
if(addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true;
|
||||||
|
|
||||||
try {
|
try{
|
||||||
return NetworkInterface.getByInetAddress(addr) != null;
|
return NetworkInterface.getByInetAddress(addr) != null;
|
||||||
} catch (Exception e) {
|
}catch(Exception e){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,12 +150,12 @@ public class KryoClient implements ClientProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect(){
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Object object, SendMode mode) {
|
public void send(Object object, SendMode mode){
|
||||||
if(mode == SendMode.tcp){
|
if(mode == SendMode.tcp){
|
||||||
client.sendTCP(object);
|
client.sendTCP(object);
|
||||||
}else{
|
}else{
|
||||||
@ -166,12 +166,12 @@ public class KryoClient implements ClientProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePing() {
|
public void updatePing(){
|
||||||
client.updateReturnTripTime();
|
client.updateReturnTripTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPing() {
|
public int getPing(){
|
||||||
return client.getReturnTripTime();
|
return client.getReturnTripTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class KryoClient implements ClientProvider{
|
|||||||
public void dispose(){
|
public void dispose(){
|
||||||
try{
|
try{
|
||||||
client.dispose();
|
client.dispose();
|
||||||
}catch (IOException e){
|
}catch(IOException e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.headless;
|
import static io.anuke.mindustry.Vars.headless;
|
||||||
|
|
||||||
/**Utilities and configs for kryo module.*/
|
/** Utilities and configs for kryo module. */
|
||||||
public class KryoCore {
|
public class KryoCore{
|
||||||
public static boolean fakeLag = false;
|
public static boolean fakeLag = false;
|
||||||
public static final int fakeLagMax = 500;
|
public static final int fakeLagMax = 500;
|
||||||
public static final int fakeLagMin = 0;
|
public static final int fakeLagMin = 0;
|
||||||
@ -26,7 +26,7 @@ public class KryoCore {
|
|||||||
Log.set(fakeLag ? Log.LEVEL_DEBUG : Log.LEVEL_WARN);
|
Log.set(fakeLag ? Log.LEVEL_DEBUG : Log.LEVEL_WARN);
|
||||||
|
|
||||||
Log.setLogger(new Logger(){
|
Log.setLogger(new Logger(){
|
||||||
public void log (int level, String category, String message, Throwable ex) {
|
public void log(int level, String category, String message, Throwable ex){
|
||||||
if(fakeLag){
|
if(fakeLag){
|
||||||
if(message.contains("UDP")){
|
if(message.contains("UDP")){
|
||||||
lastUDP = true;
|
lastUDP = true;
|
||||||
@ -45,7 +45,7 @@ public class KryoCore {
|
|||||||
|
|
||||||
builder.append(message);
|
builder.append(message);
|
||||||
|
|
||||||
if (ex != null) {
|
if(ex != null){
|
||||||
StringWriter writer = new StringWriter(256);
|
StringWriter writer = new StringWriter(256);
|
||||||
ex.printStackTrace(new PrintWriter(writer));
|
ex.printStackTrace(new PrintWriter(writer));
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
@ -60,7 +60,7 @@ public class KryoCore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int calculateLag() {
|
private static int calculateLag(){
|
||||||
return fakeLagMin + (int)(Math.random() * (fakeLagMax - fakeLagMin));
|
return fakeLagMin + (int) (Math.random() * (fakeLagMax - fakeLagMin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.threads;
|
import static io.anuke.mindustry.Vars.threads;
|
||||||
|
|
||||||
public class KryoServer implements ServerProvider {
|
public class KryoServer implements ServerProvider{
|
||||||
final Server server;
|
final Server server;
|
||||||
final CopyOnWriteArrayList<KryoConnection> connections = new CopyOnWriteArrayList<>();
|
final CopyOnWriteArrayList<KryoConnection> connections = new CopyOnWriteArrayList<>();
|
||||||
final CopyOnWriteArraySet<Integer> missing = new CopyOnWriteArraySet<>();
|
final CopyOnWriteArraySet<Integer> missing = new CopyOnWriteArraySet<>();
|
||||||
@ -42,7 +42,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
public KryoServer(){
|
public KryoServer(){
|
||||||
KryoCore.init();
|
KryoCore.init();
|
||||||
|
|
||||||
server = new Server(4096*2, 4096, connection -> new ByteSerializer());
|
server = new Server(4096 * 2, 4096, connection -> new ByteSerializer());
|
||||||
server.setDiscoveryHandler((datagramChannel, fromAddress) -> {
|
server.setDiscoveryHandler((datagramChannel, fromAddress) -> {
|
||||||
ByteBuffer buffer = NetworkIO.writeServerData();
|
ByteBuffer buffer = NetworkIO.writeServerData();
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
@ -53,10 +53,10 @@ public class KryoServer implements ServerProvider {
|
|||||||
Listener listener = new Listener(){
|
Listener listener = new Listener(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected(Connection connection){
|
||||||
String ip = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
String ip = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
||||||
|
|
||||||
KryoConnection kn = new KryoConnection(lastconnection ++, ip, connection);
|
KryoConnection kn = new KryoConnection(lastconnection++, ip, connection);
|
||||||
|
|
||||||
Connect c = new Connect();
|
Connect c = new Connect();
|
||||||
c.id = kn.id;
|
c.id = kn.id;
|
||||||
@ -69,7 +69,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected (Connection connection) {
|
public void disconnected(Connection connection){
|
||||||
KryoConnection k = getByKryoID(connection.getID());
|
KryoConnection k = getByKryoID(connection.getID());
|
||||||
if(k == null) return;
|
if(k == null) return;
|
||||||
|
|
||||||
@ -83,14 +83,14 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, Object object) {
|
public void received(Connection connection, Object object){
|
||||||
KryoConnection k = getByKryoID(connection.getID());
|
KryoConnection k = getByKryoID(connection.getID());
|
||||||
if(object instanceof FrameworkMessage || k == null) return;
|
if(object instanceof FrameworkMessage || k == null) return;
|
||||||
|
|
||||||
threads.runDelay(() -> {
|
threads.runDelay(() -> {
|
||||||
try{
|
try{
|
||||||
Net.handleServerReceived(k.id, object);
|
Net.handleServerReceived(k.id, object);
|
||||||
}catch (Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -110,7 +110,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Array<KryoConnection> getConnections() {
|
public Array<KryoConnection> getConnections(){
|
||||||
array.clear();
|
array.clear();
|
||||||
for(KryoConnection c : connections){
|
for(KryoConnection c : connections){
|
||||||
array.add(c);
|
array.add(c);
|
||||||
@ -120,7 +120,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KryoConnection getByID(int id){
|
public KryoConnection getByID(int id){
|
||||||
for(int i = 0; i < connections.size(); i ++){
|
for(int i = 0; i < connections.size(); i++){
|
||||||
KryoConnection con = connections.get(i);
|
KryoConnection con = connections.get(i);
|
||||||
if(con.id == id){
|
if(con.id == id){
|
||||||
return con;
|
return con;
|
||||||
@ -131,7 +131,7 @@ public class KryoServer 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
|
//attempt to open default ports if they're not already open
|
||||||
//this only opens the default port due to security concerns (?)
|
//this only opens the default port due to security concerns (?)
|
||||||
if(port == Vars.port){
|
if(port == Vars.port){
|
||||||
@ -139,7 +139,8 @@ public class KryoServer implements ServerProvider {
|
|||||||
try{
|
try{
|
||||||
if(!UPnP.isMappedTCP(port)) UPnP.openPortTCP(port);
|
if(!UPnP.isMappedTCP(port)) UPnP.openPortTCP(port);
|
||||||
if(!UPnP.isMappedUDP(port)) UPnP.openPortUDP(port);
|
if(!UPnP.isMappedUDP(port)) UPnP.openPortUDP(port);
|
||||||
}catch(Throwable ignored){}
|
}catch(Throwable ignored){
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +152,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
serverThread = new Thread(() -> {
|
serverThread = new Thread(() -> {
|
||||||
try{
|
try{
|
||||||
server.run();
|
server.run();
|
||||||
}catch (Throwable e){
|
}catch(Throwable e){
|
||||||
if(!(e instanceof ClosedSelectorException)) handleException(e);
|
if(!(e instanceof ClosedSelectorException)) handleException(e);
|
||||||
}
|
}
|
||||||
}, "Kryonet Server");
|
}, "Kryonet Server");
|
||||||
@ -160,7 +161,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close(){
|
||||||
connections.clear();
|
connections.clear();
|
||||||
lastconnection = 0;
|
lastconnection = 0;
|
||||||
|
|
||||||
@ -168,17 +169,17 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendStream(int id, Streamable stream) {
|
public void sendStream(int id, Streamable stream){
|
||||||
KryoConnection connection = getByID(id);
|
KryoConnection connection = getByID(id);
|
||||||
if(connection == null) return;
|
if(connection == null) return;
|
||||||
try {
|
try{
|
||||||
|
|
||||||
if (connection.connection != null) {
|
if(connection.connection != null){
|
||||||
|
|
||||||
connection.connection.addListener(new InputStreamSender(stream.stream, 512) {
|
connection.connection.addListener(new InputStreamSender(stream.stream, 512){
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
protected void start() {
|
protected void start(){
|
||||||
//send an object so the receiving side knows how to handle the following chunks
|
//send an object so the receiving side knows how to handle the following chunks
|
||||||
StreamBegin begin = new StreamBegin();
|
StreamBegin begin = new StreamBegin();
|
||||||
begin.total = stream.stream.available();
|
begin.total = stream.stream.available();
|
||||||
@ -187,14 +188,14 @@ public class KryoServer implements ServerProvider {
|
|||||||
id = begin.id;
|
id = begin.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object next(byte[] bytes) {
|
protected Object next(byte[] bytes){
|
||||||
StreamChunk chunk = new StreamChunk();
|
StreamChunk chunk = new StreamChunk();
|
||||||
chunk.id = id;
|
chunk.id = id;
|
||||||
chunk.data = bytes;
|
chunk.data = bytes;
|
||||||
return chunk; //wrap the byte[] with an object so the receiving side knows how to handle it.
|
return chunk; //wrap the byte[] with an object so the receiving side knows how to handle it.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}else{
|
||||||
int cid;
|
int cid;
|
||||||
StreamBegin begin = new StreamBegin();
|
StreamBegin begin = new StreamBegin();
|
||||||
begin.total = stream.stream.available();
|
begin.total = stream.stream.available();
|
||||||
@ -202,7 +203,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
connection.send(begin, SendMode.tcp);
|
connection.send(begin, SendMode.tcp);
|
||||||
cid = begin.id;
|
cid = begin.id;
|
||||||
|
|
||||||
while (stream.stream.available() > 0) {
|
while(stream.stream.available() > 0){
|
||||||
byte[] bytes = new byte[Math.min(512, stream.stream.available())];
|
byte[] bytes = new byte[Math.min(512, stream.stream.available())];
|
||||||
stream.stream.read(bytes);
|
stream.stream.read(bytes);
|
||||||
|
|
||||||
@ -212,20 +213,20 @@ public class KryoServer implements ServerProvider {
|
|||||||
connection.send(chunk, SendMode.tcp);
|
connection.send(chunk, SendMode.tcp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (IOException e){
|
}catch(IOException e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Object object, SendMode mode) {
|
public void send(Object object, SendMode mode){
|
||||||
for(int i = 0; i < connections.size(); i ++){
|
for(int i = 0; i < connections.size(); i++){
|
||||||
connections.get(i).send(object, mode);
|
connections.get(i).send(object, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendTo(int id, Object object, SendMode mode) {
|
public void sendTo(int id, Object object, SendMode mode){
|
||||||
NetConnection conn = getByID(id);
|
NetConnection conn = getByID(id);
|
||||||
if(conn == null){
|
if(conn == null){
|
||||||
if(!missing.contains(id))
|
if(!missing.contains(id))
|
||||||
@ -237,8 +238,8 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendExcept(int id, Object object, SendMode mode) {
|
public void sendExcept(int id, Object object, SendMode mode){
|
||||||
for(int i = 0; i < connections.size(); i ++){
|
for(int i = 0; i < connections.size(); i++){
|
||||||
KryoConnection conn = connections.get(i);
|
KryoConnection conn = connections.get(i);
|
||||||
if(conn.id != id) conn.send(object, mode);
|
if(conn.id != id) conn.send(object, mode);
|
||||||
}
|
}
|
||||||
@ -251,11 +252,13 @@ public class KryoServer implements ServerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleException(Throwable e){
|
private void handleException(Throwable e){
|
||||||
Timers.run(0f, () -> { throw new RuntimeException(e);});
|
Timers.run(0f, () -> {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
KryoConnection getByKryoID(int id){
|
KryoConnection getByKryoID(int id){
|
||||||
for(int i = 0; i < connections.size(); i ++){
|
for(int i = 0; i < connections.size(); i++){
|
||||||
KryoConnection con = connections.get(i);
|
KryoConnection con = connections.get(i);
|
||||||
if(con.connection != null && con.connection.getID() == id){
|
if(con.connection != null && con.connection.getID() == id){
|
||||||
return con;
|
return con;
|
||||||
@ -274,7 +277,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
class KryoConnection extends NetConnection{
|
class KryoConnection extends NetConnection{
|
||||||
public final Connection connection;
|
public final Connection connection;
|
||||||
|
|
||||||
public KryoConnection(int id, String address, Connection connection) {
|
public KryoConnection(int id, String address, Connection connection){
|
||||||
super(id, address);
|
super(id, address);
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
@ -286,13 +289,13 @@ public class KryoServer implements ServerProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Object object, SendMode mode){
|
public void send(Object object, SendMode mode){
|
||||||
try {
|
try{
|
||||||
if (mode == SendMode.tcp) {
|
if(mode == SendMode.tcp){
|
||||||
connection.sendTCP(object);
|
connection.sendTCP(object);
|
||||||
} else {
|
}else{
|
||||||
connection.sendUDP(object);
|
connection.sendUDP(object);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch(Exception e){
|
||||||
Log.err(e);
|
Log.err(e);
|
||||||
Log.info("Disconnecting invalid client!");
|
Log.info("Disconnecting invalid client!");
|
||||||
connection.close();
|
connection.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user