/**
  * Invoked when the idle status of a session changes.
  *
  * @param session The session in question
  * @param status The new idle status
  */
 public void sessionIdle(IoSession session, IdleStatus status) {
   Player player = (Player) session.getAttachment();
   if (!player.destroyed()) {
     player.destroy(false);
   }
   session.close();
 }
示例#2
0
  private void processIncomingPackets() {
    for (RSCPacket p : packetQueue.getPackets()) {
      IoSession session = p.getSession();
      Player player = (Player) session.getAttachment();
      if (player.getUsername() == null && p.getID() != 32 && p.getID() != 77 && p.getID() != 0) {
        final String ip = player.getCurrentIP();
        IPBanManager.throttle(ip);
        continue;
      }
      PacketHandler handler = packetHandlers.get(p.getID());
      player.ping();
      if (handler != null) {
        try {
          handler.handlePacket(p, session);
          try {
            if (p.getID() != 5) {
              // String s = "[PACKET] " +
              // session.getRemoteAddress().toString().replace("/",
              // "") + " : " + p.getID()+
              // " ["+handler.getClass().toString()+"]" + " : "+
              // player.getUsername() + " : ";
              // for(Byte b : p.getData())
              // s += b;
              // Logger.println(s);
            }
          } catch (Exception e) {
            e.printStackTrace();
          }

        } catch (Exception e) {
          String s;
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw, true);
          e.printStackTrace(pw);
          pw.flush();
          sw.flush();
          s = sw.toString();
          Logger.error(
              "Exception with p["
                  + p.getID()
                  + "] from "
                  + player.getUsername()
                  + " ["
                  + player.getCurrentIP()
                  + "]: "
                  + s);
          player.getActionSender().sendLogout();
          player.destroy(false);
        }
      } else {
        Logger.error(
            "Unhandled packet from "
                + player.getCurrentIP()
                + ": "
                + p.getID()
                + "len: "
                + p.getLength());
      }
    }
  }
 /**
  * Invoked whenever an IO session is closed. This must handle unregistering the disconnecting
  * player from the engine.
  *
  * @param session The IO session which has been closed
  */
 public void sessionClosed(IoSession session) {
   Player player = (Player) session.getAttachment();
   if (!player.destroyed()) {
     player.destroy(false);
   }
 }