Fixed invalid healing effects
This commit is contained in:
@@ -188,24 +188,22 @@ public class ArcNetProvider implements NetProvider{
|
||||
|
||||
@Override
|
||||
public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> invalid){
|
||||
executor.submit(() -> {
|
||||
try{
|
||||
DatagramSocket socket = new DatagramSocket();
|
||||
long time = Time.millis();
|
||||
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
|
||||
socket.setSoTimeout(2000);
|
||||
try{
|
||||
DatagramSocket socket = new DatagramSocket();
|
||||
long time = Time.millis();
|
||||
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
|
||||
socket.setSoTimeout(2000);
|
||||
|
||||
DatagramPacket packet = packetSupplier.get();
|
||||
socket.receive(packet);
|
||||
DatagramPacket packet = packetSupplier.get();
|
||||
socket.receive(packet);
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
||||
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
|
||||
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
||||
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
|
||||
|
||||
Core.app.post(() -> valid.get(host));
|
||||
}catch(Exception e){
|
||||
Core.app.post(() -> invalid.get(e));
|
||||
}
|
||||
});
|
||||
Core.app.post(() -> valid.get(host));
|
||||
}catch(Exception e){
|
||||
Core.app.post(() -> invalid.get(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.func.*;
|
||||
import arc.net.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.async.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.net.Packets.*;
|
||||
import mindustry.net.Streamable.*;
|
||||
@@ -12,6 +13,7 @@ import mindustry.net.Streamable.*;
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static arc.util.Log.*;
|
||||
import static mindustry.Vars.*;
|
||||
@@ -31,6 +33,7 @@ public class Net{
|
||||
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
|
||||
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
||||
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
||||
private final ExecutorService pingExecutor = Threads.executor(Math.max(Runtime.getRuntime().availableProcessors(), 6));
|
||||
|
||||
private final NetProvider provider;
|
||||
|
||||
@@ -316,10 +319,17 @@ public class Net{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pings a host in an new thread. If an error occured, failed() should be called with the exception.
|
||||
* Pings a host in a pooled thread. If an error occurred, failed() should be called with the exception.
|
||||
*/
|
||||
public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> failed){
|
||||
provider.pingHost(address, port, valid, failed);
|
||||
pingExecutor.submit(() -> provider.pingHost(address, port, valid, failed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pings a host in an new thread. If an error occurred, failed() should be called with the exception.
|
||||
*/
|
||||
public void pingHostThread(String address, int port, Cons<Host> valid, Cons<Exception> failed){
|
||||
Threads.daemon(() -> provider.pingHost(address, port, valid, failed));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,7 +377,7 @@ public class Net{
|
||||
*/
|
||||
void discoverServers(Cons<Host> callback, Runnable done);
|
||||
|
||||
/** Ping a host. If an error occurred, failed() should be called with the exception. */
|
||||
/** Ping a host. If an error occurred, failed() should be called with the exception. This method should block. */
|
||||
void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> failed);
|
||||
|
||||
/** Host a server at specified port. */
|
||||
|
||||
Reference in New Issue
Block a user