예제 #1
0
 @Override
 public void run(IoSession session) {
   if (isAudit()) {
     String hostAddress = session.getRemoteAddress().toString();
     getServerAuditStrategy().auditAuthenticationNodeFailure(hostAddress);
   }
 }
예제 #2
0
  public void handlePacket(Packet p1, IoSession session) throws Exception {

    Player player = (Player) session.getAttachment();
    final String ip =
        ((InetSocketAddress) session.getRemoteAddress())
            .getAddress()
            .toString()
            .replaceAll("/", "");

    byte loginCode;
    try {

      byte[] data = RSA.decrypt(p1.getData());
      Packet p = new Packet(session, data);

      boolean reconnecting = (p.readByte() == 1);

      int clientVersion = p.readInt();

      if (Config.SERVER_VERSION != clientVersion) {
        Logger.println(
            "ip: " + ip + " | clientversion: " + clientVersion + " : " + Config.SERVER_VERSION);
      }

      int[] sessionKeys = new int[4];
      for (int key = 0; key < sessionKeys.length; key++) {
        sessionKeys[key] = p.readInt();
      }
      String username = "";
      String password = "";

      username = p.readString(20).trim();
      password = p.readString(20).trim();

      if (world.countPlayers() >= Config.MAX_PLAYERS) {
        loginCode = 10;
      } else if (clientVersion < Config.SERVER_VERSION) {
        loginCode = 4;
      } else if (!player.setSessionKeys(sessionKeys)) {
        loginCode = 5;
      } else {
        player.load(username, password, 0, reconnecting);
        if (clientVersion < 39) {
          player.clientWarn(true);
        }
        return;
      }
    } catch (Exception e) {
      System.err.println("Login exception with: " + ip);
      e.printStackTrace();
      loginCode = 4;
    }

    RSCPacketBuilder pb = new RSCPacketBuilder();
    pb.setBare(true);
    pb.addByte((byte) loginCode);
    session.write(pb.toPacket());
    player.destroy(true);
  }
예제 #3
0
  public void sessionCreated(IoSession session) {
    session
        .getFilterChain()
        .addFirst("protocolFilter", new ProtocolCodecFilter(new RSCCodecFactory()));

    Logger.println(
        "Connection from: "
            + ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
  }
 public Channel getChannel(InetSocketAddress remoteAddress) {
   Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
   for (IoSession session : sessions) {
     if (session.getRemoteAddress().equals(remoteAddress)) {
       return MinaChannel.getOrAddChannel(session, getUrl(), this);
     }
   }
   return null;
 }
예제 #5
0
  private void setLogPrefix(final String userName, final String deviceId, final IoSession session) {

    StringBuilder prefix = new StringBuilder();
    prefix.append("[").append(session.getRemoteAddress()).append("] ");
    prefix.append("[").append(getSessionId()).append("] ");
    prefix.append("[").append(deviceId).append("] ");
    prefix.append("[").append(userName != null ? userName : "").append("] ");
    session.setAttribute(SessionLog.PREFIX, prefix.toString());
    logger.setPrefix(prefix.toString());
  }
예제 #6
0
 @Override
 public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
   ZimbraLog.addIpToContext(session.getRemoteAddress().toString());
   String msg = "Exception caught: " + cause;
   if (isSocketError(cause)) {
     // If connection error, then only log full stack trace if debug enabled
     if (log.isDebugEnabled()) {
       log.info(msg, cause);
     } else {
       log.info(msg);
     }
   } else {
     log.error(msg, cause);
   }
   nextFilter.exceptionCaught(session, cause);
 }
예제 #7
0
  /**
   * Creates a new instance of <CODE>SessionManager</CODE>
   *
   * <p>The authentication manager is retrieved from the CTPServerConfiguration using parameter
   * specifide in file config/com/funambol/ctp/server/authentication/AuthenticationManager.xml
   *
   * @param session The related IoSession
   * @param dispatcher The NotificationProvider where to subscribe for notification messages.
   */
  public SessionManager(IoSession session, NotificationProvider dispatcher) {
    this.session = session;
    this.dispatcher = dispatcher;
    this.sessionState = new StateConnected();
    this.sessionId = createSessionId();
    lastClientEventTime = System.currentTimeMillis();

    this.authenticationManager =
        CTPServerConfiguration.getCTPServerConfiguration().getAuthenticationManager();

    this.pendingNotificationManager =
        CTPServerConfiguration.getCTPServerConfiguration().getPendingNotificationManager();

    session.setAttribute(SessionLog.LOGGER, logger);

    String prefix = "[" + session.getRemoteAddress() + "] ";
    session.setAttribute(SessionLog.PREFIX, prefix);
    logger.setPrefix(prefix);
  }
 private InetAddress getAddress(IoSession io) {
   return ((InetSocketAddress) io.getRemoteAddress()).getAddress();
 }
예제 #9
0
 private void trace(IoSession session, String format, Object arg) {
   ZimbraLog.addIpToContext(session.getRemoteAddress().toString());
   log.trace(format, arg);
 }
예제 #10
0
 private void debug(IoSession session, String msg) {
   if (log.isDebugEnabled()) {
     ZimbraLog.addIpToContext(session.getRemoteAddress().toString());
     log.debug(msg);
   }
 }