use of net.minecraft.network.ServerStatusResponse in project SpongeCommon by SpongePowered.
the class MixinLegacyPingHandler method readLegacy.
private boolean readLegacy(ChannelHandlerContext ctx, ByteBuf buf) {
if (buf.readUnsignedByte() != 0xFE) {
return false;
}
MinecraftServer server = this.networkSystem.getServer();
InetSocketAddress client = (InetSocketAddress) ctx.channel().remoteAddress();
ServerStatusResponse response;
int i = buf.readableBytes();
switch(i) {
case 0:
LOGGER.debug("Ping: (<=1.3) from {}:{}", client.getAddress(), client.getPort());
response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_3, null);
if (response != null) {
this.writeResponse(ctx, String.format("%s§%d§%d", SpongeStatusResponse.getUnformattedMotd(response), response.getPlayers().getOnlinePlayerCount(), response.getPlayers().getMaxPlayers()));
} else {
ctx.close();
}
break;
case 1:
if (buf.readUnsignedByte() != 0x01) {
return false;
}
LOGGER.debug("Ping: (1.4-1.5) from {}:{}", client.getAddress(), client.getPort());
response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_5, null);
if (response != null) {
this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getOnlinePlayerCount(), response.getPlayers().getMaxPlayers()));
} else {
ctx.close();
}
break;
default:
if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) {
return false;
}
if (!buf.isReadable(2)) {
break;
}
short length = buf.readShort();
if (!buf.isReadable(length * 2)) {
break;
}
if (!buf.readBytes(length * 2).toString(Charsets.UTF_16BE).equals("MC|PingHost")) {
return false;
}
if (!buf.isReadable(2)) {
break;
}
length = buf.readShort();
if (!buf.isReadable(length)) {
break;
}
int protocol = buf.readUnsignedByte();
length = buf.readShort();
String host = buf.readBytes(length * 2).toString(Charsets.UTF_16BE);
int port = buf.readInt();
LOGGER.debug("Ping: (1.6) from {}:{}", client.getAddress(), client.getPort());
response = SpongeStatusResponse.postLegacy(server, client, new SpongeLegacyMinecraftVersion(SpongeLegacyMinecraftVersion.V1_6, protocol), InetSocketAddress.createUnresolved(NetworkUtil.cleanVirtualHost(host), port));
if (response != null) {
this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getOnlinePlayerCount(), response.getPlayers().getMaxPlayers()));
} else {
ctx.close();
}
break;
}
return true;
}
use of net.minecraft.network.ServerStatusResponse in project SpongeCommon by SpongePowered.
the class SpongeStatusResponse method clone.
private static ServerStatusResponse clone(ServerStatusResponse original) {
ServerStatusResponse clone = new ServerStatusResponse();
clone.setServerDescription(original.getServerDescription());
if (original.getFavicon() != null) {
((ClientPingServerEvent.Response) clone).setFavicon(((StatusResponse) original).getFavicon().get());
}
clone.setPlayers(clone(original.getPlayers()));
clone.setVersion(clone(original.getVersion()));
return clone;
}
use of net.minecraft.network.ServerStatusResponse in project SpongeVanilla by SpongePowered.
the class DedicatedServerMixin_Vanilla method vanilla$onServerInitialize.
@Inject(method = "init()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedPlayerList;<init>(Lnet/minecraft/server/dedicated/DedicatedServer;)V", shift = At.Shift.BEFORE))
private void vanilla$onServerInitialize(CallbackInfoReturnable<Boolean> ci) {
if (this.getFolderName() == null) {
this.setFolderName(this.settings.getStringProperty("level-name", "world"));
}
vanilla$spongeVanilla.initialize();
ServerStatusResponse statusResponse = getServerStatusResponse();
statusResponse.setServerDescription(new TextComponentString(this.getMotd()));
statusResponse.setVersion(new ServerStatusResponse.Version(MINECRAFT_VERSION.getName(), MINECRAFT_VERSION.getProtocol()));
this.applyServerIconToResponse(statusResponse);
}
use of net.minecraft.network.ServerStatusResponse in project Arclight by IzzelAliz.
the class ServerStatusNetHandlerMixin method arclight$handleServerPing.
@Redirect(method = "processServerQuery", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;sendPacket(Lnet/minecraft/network/IPacket;)V"))
private void arclight$handleServerPing(NetworkManager networkManager, IPacket<?> packetIn) {
Object[] players = this.server.getPlayerList().players.toArray();
ArclightPingEvent event = new ArclightPingEvent(networkManager, server);
Bukkit.getPluginManager().callEvent(event);
List<GameProfile> profiles = new ArrayList<>(players.length);
Object[] array;
for (int length = (array = players).length, i = 0; i < length; ++i) {
Object player = array[i];
if (player != null) {
profiles.add(((ServerPlayerEntity) player).getGameProfile());
}
}
ServerStatusResponse.Players playerSample = new ServerStatusResponse.Players(event.getMaxPlayers(), profiles.size());
if (!profiles.isEmpty()) {
Collections.shuffle(profiles);
profiles = profiles.subList(0, Math.min(profiles.size(), SpigotConfig.playerSample));
}
playerSample.setPlayers(profiles.toArray(new GameProfile[0]));
ServerStatusResponse ping = new ServerStatusResponse();
ping.setFavicon(event.icon.value);
ping.setServerDescription(new StringTextComponent(event.getMotd()));
ping.setPlayers(playerSample);
int version = SharedConstants.getVersion().getProtocolVersion();
ping.setVersion(new ServerStatusResponse.Version(this.server.getServerModName() + " " + this.server.getMinecraftVersion(), version));
ping.setForgeData(this.server.getServerStatusResponse().getForgeData());
networkManager.sendPacket(new SServerInfoPacket(ping));
}
use of net.minecraft.network.ServerStatusResponse in project Magma by magmafoundation.
the class StandardPaperServerListPingEventImpl method processRequest.
@SuppressWarnings("deprecation")
public static void processRequest(MinecraftServer server, NetworkManager networkManager) {
StandardPaperServerListPingEventImpl event = new StandardPaperServerListPingEventImpl(server, networkManager, server.getServerStatusResponse());
server.server.getPluginManager().callEvent(event);
// Close connection immediately if event is cancelled
if (event.isCancelled()) {
networkManager.closeChannel(null);
return;
}
// Setup response
ServerStatusResponse ping = new ServerStatusResponse();
// Description
ping.setServerDescription(new TextComponentString(event.getMotd()));
// Players
if (!event.shouldHidePlayers()) {
ping.setPlayers(new ServerStatusResponse.Players(event.getMaxPlayers(), event.getNumPlayers()));
ping.getPlayers().setPlayers(event.getPlayerSampleHandle());
}
// Version
ping.setVersion(new ServerStatusResponse.Version(event.getVersion(), event.getProtocolVersion()));
// Favicon
if (event.getServerIcon() != null) {
ping.setFavicon(event.getServerIcon().getData());
}
// Send response
networkManager.sendPacket(new SPacketServerInfo(ping));
}
Aggregations