@Override @RPCReponse("e_logout") public void logout(LogicRequest args) { String channelId = args.getChannelId(); String sessionId = args.getSession(); AppContext.getBean(GameCarService.class).removeUser(sessionId); String proxyId = LogicPropertyUtil.getString("proxy.id"); String keyProxyMap = String.format(RedisKeys.KEY_LOGIN_PROXY, proxyId); String targetMapping = redis.hget(RedisKeys.KEY_LOGIN_MAPPING, sessionId); if (null != targetMapping) { String[] mappingInfo = targetMapping.split("@"); String targetRouter = mappingInfo[0]; String targetChannelId = mappingInfo[1]; if (proxyId.equals(targetRouter) && targetChannelId.equals(channelId)) { // 删除登陆记录 redis.hdel(RedisKeys.KEY_LOGIN_MAPPING, sessionId); } } String oldChannelId = redis.hget(keyProxyMap, sessionId); if (null != oldChannelId && oldChannelId.equals(channelId)) { // 删除登陆记录 redis.hdel(keyProxyMap, sessionId); } }
@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; }
@Override @RPCReponse("e_login") public LoginVo login(LogicRequest args) { // ConcurrentHashMap<Long, PlayerInfoInSupremeRoom> inRoomQueue = // CarCache.PLAYER_INFO_IN_SUPREMEROOM; // System.out.println(inRoomQueue); FlashLoginOp rpcMap = null; try { rpcMap = ObjectBeanUtil.JACKSON.readValue(args.getData(), FlashLoginOp.class); } catch (IOException e) { LOGGER.warn("", e); } // Users uf = usersDao.get(rpcMap.getFbid()); /* * UserFundInfoVo users = LocalCache.USER_FUNDS.get(rpcMap.getFbid()); * if (users == null) {// 从本地调试或手机端登录的账,这里进入系统缓存 String imgurl = ""; * * imgurl = LobbyUserHelper.getFigureurl(rpcMap.getFbid(), null); * * UserFund userFund = LobbyUserHelper.getUserFund(rpcMap.getFbid());// * userFundDao.get(rpcMap.getFbid()); if (userFund != null) { * userFund.setImgurl(imgurl); users = * LobbyUserHelper.saveUserInfoToCache(userFund, false); * * } } */ String userNick = null; RedisLogin redis = SpringUtils.getBean(RedisLogin.class); String uname = redis.hget(USER_INFO_CECHED_PRDFIX + rpcMap.getFbid(), "name"); if (uname == null) userNick = "joker"; else userNick = uname; List<TodayMatchs> matchs = null; // MatchService.getTodayMatchs();// 今日大赛 // 返回值 /** * String cmd, long code, int isn, int isg, double gchips, long sessionid, String name, int lds, * double ldcs, double ldms, List<TodayMatchs> matchs */ LoginVo vo = new LoginVo( Definition.LOGIN, Definition.SUCCESS_CODE, LobbyUserHelper.isLoginNewUser(rpcMap.getFbid()), userNick, matchs); String key = ""; boolean isenablerk = true; // OptionUtils.convertToBoolean(OptionUtils.getDefaultOption("option.api.appkey.reload.enable", // "true")); if (isenablerk) { // 重连的时候需要重置sign key = UUID.randomUUID().toString(); // LobbyUserHelper.updateUserSign(fbId, key); } vo.setKey(key); // 获取用户sessionid String sessionId = args.getSession(); // 获取用户所在的映射服务器 String targetMapping = redis.hget(RedisKeys.KEY_LOGIN_MAPPING, sessionId); if (null == targetMapping) // 没有登陆 { String proxyId = LogicPropertyUtil.getString("proxy.id", "proxy1"); String keyProxyMap = String.format(RedisKeys.KEY_LOGIN_PROXY, proxyId); // 保存映射 redis.hset( RedisKeys.KEY_LOGIN_MAPPING, sessionId, String.format("%s@%s", proxyId, args.getChannelId())); redis.hset(keyProxyMap, args.getSession(), args.getChannelId()); } else // 已经登陆 { boolean isPlayGame = LobbyUserHelper.isPlay(Long.valueOf(sessionId)); // TODO // 是否在游戏当中 String[] mappingInfo = targetMapping.split("@"); String targetRouter = mappingInfo[0]; String targetChannelId = mappingInfo[1]; if (isPlayGame) // 正在玩游戏 { // TODO 通知当前通信的客户端下线 vo = new LoginVo(Definition.LOGIN, Definition.REPEAT_CODE); return vo; } else { LoginVo event = new LoginVo(Definition.OTHERPLAYLOGIN, Definition.REPEAT_CODE); // 踢出前一个正在操作的对象 ProxyResponse response = new ProxyResponse(); response.setChannelId(targetChannelId); response.setSession(sessionId); response.setReponse(event); response.setIsRoute(1); response.setProxy(targetRouter); Event responseEvent = io.nadron.client.event.Events.dataInEvent(ProxyResponseBuilder.build(response)); LogicChannelUtil.writeObjectToChannel(responseEvent); // 保存映射关系 String proxyId = LogicPropertyUtil.getString("proxy.id"); String keyProxyMap = String.format(RedisKeys.KEY_LOGIN_PROXY, proxyId); // 保存映射 redis.hset( RedisKeys.KEY_LOGIN_MAPPING, sessionId, String.format("%s@%s", proxyId, args.getChannelId())); redis.hset(keyProxyMap, args.getSession(), args.getChannelId()); } LobbyUserHelper.deleteAllUserInRoom(sessionId); } LobbyUserHelper.sendJewelBoxMoneyFromData(sessionId); // 发送公告 Notices n = LobbyMsgHelper.getLastNotice(); if (n != null && System.currentTimeMillis() < n.getEndTime().getTime()) { MsgSendVo msgvo = new MsgSendVo( Definition.NOTICES, n.getContent(), DateUtils.dateToString( new Date(n.getOperatedTime().getTime()), DateUtils.PATTERN_YMDHMS)); // 发送 LogicChannelUtil.sendToTargets(msgvo, Lists.newArrayList(sessionId)); } // return vo; }