Java Code Examples for net.minecraft.util.io.netty.util.concurrent.GenericFutureListener

The following are top voted examples for showing how to use net.minecraft.util.io.netty.util.concurrent.GenericFutureListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CraftBukkit   File: LoginListener.java   Source Code and License 6 votes vote down vote up
public void c() {
    if (!this.i.isComplete()) {
        this.i = this.a(this.i);
    }

    // CraftBukkit start - fire PlayerLoginEvent
    EntityPlayer s = this.server.getPlayerList().attemptLogin(this, this.i, this.hostname);

    if (s == null) {
        // this.disconnect(s);
        // CraftBukkit end
    } else {
        this.g = EnumProtocolState.e;
        this.networkManager.handle(new PacketLoginOutSuccess(this.i), new GenericFutureListener[0]);
        this.server.getPlayerList().a(this.networkManager, this.server.getPlayerList().processLogin(this.i, s)); // CraftBukkit - add player reference
    }
}
 
Example 2
Project: CraftBukkit   File: PlayerConnection.java   Source Code and License 6 votes vote down vote up
public void disconnect(String s) {
    // CraftBukkit start - fire PlayerKickEvent
    String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";

    PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);

    if (this.server.getServer().isRunning()) {
        this.server.getPluginManager().callEvent(event);
    }

    if (event.isCancelled()) {
        // Do not kick the player
        return;
    }
    // Send the possibly modified leave message
    s = event.getReason();
    // CraftBukkit end
    ChatComponentText chatcomponenttext = new ChatComponentText(s);

    this.networkManager.handle(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener[] { new PlayerConnectionFuture(this, chatcomponenttext)});
    this.a(chatcomponenttext); // CraftBukkit - Process quit immediately
    this.networkManager.g();
}
 
Example 3
Project: CraftBukkit   File: NetworkManager.java   Source Code and License 6 votes vote down vote up
private void b(Packet packet, GenericFutureListener[] agenericfuturelistener) {
    EnumProtocol enumprotocol = EnumProtocol.a(packet);
    EnumProtocol enumprotocol1 = (EnumProtocol) this.m.attr(d).get();

    if (enumprotocol1 != enumprotocol) {
        i.debug("Disabled auto read");
        this.m.config().setAutoRead(false);
    }

    if (this.m.eventLoop().inEventLoop()) {
        if (enumprotocol != enumprotocol1) {
            this.a(enumprotocol);
        }

        this.m.writeAndFlush(packet).addListeners(agenericfuturelistener).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
    } else {
        this.m.eventLoop().execute(new QueuedProtocolSwitch(this, enumprotocol, enumprotocol1, packet, agenericfuturelistener));
    }
}
 
Example 4
Project: Tweakkit-Server   File: LoginListener.java   Source Code and License 6 votes vote down vote up
public void c() {
    // Spigot start - Moved to initUUID
    /*
    if (!this.i.isComplete()) {
        this.i = this.a(this.i);
    }
    */
    // Spigot end

    // CraftBukkit start - fire PlayerLoginEvent
    EntityPlayer s = this.server.getPlayerList().attemptLogin(this, this.i, this.hostname);

    if (s == null) {
        // this.disconnect(s);
        // CraftBukkit end
    } else {
        this.g = EnumProtocolState.e;
        this.networkManager.handle(new PacketLoginOutSuccess(this.i), new GenericFutureListener[0]);
        this.server.getPlayerList().a(this.networkManager, this.server.getPlayerList().processLogin(this.i, s)); // CraftBukkit - add player reference
    }
}
 
Example 5
Project: Tweakkit-Server   File: PlayerConnection.java   Source Code and License 6 votes vote down vote up
public void disconnect(String s) {
    // CraftBukkit start - fire PlayerKickEvent
    String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";

    PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);

    if (this.server.getServer().isRunning()) {
        this.server.getPluginManager().callEvent(event);
    }

    if (event.isCancelled()) {
        // Do not kick the player
        return;
    }
    // Send the possibly modified leave message
    s = event.getReason();
    // CraftBukkit end
    ChatComponentText chatcomponenttext = new ChatComponentText(s);

    this.networkManager.handle(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener[] { new PlayerConnectionFuture(this, chatcomponenttext)});
    this.a(chatcomponenttext); // CraftBukkit - Process quit immediately
    this.networkManager.g();
}
 
Example 6
Project: Tweakkit-Server   File: NetworkManager.java   Source Code and License 6 votes vote down vote up
private void b(Packet packet, GenericFutureListener[] agenericfuturelistener) {
    EnumProtocol enumprotocol = EnumProtocol.a(packet);
    EnumProtocol enumprotocol1 = (EnumProtocol) this.m.attr(d).get();

    if (enumprotocol1 != enumprotocol) {
        i.debug("Disabled auto read");
        this.m.config().setAutoRead(false);
    }

    if (this.m.eventLoop().inEventLoop()) {
        if (enumprotocol != enumprotocol1) {
            this.a(enumprotocol);
        }

        this.m.writeAndFlush(packet).addListeners(agenericfuturelistener).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
    } else {
        this.m.eventLoop().execute(new QueuedProtocolSwitch(this, enumprotocol, enumprotocol1, packet, agenericfuturelistener));
    }
}
 
Example 7
Project: CraftBukkit   File: LoginListener.java   Source Code and License 5 votes vote down vote up
public void disconnect(String s) {
    try {
        c.info("Disconnecting " + this.getName() + ": " + s);
        ChatComponentText chatcomponenttext = new ChatComponentText(s);

        this.networkManager.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
        this.networkManager.close(chatcomponenttext);
    } catch (Exception exception) {
        c.error("Error whilst disconnecting player", exception);
    }
}
 
Example 8
Project: CraftBukkit   File: LoginListener.java   Source Code and License 5 votes vote down vote up
public void a(PacketLoginInStart packetlogininstart) {
    Validate.validState(this.g == EnumProtocolState.HELLO, "Unexpected hello packet", new Object[0]);
    this.i = packetlogininstart.c();
    if (this.server.getOnlineMode() && !this.networkManager.c()) {
        this.g = EnumProtocolState.KEY;
        this.networkManager.handle(new PacketLoginOutEncryptionBegin(this.j, this.server.K().getPublic(), this.e), new GenericFutureListener[0]);
    } else {
        this.g = EnumProtocolState.READY_TO_ACCEPT;
    }
}
 
Example 9
Project: CraftBukkit   File: PlayerConnection.java   Source Code and License 5 votes vote down vote up
public void sendPacket(Packet packet) {
    if (packet instanceof PacketPlayOutChat) {
        PacketPlayOutChat packetplayoutchat = (PacketPlayOutChat) packet;
        EnumChatVisibility enumchatvisibility = this.player.getChatFlags();

        if (enumchatvisibility == EnumChatVisibility.HIDDEN) {
            return;
        }

        if (enumchatvisibility == EnumChatVisibility.SYSTEM && !packetplayoutchat.d()) {
            return;
        }
    }

    // CraftBukkit start
    if (packet == null) {
        return;
    } else if (packet instanceof PacketPlayOutSpawnPosition) {
        PacketPlayOutSpawnPosition packet6 = (PacketPlayOutSpawnPosition) packet;
        this.player.compassTarget = new Location(this.getPlayer().getWorld(), packet6.x, packet6.y, packet6.z);
    }
    // CraftBukkit end

    try {
        this.networkManager.handle(packet, new GenericFutureListener[0]);
    } catch (Throwable throwable) {
        CrashReport crashreport = CrashReport.a(throwable, "Sending packet");
        CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent");

        crashreportsystemdetails.a("Packet class", (Callable) (new CrashReportConnectionPacketClass(this, packet)));
        throw new ReportedException(crashreport);
    }
}
 
Example 10
Project: CraftBukkit   File: NetworkManager.java   Source Code and License 5 votes vote down vote up
public void handle(Packet packet, GenericFutureListener... agenericfuturelistener) {
    if (this.m != null && this.m.isOpen()) {
        this.i();
        this.b(packet, agenericfuturelistener);
    } else {
        this.l.add(new QueuedPacket(packet, agenericfuturelistener));
    }
}
 
Example 11
Project: Tweakkit-Server   File: LoginListener.java   Source Code and License 5 votes vote down vote up
public void disconnect(String s) {
    try {
        c.info("Disconnecting " + this.getName() + ": " + s);
        ChatComponentText chatcomponenttext = new ChatComponentText(s);

        this.networkManager.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
        this.networkManager.close(chatcomponenttext);
    } catch (Exception exception) {
        c.error("Error whilst disconnecting player", exception);
    }
}
 
Example 12
Project: Tweakkit-Server   File: LoginListener.java   Source Code and License 5 votes vote down vote up
public void a(PacketLoginInStart packetlogininstart) {
    Validate.validState(this.g == EnumProtocolState.HELLO, "Unexpected hello packet", new Object[0]);
    this.i = packetlogininstart.c();
    if (this.server.getOnlineMode() && !this.networkManager.c()) {
        this.g = EnumProtocolState.KEY;
        this.networkManager.handle(new PacketLoginOutEncryptionBegin(this.j, this.server.K().getPublic(), this.e), new GenericFutureListener[0]);
    } else {
        (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start(); // Spigot
    }
}
 
Example 13
Project: Tweakkit-Server   File: PlayerConnection.java   Source Code and License 5 votes vote down vote up
public void sendPacket(Packet packet) {
    if (packet instanceof PacketPlayOutChat) {
        PacketPlayOutChat packetplayoutchat = (PacketPlayOutChat) packet;
        EnumChatVisibility enumchatvisibility = this.player.getChatFlags();

        if (enumchatvisibility == EnumChatVisibility.HIDDEN) {
            return;
        }

        if (enumchatvisibility == EnumChatVisibility.SYSTEM && !packetplayoutchat.d()) {
            return;
        }
    }

    // CraftBukkit start
    if (packet == null) {
        return;
    } else if (packet instanceof PacketPlayOutSpawnPosition) {
        PacketPlayOutSpawnPosition packet6 = (PacketPlayOutSpawnPosition) packet;
        this.player.compassTarget = new Location(this.getPlayer().getWorld(), packet6.x, packet6.y, packet6.z);
    }
    // CraftBukkit end

    try {
        this.networkManager.handle(packet, new GenericFutureListener[0]);
    } catch (Throwable throwable) {
        CrashReport crashreport = CrashReport.a(throwable, "Sending packet");
        CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent");

        crashreportsystemdetails.a("Packet class", (Callable) (new CrashReportConnectionPacketClass(this, packet)));
        throw new ReportedException(crashreport);
    }
}
 
Example 14
Project: Tweakkit-Server   File: NetworkManager.java   Source Code and License 5 votes vote down vote up
public void handle(Packet packet, GenericFutureListener... agenericfuturelistener) {
    if (this.m != null && this.m.isOpen()) {
        this.i();
        this.b(packet, agenericfuturelistener);
    } else {
        this.l.add(new QueuedPacket(packet, agenericfuturelistener));
    }
}
 
Example 15
Project: CraftBukkit   File: QueuedPacket.java   Source Code and License 4 votes vote down vote up
public QueuedPacket(Packet packet, GenericFutureListener... agenericfuturelistener) {
    this.a = packet;
    this.b = agenericfuturelistener;
}
 
Example 16
Project: CraftBukkit   File: QueuedPacket.java   Source Code and License 4 votes vote down vote up
static GenericFutureListener[] b(QueuedPacket queuedpacket) {
    return queuedpacket.b;
}
 
Example 17
Project: CraftBukkit   File: HandshakeListener.java   Source Code and License 4 votes vote down vote up
public void a(PacketHandshakingInSetProtocol packethandshakinginsetprotocol) {
    switch (ProtocolOrdinalWrapper.a[packethandshakinginsetprotocol.c().ordinal()]) {
    case 1:
        this.b.a(EnumProtocol.LOGIN);
        ChatComponentText chatcomponenttext;

        // CraftBukkit start - Connection throttle
        try {
            long currentTime = System.currentTimeMillis();
            long connectionThrottle = MinecraftServer.getServer().server.getConnectionThrottle();
            InetAddress address = ((java.net.InetSocketAddress) this.b.getSocketAddress()).getAddress();

            synchronized (throttleTracker) {
                if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) {
                    throttleTracker.put(address, currentTime);
                    chatcomponenttext = new ChatComponentText("Connection throttled! Please wait before reconnecting.");
                    this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
                    this.b.close(chatcomponenttext);
                    return;
                }

                throttleTracker.put(address, currentTime);
                throttleCounter++;
                if (throttleCounter > 200) {
                    throttleCounter = 0;

                    // Cleanup stale entries
                    java.util.Iterator iter = throttleTracker.entrySet().iterator();
                    while (iter.hasNext()) {
                        java.util.Map.Entry<InetAddress, Long> entry = (java.util.Map.Entry) iter.next();
                        if (entry.getValue() > connectionThrottle) {
                            iter.remove();
                        }
                    }
                }
            }
        } catch (Throwable t) {
            org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t);
        }
        // CraftBukkit end

        if (packethandshakinginsetprotocol.d() > 5) {
            chatcomponenttext = new ChatComponentText("Outdated server! I\'m still on 1.7.10");
            this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
            this.b.close(chatcomponenttext);
        } else if (packethandshakinginsetprotocol.d() < 5) {
            chatcomponenttext = new ChatComponentText("Outdated client! Please use 1.7.10");
            this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
            this.b.close(chatcomponenttext);
        } else {
            this.b.a((PacketListener) (new LoginListener(this.a, this.b)));
            ((LoginListener) this.b.getPacketListener()).hostname = packethandshakinginsetprotocol.b + ":" + packethandshakinginsetprotocol.c; // CraftBukkit - set hostname
        }
        break;

    case 2:
        this.b.a(EnumProtocol.STATUS);
        this.b.a((PacketListener) (new PacketStatusListener(this.a, this.b)));
        break;

    default:
        throw new UnsupportedOperationException("Invalid intention " + packethandshakinginsetprotocol.c());
    }
}
 
Example 18
Project: CraftBukkit   File: PacketStatusListener.java   Source Code and License 4 votes vote down vote up
public void a(PacketStatusInPing packetstatusinping) {
    this.networkManager.handle(new PacketStatusOutPong(packetstatusinping.c()), new GenericFutureListener[0]);
}
 
Example 19
Project: Tweakkit-Server   File: ServerConnection.java   Source Code and License 4 votes vote down vote up
public void c() {
    List list = this.f;

    synchronized (this.f) {
        // Spigot Start
        // This prevents players from 'gaming' the server, and strategically relogging to increase their position in the tick order
        if ( org.spigotmc.SpigotConfig.playerShuffle > 0 && MinecraftServer.currentTick % org.spigotmc.SpigotConfig.playerShuffle == 0 )
        {
            Collections.shuffle( this.f );
        }
        // Spigot End
        Iterator iterator = this.f.iterator();

        while (iterator.hasNext()) {
            NetworkManager networkmanager = (NetworkManager) iterator.next();

            if (!networkmanager.isConnected()) {
                // Spigot Start
                // Fix a race condition where a NetworkManager could be unregistered just before connection.
                if (networkmanager.preparing) continue;
                // Spigot End
                iterator.remove();
                if (networkmanager.f() != null) {
                    networkmanager.getPacketListener().a(networkmanager.f());
                } else if (networkmanager.getPacketListener() != null) {
                    networkmanager.getPacketListener().a(new ChatComponentText("Disconnected"));
                }
            } else {
                try {
                    networkmanager.a();
                } catch (Exception exception) {
                    if (networkmanager.c()) {
                        CrashReport crashreport = CrashReport.a(exception, "Ticking memory connection");
                        CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Ticking connection");

                        crashreportsystemdetails.a("Connection", (Callable) (new CrashReportServerConnection(this, networkmanager)));
                        throw new ReportedException(crashreport);
                    }

                    b.warn("Failed to handle packet for " + networkmanager.getSocketAddress(), exception);
                    ChatComponentText chatcomponenttext = new ChatComponentText("Internal server error");

                    networkmanager.handle(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener[] { new ServerConnectionFuture(this, networkmanager, chatcomponenttext)});
                    networkmanager.g();
                }
            }
        }
    }
}
 
Example 20
Project: Tweakkit-Server   File: QueuedPacket.java   Source Code and License 4 votes vote down vote up
public QueuedPacket(Packet packet, GenericFutureListener... agenericfuturelistener) {
    this.a = packet;
    this.b = agenericfuturelistener;
}
 
Example 21
Project: Tweakkit-Server   File: QueuedPacket.java   Source Code and License 4 votes vote down vote up
static GenericFutureListener[] b(QueuedPacket queuedpacket) {
    return queuedpacket.b;
}
 
Example 22
Project: Tweakkit-Server   File: PacketStatusListener.java   Source Code and License 4 votes vote down vote up
public void a(PacketStatusInPing packetstatusinping) {
    this.networkManager.handle(new PacketStatusOutPong(packetstatusinping.c()), new GenericFutureListener[0]);
}
 
Example 23
Project: PlayerSimulator   File: DummyNetworkManager.java   Source Code and License 4 votes vote down vote up
public void handle(Packet packet, GenericFutureListener... agenericfuturelistener) {
}
 
Example 24
Project: PlayerSimulator   File: DummyNetworkManager.java   Source Code and License 4 votes vote down vote up
private void b(Packet packet, GenericFutureListener[] agenericfuturelistener) {
}