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;
}
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);
}
}
}
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();
}
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;
}
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);
}
Aggregations