Package marauroa.common.net.message

Examples of marauroa.common.net.message.Message


   */
  @Override
  public void run() {
    try {
      while (keepRunning) {
        Message msg = netMan.getMessage();

        if (msg != null) {
//          playerContainer.getLock().requestWriteLock();
          messageDispatcher.dispatchMessage(msg);
//          playerContainer.getLock().releaseLock();
View Full Code Here


   *             if there is no message available in TIMEOUT milliseconds.
   * @throws BannedAddressException
   */
  private Message getMessage(int timeout) throws InvalidVersionException, TimeoutException,
          BannedAddressException {
    Message msg = null;

    if (messages.isEmpty()) {
      msg = netMan.getMessage(timeout);

      if (msg instanceof MessageS2CConnectNACK) {
View Full Code Here

    /* Send to server a login request and indicate the game name and version */
    netMan.addMessage(new MessageC2SLoginRequestKey(null, getGameName(), getVersionNumber()));

    int timeout = TIMEOUT;
    while (received < 3) {
      Message msg = getMessage(timeout);
      // Okay, now  we know that there is a marauroa server responding to the handshake.
      // We can give it more time for the next steps in case the database is slow.
      // Loging heavily depends on the database because number of failed logins for both
      // ip-address and username, banstatus, username&password have to be checked. And
      // the list of characters needs to be loaded from the database.
      timeout = TIMEOUT_EXTENDED;

      switch (msg.getType()) {
        case S2C_INVALIDMESSAGE: {
          throw new LoginFailedException(((MessageS2CInvalidMessage) msg).getReason());
        }
        /* Server sends its public RSA key */
        case S2C_LOGIN_SENDKEY: {
View Full Code Here

   *             if timeout happens while waiting for the message.
   * @throws BannedAddressException
   */
  public synchronized boolean chooseCharacter(String character) throws TimeoutException,
          InvalidVersionException, BannedAddressException {
    Message msgCC = new MessageC2SChooseCharacter(null, character);
    netMan.addMessage(msgCC);

    int received = 0;

    while (received != 1) {
      Message msg = getMessage(TIMEOUT_EXTENDED);

      switch (msg.getType()) {
        /* Server accepted the character we chose */
        case S2C_CHOOSECHARACTER_ACK:
          logger.debug("Choose Character ACK");
          return true;
          /* Server rejected the character we chose. No reason */
 
View Full Code Here

   *             if timeout happens while waiting for the message.
   * @throws BannedAddressException
   */
  public synchronized AccountResult createAccount(String username, String password, String email)
          throws TimeoutException, InvalidVersionException, BannedAddressException {
    Message msgCA = new MessageC2SCreateAccount(null, username, password, email);

    netMan.addMessage(msgCA);

    int received = 0;

    AccountResult result = null;

    while (received != 1) {
      Message msg = getMessage(TIMEOUT_EXTENDED);

      switch (msg.getType()) {
        case S2C_INVALIDMESSAGE: {
          result = new AccountResult(Result.FAILED_EXCEPTION, username);
          break;
        }
        /* Account was created */
 
View Full Code Here

   *             if timeout happens while waiting for the message.
   * @throws BannedAddressException
   */
  public synchronized CharacterResult createCharacter(String character, RPObject template)
          throws TimeoutException, InvalidVersionException, BannedAddressException {
    Message msgCA = new MessageC2SCreateCharacter(null, character, template);

    netMan.addMessage(msgCA);

    int received = 0;

    CharacterResult result = null;

    while (received != 2) {
      Message msg = getMessage(TIMEOUT_EXTENDED);

      switch (msg.getType()) {
        /* Account was created */
        case S2C_CREATECHARACTER_ACK:
          logger.debug("Create character ACK");

          MessageS2CCreateCharacterACK msgack = (MessageS2CCreateCharacterACK) msg;
View Full Code Here

   *             if timeout happens while waiting for the message.
   * @throws BannedAddressException
   */
  public synchronized boolean logout() throws InvalidVersionException, TimeoutException,
          BannedAddressException {
    Message msgL = new MessageC2SLogout(null);

    netMan.addMessage(msgL);
    int received = 0;

    while (received != 1) {
      Message msg = getMessage(TIMEOUT);
      switch (msg.getType()) {
        case S2C_LOGOUT_ACK:
          logger.debug("Logout ACK");
          return true;
        case S2C_LOGOUT_NACK:
          logger.debug("Logout NACK");
View Full Code Here

        throw new IOException("Message size is negative. Message ignored.");
      }

      if (data.length == size) {
        /* If we have the full data build the message */
        Message msg = msgFactory.getMessage(data, channel, 4);
        List<Message> list=new LinkedList<Message>();
        list.add(msg);
       
        return list;
      } else {
        logger.debug("Message full body missing ("+size+"), waiting for more data ("+data.length+").");
        /* If there is still data to store it. */
        buffers = new MessageParts();
        content.put(channel, buffers);
      }
    } else {
      logger.debug("Existing data, trying to complete Message full body");
    }

    buffers.add(data);
    List<Message> list = new LinkedList<Message>();

    while (!buffers.isEmpty()) {
      Message msg = buffers.build(channel);

      if (msg != null) {
        list.add(msg);
      } else {
        if (list.isEmpty()) {
View Full Code Here

         
          it.remove();
        }
      }

      Message msg = msgFactory.getMessage(data, channel, 4);
      return msg;
    }
View Full Code Here

    int messageTypeIndex = data[offset + 1];
    /*
     * Now we check if we have this message class implemented.
     */
    if (factoryArray.containsKey(messageTypeIndex)) {
      Message tmp = null;
      try {
        Class<?> messageType = factoryArray.get(messageTypeIndex);
        tmp = (Message) messageType.newInstance();
        tmp.setProtocolVersion(networkProtocolVersion);
        ByteArrayInputStream in = new ByteArrayInputStream(data);
        if (offset > 0) {
          in.skip(offset);
        }
        InputSerializer s = new InputSerializer(in);
        s.setProtocolVersion(networkProtocolVersion);

        tmp.readObject(s);
        tmp.setSocketChannel(channel);
        s.close();
        return tmp;
      } catch (Exception e) {
        logger.error("error in getMessage", e);
        throw new IOException(e.getMessage());
View Full Code Here

TOP

Related Classes of marauroa.common.net.message.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.