public int handleMessage(ISession aSession, IRequestMessage aReqMsg, IResponsePackage aResPkg) {
    //        mLog.debug("[BET] : Catch  ; " + aSession.getUserName());
    MessageFactory msgFactory = aSession.getMessageFactory();
    DeleteMessageResponse resBet =
        (DeleteMessageResponse) msgFactory.getResponseMessage(aReqMsg.getID());

    try {
      DeleteMessageRequest rqAddComment = (DeleteMessageRequest) aReqMsg;
      MessageDB db = new MessageDB();
      db.deleteMessage(rqAddComment.type, rqAddComment.messageId, aSession.getUID());

      resBet.mCode = ResponseCode.SUCCESS;
      aSession.write(resBet);
      CacheUserInfo cache = new CacheUserInfo();
      cache.deleteCacheMessage(aSession.getUID());

    } catch (Throwable t) {
      // resBet.setFailure(ResponseCode.FAILURE, t.getMessage());
      mLog.error("Process message " + aReqMsg.getID() + " error.", t);
      try {
        resBet.setFailure(ResponseCode.FAILURE, "Co loi xay ra");
        aSession.write(resBet);
      } catch (ServerException ex) {
        // java.util.logging.Logger.getLogger(TurnBusiness.class.getName()).log(Level.SEVERE,
        // null, ex);
      }
    }

    return 1;
  }
示例#2
0
  public boolean decode(Object aEncodedObj, IRequestMessage aDecodingObj) throws ServerException {
    try {
      // request data
      JSONObject jsonData = (JSONObject) aEncodedObj;
      FastPlayRequest fast = (FastPlayRequest) aDecodingObj;

      if (jsonData.has("v")) {
        String params = jsonData.getString("v");
        String[] arrValues = params.split(AIOConstants.SEPERATOR_BYTE_1);

        if (arrValues.length > 0) {
          fast.zoneId = Integer.valueOf(arrValues[0]);
        }
        if (arrValues.length > 1) {
          fast.setLevelId(Integer.valueOf(arrValues[1]));
        } else {
          fast.setLevelId(1);
        }

        return true;
      }

      // plain obj
      // decoding
      fast.zoneId = jsonData.getInt("room_id");
      return true;
    } catch (Throwable t) {
      mLog.error("[DECODER] " + aDecodingObj.getID(), t);
      return false;
    }
  }
  @Override
  public boolean decode(Object aEncodedObj, IRequestMessage aDecodingObj) throws ServerException {
    try {
      JSONObject jsonData = (JSONObject) aEncodedObj;
      XESendPrivateMessageRequest rq = (XESendPrivateMessageRequest) aDecodingObj;

      String[] arr = jsonData.getString("v").split(AIOConstants.SEPERATOR_BYTE_1);

      if (arr.length > 0) {
        rq.setToUserId(Long.valueOf(arr[0]));
      }

      if (arr.length > 1) {
        rq.setTitle(arr[1]);
      }

      if (arr.length > 2) {
        rq.setContent(arr[2]);
      }

      return true;
    } catch (Throwable t) {
      mLog.error("[DECODER] " + aDecodingObj.getID(), t);
      return false;
    }
  }
  public int handleMessage(ISession aSession, IRequestMessage aReqMsg, IResponsePackage aResPkg) {
    mLog.debug("get TopGame");
    MessageFactory msgFactory = aSession.getMessageFactory();
    GetTopGameResponse resalbum =
        (GetTopGameResponse) msgFactory.getResponseMessage(aReqMsg.getID());

    try {

      GetTopGameRequest rqAlb = (GetTopGameRequest) aReqMsg;
      UserEntity entity = aSession.getUserEntity();
      CacheGameInfo cacheGame = new CacheGameInfo();
      List<UserEntity> lstUsers = cacheGame.getTopGame(entity.partnerId, rqAlb.gameId);
      StringBuilder sb = new StringBuilder();
      int userSize = lstUsers.size();

      for (int i = 0; i < userSize; i++) {
        UserEntity usrEntity = lstUsers.get(i);
        sb.append(usrEntity.mUid).append(AIOConstants.SEPERATOR_BYTE_1);
        sb.append(usrEntity.mUsername).append(AIOConstants.SEPERATOR_BYTE_1);
        sb.append(usrEntity.point).append(AIOConstants.SEPERATOR_BYTE_1);
        sb.append(usrEntity.playsNumber).append(AIOConstants.SEPERATOR_BYTE_2);
      }

      if (userSize > 0) {
        sb.deleteCharAt(sb.length() - 1);
      }

      resalbum.setSuccess(sb.toString());
      aResPkg.addMessage(resalbum);

    } catch (Exception ex) {
      mLog.error(ex.getMessage(), ex);
      resalbum.setFailure("co loi xay ra");
      aResPkg.addMessage(resalbum);
    } //        catch(BusinessException ex)
    //        {
    //            mLog.warn(ex.getMessage());
    //            resalbum.setFailure(ex.getMessage());
    //
    //        }
    finally {
      //            if (resalbum!= null)
      //            {
      //                try {
      //                    aSession.write(resalbum);
      //                } catch (ServerException ex) {
      //                    mLog.error(ex.getMessage(), ex);
      //                }
      //
      //            }
    }
    return 1;
  }
示例#5
0
  @Override
  public boolean decode(Object aEncodedObj, IRequestMessage aDecodingObj) throws ServerException {
    try {
      // request data
      JSONObject jsonData = (JSONObject) aEncodedObj;
      // request messsage
      JoinRequest matchJoin = (JoinRequest) aDecodingObj;

      String[] arrV = jsonData.getString("v").split(AIOConstants.SEPERATOR_BYTE_1);
      matchJoin.mMatchId = Long.parseLong(arrV[0]);
      // jsonData.getLong("v");
      if (arrV.length > 1) {
        matchJoin.matrixSize = Integer.parseInt(arrV[1]);
      }

      return true;

    } catch (Throwable t) {
      mLog.error("[DECODER] " + aDecodingObj.getID(), t);
      return false;
    }
  }
 @Override
 public int handleMessage(ISession aSession, IRequestMessage aReqMsg, IResponsePackage aResPkg) {
   mLog.debug("[GET_AVATARS]: Catch");
   MessageFactory msgFactory = aSession.getMessageFactory();
   GetChooseAvatarResponse resBuyAvatar =
       (GetChooseAvatarResponse) msgFactory.getResponseMessage(aReqMsg.getID());
   resBuyAvatar.session = aSession;
   try {
     GetChooseAvatarRequest rqBuyAvatar = (GetChooseAvatarRequest) aReqMsg;
     long uid = rqBuyAvatar.uid;
     String res = AvatarManager.getChooseAvatarForUser(uid, aSession.isMobileDevice());
     resBuyAvatar.setSuccess(res);
   } catch (Throwable t) {
     t.printStackTrace();
     resBuyAvatar.setFailure("Có lỗi xảy ra với avatar bạn muốn mua.");
   } finally {
     if ((resBuyAvatar != null)) {
       aResPkg.addMessage(resBuyAvatar);
     }
   }
   return 1;
 }