use of net.minecraft.network.ClientConnection in project ImmersivePortalsMod by qouteall.
the class ClientWorldLoader method createFakedClientWorld.
// fool minecraft using the faked world
private ClientWorld createFakedClientWorld(DimensionType dimension) {
assert mc.world.dimension.getType() == mc.player.dimension;
assert (mc.player.dimension != dimension);
isLoadingFakedWorld = true;
// TODO get load distance
int chunkLoadDistance = 3;
WorldRenderer worldRenderer = new WorldRenderer(mc);
ClientWorld newWorld;
try {
ClientPlayNetworkHandler newNetworkHandler = new ClientPlayNetworkHandler(mc, new ChatScreen("You should not be seeing me. I'm just a faked screen."), new ClientConnection(NetworkSide.CLIENTBOUND), new GameProfile(null, "faked_profiler_id"));
// multiple net handlers share the same playerListEntries object
((IEClientPlayNetworkHandler) newNetworkHandler).setPlayerListEntries(((IEClientPlayNetworkHandler) mc.player.networkHandler).getPlayerListEntries());
newWorld = new ClientWorld(newNetworkHandler, new LevelInfo(0L, GameMode.CREATIVE, true, isHardCore, LevelGeneratorType.FLAT), dimension, chunkLoadDistance, mc.getProfiler(), worldRenderer);
} catch (Exception e) {
throw new IllegalStateException("Creating Faked World " + dimension + " " + clientWorldMap.keySet(), e);
}
worldRenderer.setWorld(newWorld);
worldRenderer.apply(mc.getResourceManager());
((IEClientPlayNetworkHandler) ((IEClientWorld) newWorld).getNetHandler()).setWorld(newWorld);
clientWorldMap.put(dimension, newWorld);
worldRendererMap.put(dimension, worldRenderer);
Helper.log("Faked World Created " + dimension);
isLoadingFakedWorld = false;
return newWorld;
}
use of net.minecraft.network.ClientConnection in project Client by MatHax.
the class ServerListPinger method add.
public void add(final MServerInfo entry, final Runnable runnable) throws UnknownHostException {
Timer timeoutTimer = new Timer();
ServerAddress serverAddress = ServerAddress.parse(entry.address);
timeoutTimer.schedule(new TimerTask() {
@Override
public void run() {
notifyDisconnectListeners();
}
}, 20000);
final ClientConnection clientConnection = ClientConnection.connect(new InetSocketAddress(InetAddress.getByName(serverAddress.getAddress()), serverAddress.getPort()), false);
failedToConnect = false;
this.clientConnections.add(clientConnection);
entry.label = "multiplayer.status.pinging";
entry.ping = -1L;
entry.playerListSummary = null;
clientConnection.setPacketListener(new ClientQueryPacketListener() {
private boolean sentQuery;
private boolean received;
private long startTime;
public void onResponse(QueryResponseS2CPacket packet) {
if (this.received)
clientConnection.disconnect(new TranslatableText("multiplayer.status.unrequested"));
else {
this.received = true;
ServerMetadata serverMetadata = packet.getServerMetadata();
if (serverMetadata.getDescription() != null)
entry.label = serverMetadata.getDescription().asString();
else
entry.label = "";
if (serverMetadata.getVersion() != null) {
entry.version = serverMetadata.getVersion().getGameVersion();
entry.protocolVersion = serverMetadata.getVersion().getProtocolVersion();
} else {
entry.version = "multiplayer.status.old";
entry.protocolVersion = 0;
}
if (serverMetadata.getPlayers() != null) {
entry.playerCountLabel = ServerListPinger.getPlayerCountLabel(serverMetadata.getPlayers().getOnlinePlayerCount(), serverMetadata.getPlayers().getPlayerLimit());
entry.playerCount = serverMetadata.getPlayers().getOnlinePlayerCount();
entry.playercountMax = serverMetadata.getPlayers().getPlayerLimit();
List<Text> list = Lists.newArrayList();
if (ArrayUtils.isNotEmpty(serverMetadata.getPlayers().getSample())) {
GameProfile[] gameProfiles = serverMetadata.getPlayers().getSample();
for (GameProfile gameProfile : gameProfiles) {
list.add(new LiteralText(gameProfile.getName()));
}
if (serverMetadata.getPlayers().getSample().length < serverMetadata.getPlayers().getOnlinePlayerCount())
list.add(new TranslatableText("multiplayer.status.and_more", serverMetadata.getPlayers().getOnlinePlayerCount() - serverMetadata.getPlayers().getSample().length));
entry.playerListSummary = list;
}
} else
entry.playerCountLabel = "multiplayer.status.unknown";
String string = null;
if (serverMetadata.getFavicon() != null) {
String string2 = serverMetadata.getFavicon();
if (string2.startsWith("data:image/png;base64,"))
string = string2.substring("data:image/png;base64,".length());
else
MatHax.LOG.error("Invalid server icon (unknown format)");
}
if (!Objects.equals(string, entry.getIcon())) {
entry.setIcon(string);
runnable.run();
}
this.startTime = Util.getMeasuringTimeMs();
clientConnection.send(new QueryPingC2SPacket(this.startTime));
this.sentQuery = true;
notifyDisconnectListeners();
}
}
public void onPong(QueryPongS2CPacket packet) {
long l = this.startTime;
long m = Util.getMeasuringTimeMs();
entry.ping = m - l;
clientConnection.disconnect(new TranslatableText("multiplayer.status.finished"));
}
public void onDisconnected(Text reason) {
if (!this.sentQuery) {
MatHax.LOG.error("Can't ping {}: {}", entry.address, reason.getString());
entry.label = "multiplayer.status.cannot_connect";
entry.playerCountLabel = "";
entry.playerCount = 0;
entry.playercountMax = 0;
ServerListPinger.this.ping(entry);
}
notifyDisconnectListeners();
}
public ClientConnection getConnection() {
return clientConnection;
}
});
try {
clientConnection.send(new HandshakeC2SPacket(serverAddress.getAddress(), serverAddress.getPort(), NetworkState.STATUS));
clientConnection.send(new QueryRequestC2SPacket());
} catch (Throwable throwable) {
MatHax.LOG.error("[MatHax] Couldn't send handshake", throwable);
}
}
use of net.minecraft.network.ClientConnection in project Client by MatHax.
the class ServerListPinger method cancel.
public void cancel() {
synchronized (this.clientConnections) {
Iterator<ClientConnection> iterator = this.clientConnections.iterator();
while (iterator.hasNext()) {
ClientConnection clientConnection = iterator.next();
if (clientConnection.isOpen()) {
iterator.remove();
clientConnection.disconnect(new TranslatableText("multiplayer.status.cancelled"));
}
}
}
}
use of net.minecraft.network.ClientConnection in project Client by MatHax.
the class ServerListPinger method tick.
public void tick() {
synchronized (this.clientConnections) {
Iterator<ClientConnection> iterator = this.clientConnections.iterator();
while (iterator.hasNext()) {
ClientConnection clientConnection = iterator.next();
if (clientConnection.isOpen())
clientConnection.tick();
else {
iterator.remove();
clientConnection.handleDisconnection();
}
}
}
}
Aggregations