コード例 #1
0
  /**
   * 邀请好友
   *
   * @param args
   */
  @RPCReponse("e_invitation")
  public void invitation(LogicRequest args) {
    Long uid; // 用户id
    Long rid; // 房间id
    List<String> list; // 好友id列表
    List<String> onlinelist = new ArrayList<String>();
    try {
      InvitationOp op = ObjectBeanUtil.JACKSON.readValue(args.getData(), InvitationOp.class);
      if (op != null) {
        uid = op.getUid();
        rid = op.getRid();
        list = op.getList();
        String uName = "";
        String roomName = "";
        UserFundDetails uinfo = LobbyUserHelper.getUserInfo(uid);
        uName = uinfo.getNn();
        Rooms r = LocalCache.ROOMS.get(rid.toString());
        if (r != null) {
          roomName = r.getRn();
        }
        InvitationsRoomVo iRV =
            new InvitationsRoomVo(
                Definition.INVITATIONS, Definition.SUCCESS_CODE, rid, roomName, uid, uName);
        System.out.println(list);
        if (list != null && list.size() > 0) {
          Iterator itr = list.iterator();
          while (itr.hasNext()) {
            Long otherId = Long.valueOf(itr.next().toString());
            if (LobbyUserHelper.isLobby(otherId)) { // 大厅中存在该用户

              // 建立消息通道

              onlinelist.add(otherId.toString());

              // 存储消息邮件
              UserMessageHelper.Message message = new UserMessageHelper.Message();
              message.setTitle("牌局邀请");
              message.setContent(iRV.toString());
              message.setType(MessageManager.Type.INT.getValue());
              message.setSubtype(MessageManager.Subtype.interaction.getValue());
              UserMessageHelper.insertUserMessage(otherId, message);

              // MessageSendUtil.sendAddUserMsgTipToUser(otherId);//更新TOP菜单栏消息提示
              LobbyUserHelper.sendMsgTips(uid);
            }
          }

          LogicChannelUtil.sendToTargets(iRV, onlinelist);
        }
      }
    } catch (Exception e) {
      LOGGER.error("", e);
      e.printStackTrace();
    }
  }
コード例 #2
0
  @Override
  @RPCReponse("e_getoffrooms")
  public ResultVo getOffRooms(LogicRequest args) {
    // TODO 自动生成的方法存根
    ResultVo vo = null;
    Long fbid = null;
    try {
      FlashLoginOp op = ObjectBeanUtil.JACKSON.readValue(args.getData(), FlashLoginOp.class);
      if (op != null) {
        fbid = op.getFbid();
        List<UserInRoom> resultList = new ArrayList<UserInRoom>();
        List<UserInRoom> userInRoomList =
            LocalCache.USER_IN_ROOM.get(String.valueOf(op.getFbid())); // 普通房间
        if (userInRoomList != null) {
          UserInRoom inRoom = null;
          Rooms room = null;
          for (int i = 0; i < userInRoomList.size(); i++) {
            inRoom = userInRoomList.get(i);
            if (inRoom.getIsSit() == 1 || inRoom.getIsSit() == 2) {
              room = LocalCache.getRoom(inRoom.getRid());
              if (room != null) {
                inRoom.setGt(room.getGt());
                // 强制更新
                userInRoomList.set(i, inRoom);
              }
              resultList.add(inRoom);
            }
          }
        }
        // 技术债务, 比赛房间断线重连
        RedisMapMap<Integer /*playerId*/, UserInRoom> roomMapCache =
            new RedisMapMap<Integer /*playerId*/, UserInRoom>(
                "matchroom", Integer.class, UserInRoom.class);
        RedisMapSimple<Integer /*roomId*/, UserInRoom> roommap = roomMapCache.get(op.getFbid());
        if (null != roommap) {
          for (UserInRoom inRoom : roommap.values()) {
            resultList.add(inRoom);
          }
        }

        //				List<UserInRoom> matchUserInRoomList =
        // LocalMatchCache.MATCH_USER_IN_ROOM.get(String.valueOf(op.getFbid()));// 比赛房间
        //				if (matchUserInRoomList != null) {
        //					UserInRoom inRoom = null;
        //					for (int i = 0; i < matchUserInRoomList.size(); i++) {
        //						inRoom = matchUserInRoomList.get(i);
        //						if (inRoom.getIsSit() == 1 || inRoom.getIsSit() == 2) {
        //							Match match = LocalMatchCache.MATCHS.get(inRoom.getMi());
        //							if (match != null) {
        //								MatchUser mu = match.getUsers().get(op.getFbid());
        //								if (mu != null && mu.getRanking() == 0) {// 没有淘汰
        //									resultList.add(inRoom);
        //								}
        //							}
        //						}
        //					}
        //				}
        // 成功
        vo = new ResultVo(Definition.GETOFFROOMS, Definition.SUCCESS_CODE, resultList);
      } else {
        vo = new ResultVo(Definition.GETOFFROOMS, Definition.ARG_CODE, null);
        // Logger.error("deal with getoffroom arg error!!!");
      }
    } catch (Exception e) {
      vo = new ResultVo(Definition.GETOFFROOMS, Definition.UNKNOW_CODE, null);
      // Logger.error("deal with getoffroom error  !!!",e);
    }

    return vo;
  }
コード例 #3
0
  @Override
  @RPCReponse("e_rooms")
  public ResultVo getRooms(LogicRequest args) {
    // TODO 自动生成的方法存根

    Map<Integer, Object> _count = null;
    Map<Long, PlayerInfoInRoom> omIds = null;
    // 查询更新房间,填充到list
    FlashLoginOp op = null;
    try {
      op = ObjectBeanUtil.JACKSON.readValue(args.getData(), FlashLoginOp.class);
    } catch (IOException e) {
      LOGGER.warn("", e);
    }
    // 保存节点记录
    if (op.getGl() > 0) {
      if (op.getGl() == 1) {
        // LobbyUserHelper.saveUserNodeLog(fbid,
        // UserNodeLog.USER_NODE_TALBE_LOW, 0);
      } else if (op.getGl() == 2) {
        // LobbyUserHelper.saveUserNodeLog(fbid,
        // UserNodeLog.USER_NODE_TALBE_MID, 0);
      } else if (op.getGl() == 3) {
        // LobbyUserHelper.saveUserNodeLog(fbid,
        // UserNodeLog.USER_NODE_TALBE_HIG, 0);
      }
    }

    // 显示最大空座数
    Integer maxEmptyLevelRoom = LogicPropertyUtil.getInteger("option.max.empty.level.room", 1);

    Map<String, Map<Integer, Integer>> emptyLevelRoom =
        new HashMap<String, Map<Integer, Integer>>(); // 某个房间等级下几人场空的房间
    Map<Double, Map<Integer, Integer>> lock =
        new HashMap<Double, Map<Integer, Integer>>(); // 小盲对应的锁
    // 通过roomId比较排序
    Map<String, Rooms> sortRooms = MapUtils.sortKey(LocalCache.ROOMS);
    Iterator iter = sortRooms.entrySet().iterator(); // 获得map的Iterator
    Map<Integer, Integer> mc = null;
    ResultVo vo = null;

    if (op.getGt() == 1) { // 简洁
      // ----------------------------------1----------------------------------
      Rooms room = null;
      Map<String, RoomsAsBB> roomlist = new HashMap<String, RoomsAsBB>();
      List<RoomsAsBB> list = new ArrayList<RoomsAsBB>();

      while (iter.hasNext()) {
        try {
          Entry entry = (Entry) iter.next();
          room = (Rooms) entry.getValue();

          if (op.getGt() == room.getGl()) {
            omIds = LocalCache.PLAYER_ON_ROOM.get(room.getRid());
            room.setCc(omIds == null ? 0 : omIds.size());

            RoomsAsBB rbb = roomlist.get(room.getGid());
            if (rbb != null) {
              rbb.setCc(rbb.getCc() + room.getCc());
            } else {
              rbb = new RoomsAsBB();
              rbb.setGr(room.getGid());
              rbb.setSb(room.getSb());
              rbb.setBb(room.getBb());
              rbb.setDefc(room.getDefc());
              rbb.setCc(room.getCc());
              rbb.setRn("");
            }
            roomlist.put(room.getGid(), rbb);
          }

        } catch (Exception e) {
          // TODO: handle exception
        }
      }

      if (roomlist.size() > 0) {

        Iterator<Entry<String, RoomsAsBB>> riter = roomlist.entrySet().iterator();
        while (riter.hasNext()) {
          try {
            Map.Entry<String, RoomsAsBB> entry = riter.next();

            RoomsAsBB rbb = entry.getValue();
            list.add(rbb);
          } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
          }
        }
      }
      vo = new ResultVo(Definition.ROOMS, Definition.SUCCESS_CODE, list, op.getGt());

    } else if (op.getGt() == 2) { // 复杂
      // --------------------------------2-----------------------------------
      List<Rooms> list = new ArrayList<Rooms>();

      Rooms room = null;
      while (iter.hasNext()) {
        try {
          Entry entry = (Entry) iter.next();
          room = (Rooms) entry.getValue();
          if (op.getGl() == 0 || op.getGl() == room.getGl()) {
            omIds = LocalCache.PLAYER_ON_ROOM.get(room.getRid());
            room.setCc(omIds == null ? 0 : omIds.size());

            // 状态类型筛选
            if (op.getSt() > 0) {
              if (op.getSt() == 5) { // 隐藏满员桌
                if (room.getCc() == room.getMc()) {
                  continue;
                }
              } else if (op.getSt() == 6) { // 隐藏空桌
                if (room.getCc() == 0) {
                  continue;
                }
              } else if (op.getSt() == 56) { // 满足上面两个情况
                if (room.getCc() == room.getMc() || room.getCc() == 0) {
                  continue;
                }
              }
            }

            // 记录空房间数量
            if (omIds == null || omIds.size() == 0) {
              if (emptyLevelRoom.containsKey(room.getGid())) {
                mc = emptyLevelRoom.get(room.getGid());
                if (mc != null && mc.containsKey(room.getMc())) {
                  mc.put(room.getMc(), mc.get(room.getMc()) + 1);
                } else {
                  mc = new HashMap<Integer, Integer>();
                  mc.put(room.getMc(), 1);
                }
                emptyLevelRoom.put(room.getGid(), mc);
              } else {
                mc = new HashMap<Integer, Integer>();
                mc.put(room.getMc(), 1);
                emptyLevelRoom.put(room.getGid(), mc);
              }

              // 空房间数量是否超过设置
              if (mc.get(room.getMc()) > maxEmptyLevelRoom) {
                continue;
              }
            }
            /*
             * if(omIds != null && omIds.size() > 0){ _count =
             * getAp(room.getRid());
             * room.setAp(Double.valueOf(_count.get
             * (0).toString()).intValue());
             * room.setFr(Double.valueOf(_count
             * .get(1).toString()).intValue());
             * room.setRh(Integer.valueOf
             * (_count.get(2).toString())); }else{ room.setAp(0D);
             * room.setFr(0D); room.setRh(0);
             * LobbyCache.GAME_ROOMS_END.remove(room.getRid()); }
             * room.setSt(omIds != null && omIds.containsKey(fbid) ?
             * true : false); //锁 Map<Integer,Integer> lockroom =
             * null; if(lock.containsKey(room.getSb())){ lockroom =
             * lock.get(room.getSb()); }else{ lockroom =
             * LobbyUserHelper.getRoomLock(fbid, room.getSb(),
             * room.getBb()); lock.put(room.getSb(), lockroom); }
             * room.setClk(lockroom.get(0));
             * room.setLk(lockroom.get(1));
             */
            if (room.getCc() > room.getMc()) { // 出现不同步的情况下应急处理
              room.setCc(room.getMc());
            }
            list.add(room);
          }
        } catch (Exception e) {
          break;
        }
      }
      vo = new ResultVo(Definition.ROOMS, Definition.SUCCESS_CODE, list, op.getGl());

    } else if (op.getGt() == 3) { // 比赛
      // ---------------------------------3-------------------------------
    }

    return vo;
  }