Пример #1
0
 @Override
 public void channelActive(ChannelHandlerContext ctx) {
   final Channel c = ctx.channel();
   Session s = connectionManager.newSession(c);
   if (!session.compareAndSet(null, s)) {
     throw new IllegalStateException("Session may not be set more than once");
   }
   s.onReady();
 }
Пример #2
0
  /** Pulse this session, performing any updates needed. */
  void pulse() {
    // drop the previous placement if needed
    if (previousPlacementTicks > 0 && --previousPlacementTicks == 0) {
      previousPlacement = null;
    }

    // process messages
    Message message;
    while ((message = messageQueue.poll()) != null) {
      if (disconnected) {
        // disconnected, we are just seeing extra messages now
        continue;
      }

      super.messageReceived(message);
    }

    // check if the client is disconnected
    if (disconnected) {
      connectionManager.sessionInactivated(this);

      if (player == null) {
        return;
      }

      player.remove();

      Message userListMessage = UserListItemMessage.removeOne(player.getUniqueId());
      for (GlowPlayer player : server.getOnlinePlayers()) {
        if (player.canSee(this.player)) {
          player.getSession().send(userListMessage);
        } else {
          player.stopHidingDisconnectedPlayer(this.player);
        }
      }

      GlowServer.logger.info(player.getName() + " [" + address + "] lost connection");

      if (player.isSleeping()) {
        player.leaveBed(false);
      }

      final String text = EventFactory.onPlayerQuit(player).getQuitMessage();
      if (online && text != null && !text.isEmpty()) {
        server.broadcastMessage(text);
      }

      player = null; // in case we are disposed twice
    }
  }