예제 #1
0
 public void setCompressionThreshold(int compressionThreshold) {
   if (ch.getHandle().isActive()
       && this.compressionThreshold == -1
       && getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8) {
     this.compressionThreshold = compressionThreshold;
     unsafe.sendPacket(new SetCompression(compressionThreshold));
     ch.setCompressionThreshold(compressionThreshold);
   }
 }
예제 #2
0
 public synchronized void disconnect0(BaseComponent... reason) {
   if (ch.getHandle().isActive()) {
     bungee
         .getLogger()
         .log(
             Level.INFO,
             "[" + getName() + "] disconnected with: " + BaseComponent.toLegacyText(reason));
     unsafe().sendPacket(new Kick(ComponentSerializer.toString(reason)));
     ch.close();
     if (server != null) {
       server.disconnect("Quitting");
     }
   }
 }
예제 #3
0
  public void disconnect0(final BaseComponent... reason) {
    if (!ch.isClosed()) {
      bungee
          .getLogger()
          .log(
              Level.INFO,
              "[{0}] disconnected with: {1}",
              new Object[] {getName(), BaseComponent.toLegacyText(reason)});

      // Why do we have to delay this you might ask? Well the simple reason is MOJANG.
      // Despite many a bug report posted, ever since the 1.7 protocol rewrite, the client STILL has
      // a race condition upon switching protocols.
      // As such, despite the protocol switch packets already having been sent, there is the
      // possibility of a client side exception
      // To help combat this we will wait half a second before actually sending the disconnected
      // packet so that whoever is on the other
      // end has a somewhat better chance of receiving the proper packet.
      ch.getHandle()
          .eventLoop()
          .schedule(
              new Runnable() {

                @Override
                public void run() {
                  unsafe().sendPacket(new Kick(ComponentSerializer.toString(reason)));
                  ch.close();
                }
              },
              500,
              TimeUnit.MILLISECONDS);

      if (server != null) {
        server.disconnect("Quitting");
      }
    }
  }
예제 #4
0
 @Override
 public void sendPacket(DefinedPacket packet) {
   ch.write(packet);
 }
예제 #5
0
 @Override
 public InetSocketAddress getAddress() {
   return (InetSocketAddress) ch.getHandle().remoteAddress();
 }
예제 #6
0
  public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry) {
    Preconditions.checkNotNull(info, "info");

    ServerConnectEvent event = new ServerConnectEvent(this, info);
    if (bungee.getPluginManager().callEvent(event).isCancelled()) {
      return;
    }

    final BungeeServerInfo target =
        (BungeeServerInfo) event.getTarget(); // Update in case the event changed target

    if (getServer() != null && Objects.equals(getServer().getInfo(), target)) {
      sendMessage(bungee.getTranslation("already_connected"));
      return;
    }
    if (pendingConnects.contains(target)) {
      sendMessage(bungee.getTranslation("already_connecting"));
      return;
    }

    pendingConnects.add(target);

    ChannelInitializer initializer =
        new ChannelInitializer() {
          @Override
          protected void initChannel(Channel ch) throws Exception {
            PipelineUtils.BASE.initChannel(ch);
            ch.pipeline()
                .addAfter(
                    PipelineUtils.FRAME_DECODER,
                    PipelineUtils.PACKET_DECODER,
                    new MinecraftDecoder(
                        Protocol.HANDSHAKE, false, getPendingConnection().getVersion()));
            ch.pipeline()
                .addAfter(
                    PipelineUtils.FRAME_PREPENDER,
                    PipelineUtils.PACKET_ENCODER,
                    new MinecraftEncoder(
                        Protocol.HANDSHAKE, false, getPendingConnection().getVersion()));
            ch.pipeline()
                .get(HandlerBoss.class)
                .setHandler(new ServerConnector(bungee, UserConnection.this, target));
          }
        };
    ChannelFutureListener listener =
        new ChannelFutureListener() {
          @Override
          public void operationComplete(ChannelFuture future) throws Exception {
            if (callback != null) {
              callback.done(future.isSuccess(), future.cause());
            }

            if (!future.isSuccess()) {
              future.channel().close();
              pendingConnects.remove(target);

              ServerInfo def =
                  ProxyServer.getInstance()
                      .getServers()
                      .get(getPendingConnection().getListener().getFallbackServer());
              if (retry && target != def && (getServer() == null || def != getServer().getInfo())) {
                sendMessage(bungee.getTranslation("fallback_lobby"));
                connect(def, null, false);
              } else {
                if (dimensionChange) {
                  disconnect(
                      bungee.getTranslation("fallback_kick") + future.cause().getClass().getName());
                } else {
                  sendMessage(
                      bungee.getTranslation("fallback_kick") + future.cause().getClass().getName());
                }
              }
            }
          }
        };
    Bootstrap b =
        new Bootstrap()
            .channel(NioSocketChannel.class)
            .group(ch.getHandle().eventLoop())
            .handler(initializer)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) // TODO: Configurable
            .remoteAddress(target.getAddress());
    // Windows is bugged, multi homed users will just have to live with random connecting IPs
    if (getPendingConnection().getListener().isSetLocalAddress()
        && !PlatformDependent.isWindows()) {
      b.localAddress(getPendingConnection().getListener().getHost().getHostString(), 0);
    }
    b.connect().addListener(listener);
  }
예제 #7
0
 @Deprecated
 public boolean isActive() {
   return !ch.isClosed();
 }
예제 #8
0
 public void sendPacket(PacketWrapper packet) {
   ch.write(packet);
 }