private void func_147138_a(ServerStatusResponse p_147138_1_) { File var2 = this.getFile("server-icon.png"); if (var2.isFile()) { ByteBuf var3 = Unpooled.buffer(); try { BufferedImage var4 = ImageIO.read(var2); Validate.validState(var4.getWidth() == 64, "Must be 64 pixels wide", new Object[0]); Validate.validState(var4.getHeight() == 64, "Must be 64 pixels high", new Object[0]); ImageIO.write(var4, "PNG", new ByteBufOutputStream(var3)); ByteBuf var5 = Base64.encode(var3); p_147138_1_.func_151320_a("data:image/png;base64," + var5.toString(Charsets.UTF_8)); } catch (Exception var6) { logger.error("Couldn\'t load server icon", var6); } } }
private void addFaviconToStatusResponse(ServerStatusResponse response) { File file1 = this.getFile("server-icon.png"); if (file1.isFile()) { ByteBuf bytebuf = Unpooled.buffer(); try { BufferedImage bufferedimage = ImageIO.read(file1); Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]); Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]); ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf))); ByteBuf bytebuf1 = Base64.encode(bytebuf); response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8)); } catch (Exception exception) { logger.error((String)"Couldn\'t load server icon", (Throwable)exception); } finally { bytebuf.release(); } } }
public void applyServerIconToResponse(ServerStatusResponse response) { File file1 = this.getFile("server-icon.png"); if (!file1.exists()) { file1 = this.getActiveAnvilConverter().getFile(this.getFolderName(), "icon.png"); } if (file1.isFile()) { ByteBuf bytebuf = Unpooled.buffer(); try { BufferedImage bufferedimage = ImageIO.read(file1); Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]); Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]); ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf))); ByteBuf bytebuf1 = Base64.encode(bytebuf); response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8)); } catch (Exception exception) { LOG.error((String)"Couldn\'t load server icon", (Throwable)exception); } finally { bytebuf.release(); } } }
public void captureAdditionalData(ServerStatusResponse serverstatusresponse, JsonObject jsonobject) { if (jsonobject.has("modinfo")) { JsonObject fmlData = jsonobject.get("modinfo").getAsJsonObject(); extraServerListData.put(serverstatusresponse, fmlData); } }
@Override public OptionalInt getProtocolVersion(StatusResponse response) { if (response instanceof ServerStatusResponse) { return OptionalInt.of(((ServerStatusResponse) response).getProtocolVersionInfo().getProtocol()); } else { return OptionalInt.empty(); } }
@Override public boolean setVersion(ClientPingServerEvent.Response response, String name, int protocol) { if (response instanceof ServerStatusResponse) { ((ServerStatusResponse) response).setProtocolVersionInfo(new ServerStatusResponse.MinecraftProtocolVersionIdentifier(name, protocol)); return true; } else { return false; } }
@Override public OptionalInt getProtocolVersion(StatusResponse response) { if (response instanceof ServerStatusResponse) { return OptionalInt.of(((ServerStatusResponse) response).getVersion().getProtocol()); } else { return OptionalInt.empty(); } }
@Override public boolean setVersion(ClientPingServerEvent.Response response, String name, int protocol) { if (response instanceof ServerStatusResponse) { ((ServerStatusResponse) response).setVersion(new ServerStatusResponse.Version(name, protocol)); return true; } else { return false; } }
@Inject(method = "deserialize", at = @At("RETURN")) private void onDeserialize(JsonElement element, Type type, JsonDeserializationContext ctx, CallbackInfoReturnable<ServerStatusResponse> cir) { JsonObject json = element.getAsJsonObject(); ServerStatusResponse response = cir.getReturnValue(); ServerType serverType = null; ServerCompatibility serverCompat = null; if (json.has("spongeInfo")) { JsonObject spongeInfo = json.getAsJsonObject("spongeInfo"); serverType = spongeInfo.has("serverType") ? ServerType.valueOf(spongeInfo.get("serverType").getAsString().toUpperCase()) : null; // Mainly means the server compatibility against the vanilla client serverCompat = spongeInfo.has("serverCompat") ? ServerCompatibility.valueOf( spongeInfo.get("serverCompat").getAsString().toUpperCase()) : null; } // System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(json.getAsJsonObject("modinfo"))); if (serverType == null || serverCompat == null) { JsonObject modInfo = json.has("modinfo") ? json.getAsJsonObject("modinfo") : null; if (modInfo != null && modInfo.has("modList")) { List<String> mods = StreamSupport.stream(modInfo.getAsJsonArray("modList").spliterator(), false) .map(e -> e.getAsJsonObject().get("modid").getAsString()) .collect(Collectors.toList()); if (serverType == null) { if (mods.contains("sponge")) { serverType = ServerType.SPONGE_FORGE; } else { serverType = ServerType.FORGE; } } } else { if (serverCompat == null) { serverCompat = ServerCompatibility.UNKNOWN; } } } ((IMixinServerStatusResponse) response).setSpongeInfo(new SpongeStatusInfo( serverType == null ? ServerType.VANILLA : serverType, serverCompat == null ? ServerCompatibility.UNKNOWN : serverCompat)); }
@Overwrite public void processServerQuery(C00PacketServerQuery packetIn) { ServerListPingHook hook = (ServerListPingHook) new ServerListPingHook((InetSocketAddress) networkManager.getRemoteAddress(), ((IMixinNetworkManager) networkManager).getProtocolVersion(), ((IMixinNetworkManager) networkManager).getHostnamePinged(), ((IMixinNetworkManager) networkManager).getPortPinged(), new NeptuneChatComponent(server.getServerStatusResponse().getServerDescription()), server.getServerStatusResponse().getPlayerCountData().getOnlinePlayerCount(), server.getServerStatusResponse().getPlayerCountData().getMaxPlayers(), server.getServerStatusResponse().getFavicon(), Arrays.asList(server.getServerStatusResponse().getPlayerCountData().getPlayers())).call(); if (hook.isCanceled()) { networkManager.closeChannel(null); return; } ServerStatusResponse response = new ServerStatusResponse(); response.setProtocolVersionInfo(server.getServerStatusResponse().getProtocolVersionInfo()); ServerStatusResponse.PlayerCountData playerCountData = new ServerStatusResponse.PlayerCountData(hook .getMaxPlayers(), hook.getCurrentPlayers()); playerCountData.setPlayers(hook.getProfiles().toArray(new GameProfile[hook.getProfiles().size()])); response.setPlayerCountData(playerCountData); response.setServerDescription(((NeptuneChatComponent) hook.getMotd()).getHandle()); response.setFavicon(hook.getFavicon()); networkManager.sendPacket(new S00PacketServerInfo(response)); }
/** * @author jamierocks - 5th May 2015 * @reason Handle the ServerListPingHook */ @Overwrite public void processServerQuery(C00PacketServerQuery packetIn) { if (handled) { this.networkManager.closeChannel(EXIT_MESSAGE); } else { this.handled = true; ServerListPingHook hook = (ServerListPingHook) new ServerListPingHook((InetSocketAddress) this.networkManager.getRemoteAddress(), ((IMixinNetworkManager) this.networkManager).getProtocolVersion(), ((IMixinNetworkManager) this.networkManager).getHostnamePinged(), ((IMixinNetworkManager) this.networkManager).getPortPinged(), (ChatComponent) this.server.getServerStatusResponse().getServerDescription(), this.server.getServerStatusResponse().getPlayerCountData().getOnlinePlayerCount(), this.server.getServerStatusResponse().getPlayerCountData().getMaxPlayers(), this.server.getServerStatusResponse().getFavicon(), Arrays.asList(this.server.getServerStatusResponse().getPlayerCountData().getPlayers())).call(); if (hook.isCanceled()) { this.networkManager.closeChannel(null); return; } ServerStatusResponse response = new ServerStatusResponse(); response.setProtocolVersionInfo(this.server.getServerStatusResponse().getProtocolVersionInfo()); ServerStatusResponse.PlayerCountData playerCountData = new ServerStatusResponse.PlayerCountData(hook .getMaxPlayers(), hook.getCurrentPlayers()); playerCountData.setPlayers(hook.getProfiles().toArray(new GameProfile[hook.getProfiles().size()])); response.setPlayerCountData(playerCountData); response.setServerDescription((IChatComponent) hook.getMotd()); response.setFavicon(hook.getFavicon()); this.networkManager.sendPacket(new S00PacketServerInfo(response)); } }
private void func_147138_a(ServerStatusResponse p_147138_1_) { File file1 = this.getFile("server-icon.png"); if (file1.isFile()) { ByteBuf bytebuf = Unpooled.buffer(); try { BufferedImage bufferedimage = ImageIO.read(file1); Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]); Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]); ImageIO.write(bufferedimage, "PNG", new ByteBufOutputStream(bytebuf)); ByteBuf bytebuf1 = Base64.encode(bytebuf); p_147138_1_.func_151320_a("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8)); } catch (Exception exception) { logger.error("Couldn\'t load server icon", exception); } finally { bytebuf.release(); } } }
public S00PacketServerInfo(ServerStatusResponse responseIn) { this.response = responseIn; }
/** * Reads the raw packet data from the data stream. */ public void readPacketData(PacketBuffer buf) throws IOException { this.response = (ServerStatusResponse)GSON.fromJson(buf.readStringFromBuffer(32767), ServerStatusResponse.class); }
/** * Main function called by run() every loop. */ protected void tick() { long i = System.nanoTime(); ++this.tickCounter; if (this.startProfiling) { this.startProfiling = false; this.theProfiler.profilingEnabled = true; this.theProfiler.clearProfiling(); } this.theProfiler.startSection("root"); this.updateTimeLightAndEntities(); if (i - this.nanoTimeSinceStatusRefresh >= 5000000000L) { this.nanoTimeSinceStatusRefresh = i; this.statusResponse.setPlayerCountData(new ServerStatusResponse.PlayerCountData(this.getMaxPlayers(), this.getCurrentPlayerCount())); GameProfile[] agameprofile = new GameProfile[Math.min(this.getCurrentPlayerCount(), 12)]; int j = MathHelper.getRandomIntegerInRange(this.random, 0, this.getCurrentPlayerCount() - agameprofile.length); for (int k = 0; k < agameprofile.length; ++k) { agameprofile[k] = ((EntityPlayerMP)this.serverConfigManager.func_181057_v().get(j + k)).getGameProfile(); } Collections.shuffle(Arrays.asList(agameprofile)); this.statusResponse.getPlayerCountData().setPlayers(agameprofile); } if (this.tickCounter % 900 == 0) { this.theProfiler.startSection("save"); this.serverConfigManager.saveAllPlayerData(); this.saveAllWorlds(true); this.theProfiler.endSection(); } this.theProfiler.startSection("tallying"); this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - i; this.theProfiler.endSection(); this.theProfiler.startSection("snooper"); if (!this.usageSnooper.isSnooperRunning() && this.tickCounter > 100) { this.usageSnooper.startSnooper(); } if (this.tickCounter % 6000 == 0) { this.usageSnooper.addMemoryStatsToSnooper(); } this.theProfiler.endSection(); this.theProfiler.endSection(); }
public ServerStatusResponse getServerStatusResponse() { return this.statusResponse; }
public ServerStatusResponse getResponse() { return this.response; }
/** * Main function called by run() every loop. */ public void tick() { long i = System.nanoTime(); ++this.tickCounter; if (this.startProfiling) { this.startProfiling = false; this.theProfiler.profilingEnabled = true; this.theProfiler.clearProfiling(); } this.theProfiler.startSection("root"); this.updateTimeLightAndEntities(); if (i - this.nanoTimeSinceStatusRefresh >= 5000000000L) { this.nanoTimeSinceStatusRefresh = i; this.statusResponse.setPlayerCountData(new ServerStatusResponse.PlayerCountData(this.getMaxPlayers(), this.getCurrentPlayerCount())); GameProfile[] agameprofile = new GameProfile[Math.min(this.getCurrentPlayerCount(), 12)]; int j = MathHelper.getRandomIntegerInRange(this.random, 0, this.getCurrentPlayerCount() - agameprofile.length); for (int k = 0; k < agameprofile.length; ++k) { agameprofile[k] = ((EntityPlayerMP)this.serverConfigManager.func_181057_v().get(j + k)).getGameProfile(); } Collections.shuffle(Arrays.asList(agameprofile)); this.statusResponse.getPlayerCountData().setPlayers(agameprofile); } if (this.tickCounter % 900 == 0) { this.theProfiler.startSection("save"); this.serverConfigManager.saveAllPlayerData(); this.saveAllWorlds(true); this.theProfiler.endSection(); } this.theProfiler.startSection("tallying"); this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - i; this.theProfiler.endSection(); this.theProfiler.startSection("snooper"); if (!this.usageSnooper.isSnooperRunning() && this.tickCounter > 100) { this.usageSnooper.startSnooper(); } if (this.tickCounter % 6000 == 0) { this.usageSnooper.addMemoryStatsToSnooper(); } this.theProfiler.endSection(); this.theProfiler.endSection(); }