use of v1_8_9.net.minecraft.network.handshake.client.C00Handshake in project sol-client-glassmc by danterusdev.
the class Utils method pingServer.
public void pingServer(String address, IntConsumer callback) throws UnknownHostException {
ServerAddress serverAddress = ServerAddress.fromString(address);
NetworkManager networkManager = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(serverAddress.getIP()), serverAddress.getPort(), false);
networkManager.setNetHandler(new INetHandlerStatusClient() {
private boolean expected = false;
private long time = 0L;
@Override
public void handleServerInfo(S00PacketServerInfo packetIn) {
if (expected) {
networkManager.closeChannel(new ChatComponentText("Received unrequested status"));
} else {
expected = true;
time = Minecraft.getSystemTime();
networkManager.sendPacket(new C01PacketPing(this.time));
}
}
@Override
public void handlePong(S01PacketPong packetIn) {
long systemTime = Minecraft.getSystemTime();
callback.accept((int) (systemTime - time));
networkManager.closeChannel(new ChatComponentText("Finished"));
}
@Override
public void onDisconnect(IChatComponent reason) {
callback.accept(-1);
}
});
networkManager.sendPacket(new C00Handshake(47, serverAddress.getIP(), serverAddress.getPort(), EnumConnectionState.STATUS));
networkManager.sendPacket(new C00PacketServerQuery());
}
use of v1_8_9.net.minecraft.network.handshake.client.C00Handshake in project Client by Sol-Client.
the class Utils method pingServer.
public void pingServer(String address, IntConsumer callback) throws UnknownHostException {
ServerAddress serverAddress = ServerAddress.fromString(address);
NetworkManager networkManager = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(serverAddress.getIP()), serverAddress.getPort(), false);
networkManager.setNetHandler(new INetHandlerStatusClient() {
private boolean expected = false;
private long time = 0L;
@Override
public void handleServerInfo(S00PacketServerInfo packetIn) {
if (expected) {
networkManager.closeChannel(new ChatComponentText("Received unrequested status"));
} else {
expected = true;
time = Minecraft.getSystemTime();
networkManager.sendPacket(new C01PacketPing(this.time));
}
}
@Override
public void handlePong(S01PacketPong packetIn) {
long systemTime = Minecraft.getSystemTime();
callback.accept((int) (systemTime - time));
networkManager.closeChannel(new ChatComponentText("Finished"));
}
@Override
public void onDisconnect(IChatComponent reason) {
callback.accept(-1);
}
});
networkManager.sendPacket(new C00Handshake(47, serverAddress.getIP(), serverAddress.getPort(), EnumConnectionState.STATUS));
networkManager.sendPacket(new C00PacketServerQuery());
}
Aggregations