Search in sources :

Example 6 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class UserRedisService method addUserMoney.

@Override
public double addUserMoney(long userId, double money) {
    HashOperations<String, String, Double> user_money = redisTemplate.opsForHash();
    // 把修改后的值放入userBean里
    double m = user_money.increment(USER_MONEY, "" + userId, money);
    UserBean userBean = getUserBean(userId);
    if (userBean != null) {
        userBean.setMoney(m);
        updateUserBean(userId, userBean);
    }
    return m;
}
Also used : UserBean(com.code.server.constant.game.UserBean)

Example 7 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class CenterMsgService method guessAddGold.

private static void guessAddGold(String msg) {
    if (msg != null) {
        JsonNode jsonNode = JsonUtil.readTree(msg);
        long userId = jsonNode.path("userId").asLong();
        double gold = jsonNode.path("gold").asDouble();
        UserBean own = RedisManager.getUserRedisService().getUserBean(userId);
        int bindUser1 = own.getReferee();
        // 第一级代理
        if (bindUser1 != 0) {
            UserBean userBean1 = loadUserBean(bindUser1);
            if (userBean1.getId() == 1) {
                // 是总代理
                RedisManager.getUserRedisService().addUserGold(bindUser1, gold * 3);
            } else {
                RedisManager.getUserRedisService().addUserGold(bindUser1, gold);
                // 第二级代理
                int bindUser2 = userBean1.getReferee();
                if (bindUser2 != 0) {
                    UserBean userBean2 = loadUserBean(bindUser2);
                    if (userBean2.getId() == 1) {
                        // 是总代理
                        RedisManager.getUserRedisService().addUserGold(bindUser2, gold * 2);
                    } else {
                        RedisManager.getUserRedisService().addUserGold(bindUser2, gold);
                        // 第三级代理
                        int bindUser3 = userBean2.getReferee();
                        if (bindUser3 != 0) {
                            UserBean userBean3 = loadUserBean(bindUser3);
                            if (userBean3.getId() == 1) {
                                // 是总代理
                                RedisManager.getUserRedisService().addUserGold(bindUser3, gold * 1);
                            } else {
                                RedisManager.getUserRedisService().addUserGold(bindUser3, gold);
                            }
                        }
                    }
                }
            }
            // 给总代理2份
            RedisManager.getUserRedisService().addUserGold(1, gold * 2);
        }
    }
}
Also used : UserBean(com.code.server.constant.game.UserBean) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 8 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class CenterService method saveUser.

private static void saveUser() {
    Set<String> users = RedisManager.getUserRedisService().getSaveUsers();
    if (users != null) {
        UserService userService = SpringUtil.getBean(UserService.class);
        Set<String> removeList = new HashSet<>();
        users.forEach(userId -> {
            long uid = Long.valueOf(userId);
            UserBean userBean = RedisManager.getUserRedisService().getUserBean(uid);
            User user = GameUserService.userBean2User(userBean);
            // 保存
            userService.save(user);
            removeList.add(userId);
        });
        // 批量删除 需要保存的玩家
        if (removeList.size() > 0) {
            RedisManager.getUserRedisService().removeSaveUser(removeList.toArray());
        }
    }
    // 俱乐部 保存
    ClubManager.getInstance().saveAll();
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) HashSet(java.util.HashSet)

Example 9 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class GameClubService method getClubInfo.

/**
 * 获得俱乐部信息
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @return
 */
public int getClubInfo(KafkaMsgKey msgKey, long userId, String clubId) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    // 刷新房间
    initRoomInstance(club);
    boolean isPresident = club.getPresident() == userId;
    ClubVo clubVo = getClubVo_simple(club);
    clubVo.getRoomModels().addAll(club.getClubInfo().getRoomModels());
    // 玩家在线情况
    clubVo.getMember().addAll(club.getClubInfo().getMember().values());
    clubVo.getMember().forEach(clubMember -> {
        String gateId = RedisManager.getUserRedisService().getGateId(clubMember.getUserId());
        boolean online = gateId != null;
        clubMember.setOnline(online);
    });
    club.getClubInfo().getRoomInstance().values().forEach(roomInstance -> {
        if (roomInstance.getRoomId() != null) {
            clubVo.getRoomInstance().add(getRoomInstanceVo(roomInstance));
        }
    });
    // 房间情况
    if (isPresident) {
        clubVo.getApplyList().addAll(club.getClubInfo().getApplyList());
    }
    // todo 初始化数据
    // todo 更改玩家真实信息
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (isPresident) {
        club.setPresidentName(userBean.getUsername());
    }
    ClubMember clubMember = club.getClubInfo().getMember().get("" + userId);
    clubMember.setName(userBean.getUsername());
    clubMember.setImage(userBean.getImage());
    // 发送结果
    sendMsg(msgKey, new ResponseVo("clubService", "getClubInfo", clubVo));
    return 0;
}
Also used : ClubVo(com.code.server.constant.response.ClubVo) UserBean(com.code.server.constant.game.UserBean) Club(com.code.server.db.model.Club) ClubMember(com.code.server.constant.club.ClubMember) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 10 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class LoginAction method login.

@RequestMapping("/login")
public Map<String, Object> login(String account, String password, String token_user) {
    Map<String, Object> params = new HashMap<>();
    int code = 0;
    // redis里的数据
    // 玩家id
    String userId = userRedisService.getUserIdByAccount(account);
    if (userId == null) {
        code = login4sqlByAccount(account, password, params);
        userId = String.valueOf(params.get("userId"));
    } else {
        String redisToken = userRedisService.getToken(Long.valueOf(userId));
        UserBean userBean = userRedisService.getUserBean(Long.valueOf(userId));
        if (!password.equals(userBean.getPassword())) {
            code = ErrorCode.ROLE_ACCOUNT_OR_PASSWORD_ERROR;
        } else {
            redisToken = getToken(Long.valueOf(userId));
            userRedisService.setToken(Long.valueOf(userId), redisToken);
            userBean.setLastLoginDate(new Date());
        }
        params.put("token", redisToken);
        params.put("userId", userId);
    }
    // 黑名单
    boolean isInBlackList = ServerManager.constant.getBlackList() != null && ServerManager.constant.getBlackList().contains(userId);
    if (isInBlackList) {
        code = ErrorCode.BLACK_LIST;
    } else {
        setHostAndPort(userId, params, code == 0);
    }
    System.err.println(params);
    return getParams("login", params, code);
}
Also used : UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserBean (com.code.server.constant.game.UserBean)32 User (com.code.server.db.model.User)12 UserService (com.code.server.db.Service.UserService)9 HashMap (java.util.HashMap)9 ResponseVo (com.code.server.constant.response.ResponseVo)8 ArrayList (java.util.ArrayList)6 Charge (com.code.server.db.model.Charge)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Date (java.util.Date)4 Club (com.code.server.db.model.Club)3 ClubMember (com.code.server.constant.club.ClubMember)2 UserRecord (com.code.server.constant.game.UserRecord)2 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)2 ChargeService (com.code.server.db.Service.ChargeService)2 MsgProducer (com.code.server.kafka.MsgProducer)2 UserRedisService (com.code.server.redis.service.UserRedisService)2 com.code.server.rpc.idl (com.code.server.rpc.idl)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1