use of net.minecraft.network.ServerStatusResponse in project UtilityClient2 by Utility-Client.
the class OldServerPinger method ping.
public void ping(final ServerData server) throws UnknownHostException {
ServerAddress serveraddress = ServerAddress.func_78860_a(server.serverIP);
final NetworkManager networkmanager = NetworkManager.func_181124_a(InetAddress.getByName(serveraddress.getIP()), serveraddress.getPort(), false);
this.pingDestinations.add(networkmanager);
server.serverMOTD = "Pinging...";
server.pingToServer = -1L;
server.playerList = null;
networkmanager.setNetHandler(new INetHandlerStatusClient() {
private boolean field_147403_d = false;
private boolean field_183009_e = false;
private long field_175092_e = 0L;
public void handleServerInfo(S00PacketServerInfo packetIn) {
if (this.field_183009_e) {
networkmanager.closeChannel(new ChatComponentText("Received unrequested status"));
} else {
this.field_183009_e = true;
ServerStatusResponse serverstatusresponse = packetIn.getResponse();
if (serverstatusresponse.getServerDescription() != null) {
server.serverMOTD = serverstatusresponse.getServerDescription().getFormattedText();
} else {
server.serverMOTD = "";
}
if (serverstatusresponse.getProtocolVersionInfo() != null) {
server.gameVersion = serverstatusresponse.getProtocolVersionInfo().getName();
server.version = serverstatusresponse.getProtocolVersionInfo().getProtocol();
} else {
server.gameVersion = "Old";
server.version = 0;
}
if (serverstatusresponse.getPlayerCountData() != null) {
server.populationInfo = EnumChatFormatting.GRAY + "" + serverstatusresponse.getPlayerCountData().getOnlinePlayerCount() + "" + EnumChatFormatting.DARK_GRAY + "/" + EnumChatFormatting.GRAY + serverstatusresponse.getPlayerCountData().getMaxPlayers();
if (ArrayUtils.isNotEmpty(serverstatusresponse.getPlayerCountData().getPlayers())) {
StringBuilder stringbuilder = new StringBuilder();
for (GameProfile gameprofile : serverstatusresponse.getPlayerCountData().getPlayers()) {
if (stringbuilder.length() > 0) {
stringbuilder.append("\n");
}
stringbuilder.append(gameprofile.getName());
}
if (serverstatusresponse.getPlayerCountData().getPlayers().length < serverstatusresponse.getPlayerCountData().getOnlinePlayerCount()) {
if (stringbuilder.length() > 0) {
stringbuilder.append("\n");
}
stringbuilder.append("... and ").append(serverstatusresponse.getPlayerCountData().getOnlinePlayerCount() - serverstatusresponse.getPlayerCountData().getPlayers().length).append(" more ...");
}
server.playerList = stringbuilder.toString();
}
} else {
server.populationInfo = EnumChatFormatting.DARK_GRAY + "???";
}
if (serverstatusresponse.getFavicon() != null) {
String s = serverstatusresponse.getFavicon();
if (s.startsWith("data:image/png;base64,")) {
server.setBase64EncodedIconData(s.substring("data:image/png;base64,".length()));
} else {
OldServerPinger.logger.error("Invalid server icon (unknown format)");
}
} else {
server.setBase64EncodedIconData((String) null);
}
this.field_175092_e = Minecraft.getSystemTime();
networkmanager.sendPacket(new C01PacketPing(this.field_175092_e));
this.field_147403_d = true;
}
}
public void handlePong(S01PacketPong packetIn) {
long i = this.field_175092_e;
long j = Minecraft.getSystemTime();
server.pingToServer = j - i;
networkmanager.closeChannel(new ChatComponentText("Finished"));
}
public void onDisconnect(IChatComponent reason) {
if (!this.field_147403_d) {
OldServerPinger.logger.error("Can\'t ping " + server.serverIP + ": " + reason.getUnformattedText());
server.serverMOTD = EnumChatFormatting.DARK_RED + "Can\'t connect to server.";
server.populationInfo = "";
OldServerPinger.this.tryCompatibilityPing(server);
}
}
});
try {
networkmanager.sendPacket(new C00Handshake(47, serveraddress.getIP(), serveraddress.getPort(), EnumConnectionState.STATUS));
networkmanager.sendPacket(new C00PacketServerQuery());
} catch (Throwable throwable) {
logger.error((Object) throwable);
}
}
use of net.minecraft.network.ServerStatusResponse in project UtilityClient2 by Utility-Client.
the class RealmsServerStatusPinger method pingServer.
public void pingServer(final String p_pingServer_1_, final RealmsServerPing p_pingServer_2_) throws UnknownHostException {
if (p_pingServer_1_ != null && !p_pingServer_1_.startsWith("0.0.0.0") && !p_pingServer_1_.isEmpty()) {
RealmsServerAddress realmsserveraddress = RealmsServerAddress.parseString(p_pingServer_1_);
final NetworkManager networkmanager = NetworkManager.func_181124_a(InetAddress.getByName(realmsserveraddress.getHost()), realmsserveraddress.getPort(), false);
this.connections.add(networkmanager);
networkmanager.setNetHandler(new INetHandlerStatusClient() {
private boolean field_154345_e = false;
public void handleServerInfo(S00PacketServerInfo packetIn) {
ServerStatusResponse serverstatusresponse = packetIn.getResponse();
if (serverstatusresponse.getPlayerCountData() != null) {
p_pingServer_2_.nrOfPlayers = String.valueOf(serverstatusresponse.getPlayerCountData().getOnlinePlayerCount());
if (ArrayUtils.isNotEmpty(serverstatusresponse.getPlayerCountData().getPlayers())) {
StringBuilder stringbuilder = new StringBuilder();
for (GameProfile gameprofile : serverstatusresponse.getPlayerCountData().getPlayers()) {
if (stringbuilder.length() > 0) {
stringbuilder.append("\n");
}
stringbuilder.append(gameprofile.getName());
}
if (serverstatusresponse.getPlayerCountData().getPlayers().length < serverstatusresponse.getPlayerCountData().getOnlinePlayerCount()) {
if (stringbuilder.length() > 0) {
stringbuilder.append("\n");
}
stringbuilder.append("... and ").append(serverstatusresponse.getPlayerCountData().getOnlinePlayerCount() - serverstatusresponse.getPlayerCountData().getPlayers().length).append(" more ...");
}
p_pingServer_2_.playerList = stringbuilder.toString();
}
} else {
p_pingServer_2_.playerList = "";
}
networkmanager.sendPacket(new C01PacketPing(Realms.currentTimeMillis()));
this.field_154345_e = true;
}
public void handlePong(S01PacketPong packetIn) {
networkmanager.closeChannel(new ChatComponentText("Finished"));
}
public void onDisconnect(IChatComponent reason) {
if (!this.field_154345_e) {
RealmsServerStatusPinger.LOGGER.error("Can\'t ping " + p_pingServer_1_ + ": " + reason.getUnformattedText());
}
}
});
try {
networkmanager.sendPacket(new C00Handshake(RealmsSharedConstants.NETWORK_PROTOCOL_VERSION, realmsserveraddress.getHost(), realmsserveraddress.getPort(), EnumConnectionState.STATUS));
networkmanager.sendPacket(new C00PacketServerQuery());
} catch (Throwable throwable) {
LOGGER.error((Object) throwable);
}
}
}
Aggregations