public Object encode(IResponseMessage aResponseMessage) throws ServerException {
    try {
      JSONObject encodingObj = new JSONObject();
      // put response data into json object

      // cast response obj
      DeleteItemResponse res = (DeleteItemResponse) aResponseMessage;

      StringBuilder sb = new StringBuilder();
      sb.append(Integer.toString(aResponseMessage.getID())).append(AIOConstants.SEPERATOR_BYTE_1);
      sb.append(Integer.toString(res.mCode)).append(AIOConstants.SEPERATOR_NEW_MID);

      if (res.mCode == ResponseCode.FAILURE) {
        sb.append(res.mErrorMsg);
      }

      encodingObj.put("v", sb.toString());

      // response encoded obj
      return encodingObj;
    } catch (Throwable t) {
      mLog.error("[ENCODER] " + aResponseMessage.getID(), t);
      return null;
    }
  }
Example #2
0
  public Object encode(IResponseMessage aResponseMessage) throws ServerException {
    try {
      JSONObject encodingObj = new JSONObject();
      FastPlayResponse fast = (FastPlayResponse) aResponseMessage;
      if (fast.session != null
          && fast.session.getByteProtocol() > AIOConstants.PROTOCOL_ADVERTISING) {
        getMidEncode(fast, encodingObj);

        return encodingObj;
      }

      // put response data into json object
      encodingObj.put("mid", aResponseMessage.getID());

      encodingObj.put("code", fast.mCode);
      // System.out.println(" chat.mUsername : "******"error_msg", fast.message);
      } else if (fast.mCode == ResponseCode.SUCCESS) {
        encodingObj.put("match_id", fast.matchID);
        encodingObj.put("nTable", fast.tableID);
      }
      // response encoded obj
      return encodingObj;
    } catch (Throwable t) {
      mLog.error("[ENCODER] " + aResponseMessage.getID(), t);
      return null;
    }
  }
  public Object encode(IResponseMessage aResponseMessage) throws ServerException {
    try {
      JSONObject encodingObj = new JSONObject();

      GetNewestBlogResponse res = (GetNewestBlogResponse) aResponseMessage;

      StringBuilder sb = new StringBuilder();
      sb.append(Integer.toString(aResponseMessage.getID())).append(AIOConstants.SEPERATOR_BYTE_1);
      sb.append(Integer.toString(res.mCode)).append(AIOConstants.SEPERATOR_NEW_MID);

      if (res.mCode == ResponseCode.FAILURE) {
        sb.append(res.errMsg);
      } else {
        if (res.value != null && !res.value.equals("")) {
          sb.append(res.value);
        }
      }

      encodingObj.put("v", sb.toString());

      return encodingObj;
    } catch (JSONException ex) {
      mLog.error(ex.getMessage(), ex);
    }

    return null;
  }
  public Object encode(IResponseMessage aResponseMessage) throws ServerException {
    try {
      JSONObject encodingObj = new JSONObject();

      GetRichestsResponse getRichestsList = (GetRichestsResponse) aResponseMessage;
      if (getRichestsList.session != null
          && getRichestsList.session.getByteProtocol() > AIOConstants.PROTOCOL_ADVERTISING) {
        StringBuilder sb = new StringBuilder();
        sb.append(Integer.toString(aResponseMessage.getID())).append(AIOConstants.SEPERATOR_BYTE_1);
        sb.append(Integer.toString(getRichestsList.mCode)).append(AIOConstants.SEPERATOR_NEW_MID);
        if (getRichestsList.mCode == ResponseCode.FAILURE) {
          sb.append(getRichestsList.mErrorMsg);
        } else {
          sb.append(finalProtocol(getRichestsList));
        }
        encodingObj.put("v", sb.toString());
        return encodingObj;
      }
      encodingObj.put("mid", aResponseMessage.getID());
      encodingObj.put("code", getRichestsList.mCode);
      if (getRichestsList.mCode == ResponseCode.FAILURE) {
      } else if (getRichestsList.mCode == ResponseCode.SUCCESS) {
        JSONArray arrRooms = new JSONArray();
        if (getRichestsList.mRichestsList != null) {
          for (UserEntity userEntity : getRichestsList.mRichestsList) {
            // with each playing room
            JSONObject jRoom = new JSONObject();
            // attached object
            jRoom.put("username", userEntity.mUsername);
            jRoom.put("uid", userEntity.mUid);
            jRoom.put("avatar", userEntity.avatarID);
            jRoom.put("level", userEntity.level);
            jRoom.put("money", userEntity.money);
            jRoom.put("PlaysNumber", userEntity.playsNumber);
            jRoom.put("sex", userEntity.mIsMale);
            arrRooms.put(jRoom);
          }
        }
        encodingObj.put("frient_list", arrRooms);
      }
      // response encoded obj
      return encodingObj;
    } catch (Throwable t) {
      mLog.error("[ENCODER] " + aResponseMessage.getID(), t);
      return null;
    }
  }
  @Override
  public Object encode(IResponseMessage aResponseMessage) throws ServerException {
    try {
      JSONObject encodingObj = new JSONObject();

      XESendPrivateMessageResponse res = (XESendPrivateMessageResponse) aResponseMessage;
      StringBuilder sb = new StringBuilder();
      sb.append(Integer.toString(aResponseMessage.getID())).append(AIOConstants.SEPERATOR_BYTE_1);
      sb.append(Integer.toString(res.mCode)).append(AIOConstants.SEPERATOR_NEW_MID);
      sb.append(res.getMessage());

      encodingObj.put("v", sb.toString());
      return encodingObj;
    } catch (Throwable t) {
      mLog.error("[ENCODER] " + aResponseMessage.getID(), t);
      return null;
    }
  }
Example #6
0
 @Override
 public Object encode(IResponseMessage aResponseMessage) throws ServerException {
   try {
     JSONObject encodingObj = new JSONObject();
     JoinResponse matchJoin = (JoinResponse) aResponseMessage;
     newProtocol(matchJoin, encodingObj);
     return encodingObj;
   } catch (Throwable t) {
     mLog.error("[ENCODER] " + aResponseMessage.getID(), t);
     return null;
   }
 }
  @Override
  public Object encode(IResponseMessage paramIResponseMessage) throws ServerException {
    try {
      JSONObject encodingObj = new JSONObject();
      XEGetInventoryResponse response = (XEGetInventoryResponse) paramIResponseMessage;

      StringBuilder sb = new StringBuilder();
      sb.append(Integer.toString(paramIResponseMessage.getID()))
          .append(AIOConstants.SEPERATOR_BYTE_1);
      sb.append(Integer.toString(response.mCode)).append(AIOConstants.SEPERATOR_NEW_MID);

      if (response.mCode == ResponseCode.SUCCESS) {
        int size = response.itemsList.size();
        if (size != 0) {
          StringBuilder sb1 = new StringBuilder();
          for (int i = 0; i < size; i++) {
            InventoryItemEntity item = response.itemsList.get(i);
            sb1.append(item.getItemCode()).append(AIOConstants.SEPERATOR_BYTE_1);
            sb1.append(item.getName()).append(AIOConstants.SEPERATOR_BYTE_1);
            sb1.append(item.getDescription()).append(AIOConstants.SEPERATOR_BYTE_1);
            sb1.append(item.getQuantity()).append(AIOConstants.SEPERATOR_BYTE_1);
            sb1.append(item.getIsUsable() ? "1" : "0").append(AIOConstants.SEPERATOR_BYTE_2);
          }
          sb1.deleteCharAt(sb1.length() - 1);
          sb.append(sb1);
        }
      }

      encodingObj.put("v", sb);

      return encodingObj;
    } catch (Throwable t) {
      mLog.error("[ENCODER] " + paramIResponseMessage.getID(), t);
      return null;
    }
  }