@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_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; }