1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 03:31:19 +03:00

Fixed issues with multithreaded serializer access

This commit is contained in:
Anuken 2019-08-23 16:13:46 -04:00
parent 5f9000db92
commit 7b41d65fa6
4 changed files with 13 additions and 6 deletions

View File

@ -73,7 +73,6 @@ public class DesktopPlatform extends Platform{
@Override
public void updateRPC(){
if(!useDiscord) return;
Log.info("Updating discord RPC status.");
DiscordRichPresence presence = new DiscordRichPresence();

View File

@ -3,6 +3,7 @@ package io.anuke.mindustry.net;
import io.anuke.arc.*;
import io.anuke.arc.function.*;
import io.anuke.arc.util.async.*;
import io.anuke.arc.util.pooling.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.net.Net.*;
import io.anuke.mindustry.net.Packets.*;
@ -23,7 +24,7 @@ public class MClient implements ClientProvider, ApplicationListener{
}
public void connect(String ip, int port, Runnable success) throws IOException{
socket = new MSocket(InetAddress.getByName(ip), port, new PacketSerializer());
socket = new MSocket(InetAddress.getByName(ip), port, PacketSerializer::new);
socket.addDcListener((sock, reason) -> Core.app.post(() -> Net.handleClientReceived(new Disconnect())));
socket.connectAsync(null, 2000, response -> {
if(response.getType() == ResponseType.ACCEPTED){
@ -43,14 +44,14 @@ public class MClient implements ClientProvider, ApplicationListener{
public void update(){
if(socket == null) return;
socket.update((sock, object) -> Core.app.post(() -> {
socket.update((sock, object) -> {
try{
Net.handleClientReceived(object);
}catch(Exception e){
Net.showError(e);
netClient.disconnectQuietly();
}
}));
});
}
@Override
@ -69,6 +70,8 @@ public class MClient implements ClientProvider, ApplicationListener{
}else{
socket.sendUnreliable(object);
}
Pools.free(object);
}
public int getPing(){

View File

@ -39,6 +39,8 @@ public class MServer implements ServerProvider, ApplicationListener{
@Override
public void host(int port) throws IOException{
close();
socket = new MServerSocket(port, con -> {
MSocket sock = con.accept(null);
@ -78,7 +80,10 @@ public class MServer implements ServerProvider, ApplicationListener{
@Override
public void close(){
if(socket != null) socket.close();
if(socket != null){
socket.close();
socket = null;
}
}
@Override

View File

@ -1,6 +1,6 @@
package io.anuke.mindustry.net;
import io.anuke.arc.function.Supplier;
import io.anuke.arc.function.*;
import io.anuke.arc.net.*;
import io.anuke.arc.net.FrameworkMessage.*;
import io.anuke.arc.util.pooling.*;