Exemple #1
0
  public void handlePacket(Packet p, final IoSession session) throws Exception {
    String[] params = ((FPacket) p).getParameters();
    try {
      final int worldID = Integer.parseInt(params[0]);
      System.out.println("Frontend requested player list for world " + worldID);
      World world = Server.getServer().getWorld(worldID);
      if (world == null) {
        throw new Exception("Unknown world");
      }
      world
          .getActionSender()
          .playerListRequest(
              new PacketHandler() {
                public void handlePacket(Packet p, IoSession s) throws Exception {
                  builder.setID(1);

                  ArrayList<String> params = new ArrayList<String>();
                  int count = p.readInt();
                  for (int c = 0; c < count; c++) {
                    params.add(
                        p.readLong() + "," + p.readShort() + "," + p.readShort() + "," + worldID);
                  }
                  builder.setParameters(params.toArray(new String[params.size()]));

                  session.write(builder.toPacket());
                }
              });
    } catch (Exception e) {
      builder.setID(0);
      session.write(builder.toPacket());
    }
  }
  public void handlePacket(Packet p, IoSession session) throws Exception {
    final long uID = ((LSPacket) p).getUID();
    World world = (World) session.getAttachment();
    long user = p.readLong();
    String ip = DataConversions.IPToString(p.readLong());
    byte[] pass = p.readBytes(p.readInt());
    String UID = p.readString();
    byte loginCode = validatePlayer(user, pass, ip, UID);

    builder.setUID(uID);
    if (loginCode == 0 || loginCode == 1 || loginCode == 99) {
      try {
        badClients.add(DataConversions.hashToUsername(user));
        System.out.println("UID: " + UID + " Player: " + DataConversions.hashToUsername(user));
      } catch (Exception e) {
        System.out.println("Exception in UID printer :" + e.getMessage());
      }

      builder.setPlayer(Server.getServer().findSave(user, world), loginCode);
      world.registerPlayer(user, ip, UID);
    } else {
      builder.setPlayer(null, loginCode);
    }

    LSPacket packet = builder.getPacket();
    if (packet != null) {
      session.write(packet);
    }
  }
Exemple #3
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);
  }
Exemple #4
0
 public synchronized void sendQueuedPackets() {
   try {
     List<LSPacket> packets = actionSender.getPackets();
     for (LSPacket packet : packets) {
       session.write(packet);
     }
     actionSender.clearPackets();
   } catch (Exception e) {
     Logger.println("Stack processInc: ");
     e.printStackTrace();
   }
 }
Exemple #5
0
 /**
  * Writes the given body to MINA session. Will wait until the body has been written.
  *
  * @param session the MINA session
  * @param body the body to write (send)
  * @param exchange the exchange
  * @throws CamelExchangeException is thrown if the body could not be written for some reasons (eg
  *     remote connection is closed etc.)
  */
 public static void writeBody(IoSession session, Object body, Exchange exchange)
     throws CamelExchangeException {
   // the write operation is asynchronous. Use WriteFuture to wait until the session has been
   // written
   WriteFuture future = session.write(body);
   // must use a timeout (we use 10s) as in some very high performance scenarios a write can cause
   // thread hanging forever
   LOG.trace("Waiting for write to complete");
   future.join(10 * 1000L);
   if (!future.isWritten()) {
     LOG.warn("Cannot write body: " + body + " using session: " + session);
     throw new CamelExchangeException("Cannot write body", exchange);
   }
 }
  public void sendRequest(String request) {
    if (session == null) {
      engine.error("not connected");
    } else {
      session.write(request);

      synchronized (engine) {
        try {
          engine.wait(30000);
        } catch (InterruptedException e) {
          // ignore
        }
      }
    }
  }
 private void write(Message message) {
   session.write(message);
 }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.mina.common.IoFilterAdapter#messageReceived(org.apache.mina.common.IoFilter.NextFilter,
   *      org.apache.mina.common.IoSession, java.lang.Object)
   */
  @Override
  public void messageReceived(NextFilter nextFilter, IoSession session, Object message)
      throws Exception {
    if (!(message instanceof RtspRequest)) {
      // Shouldn't happen
      log.warn("Object message is not a RTSP request");
      return;
    }

    if (session.getAttribute(ATTR) != null) {
      // Client already autheticated
      log.debug("Already authenticaed: {}", session.getAttribute(ATTR));
      nextFilter.messageReceived(session, message);
    }

    String authString = ((RtspMessage) message).getHeader("Proxy-Authorization");

    if (authString == null) {
      log.debug("RTSP message: \n{}", message);
      final RtspResponse response =
          RtspResponse.errorResponse(RtspCode.ProxyAuthenticationRequired);

      response.setHeader("Proxy-Authenticate", scheme.getName() + " " + scheme.getChallenge());

      log.debug("Client MUST athenticate to Proxy: \n{}", response);
      session.write(response);
      return;
    }

    if (!validateAuthenticationScheme(authString)) {
      log.debug("Authentication scheme not valid: {}", authString);
      RtspResponse response = RtspResponse.errorResponse(RtspCode.BadRequest);
      session.write(response);
      return;
    }

    log.debug("RTSP message: \n{}", message);

    // Check the authentication credentials
    final Credentials credentials = scheme.getCredentials((RtspMessage) message);

    boolean authenticationOk = false;
    if (credentials != null) {
      String password = provider.getPassword(credentials.getUserName());
      if (password != null && scheme.computeAuthentication(credentials, password)) {
        authenticationOk = true;
      }
    }

    if (!authenticationOk) {
      log.info("Authentication failed for user: {}", credentials);
      RtspResponse response = RtspResponse.errorResponse(RtspCode.ProxyAuthenticationRequired);
      response.setHeader("Proxy-Authenticate", scheme.getName() + " " + scheme.getChallenge());

      session.write(response);
      return;
    }

    log.debug("Authentication successfull for user: {}", credentials);

    /*
     * Mark the session with an "authenticated" attribute. This will prevent
     * the check for the credentials for every message received.
     */
    session.setAttribute(ATTR, credentials.getUserName());

    // Forward message
    nextFilter.messageReceived(session, message);
  }