|
@@ -1,27 +1,19 @@
|
|
|
package com.zanxiang.game.module.sdk.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.github.sd4324530.jtuple.Tuple2;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.BanStatusEnum;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
|
|
|
-import com.zanxiang.game.module.mybatis.entity.Game;
|
|
|
-import com.zanxiang.game.module.mybatis.entity.GameSupper;
|
|
|
import com.zanxiang.game.module.mybatis.entity.IpBan;
|
|
|
-import com.zanxiang.game.module.mybatis.entity.UserEvent;
|
|
|
import com.zanxiang.game.module.mybatis.mapper.IpBanMapper;
|
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
|
-import com.zanxiang.game.module.sdk.service.IGameService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IGameSupperService;
|
|
|
import com.zanxiang.game.module.sdk.service.IIpBanService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IUserEventService;
|
|
|
+import com.zanxiang.game.module.sdk.service.IUserBanService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
+import reactor.util.function.Tuples;
|
|
|
|
|
|
/**
|
|
|
* @author : lingfeng
|
|
@@ -33,49 +25,19 @@ import java.util.Optional;
|
|
|
public class IpBanServiceImpl extends ServiceImpl<IpBanMapper, IpBan> implements IIpBanService {
|
|
|
|
|
|
@Autowired
|
|
|
- private IUserEventService userEventService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IGameSupperService gameSupperService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IGameService gameService;
|
|
|
+ private IUserBanService userBanService;
|
|
|
|
|
|
@Override
|
|
|
- public boolean checkIpBan(UserData userData) {
|
|
|
- IpBan ipBan = super.getOne(new LambdaUpdateWrapper<IpBan>()
|
|
|
- .eq(IpBan::getIp, userData.getIp())
|
|
|
+ public Tuple2<Boolean, HttpStatusEnum> banCheck(UserData userData) {
|
|
|
+ //IP检测
|
|
|
+ if (super.count(new LambdaQueryWrapper<IpBan>()
|
|
|
.eq(IpBan::getGameId, userData.getGameId())
|
|
|
- );
|
|
|
- return ipBan != null && Objects.equals(ipBan.getStatus(), BanStatusEnum.BAN_STATUS.getStatus());
|
|
|
- }
|
|
|
-
|
|
|
- public Tuple2<Boolean, HttpStatusEnum> checkIpBanAndGetStatus(UserData userData) {
|
|
|
- IpBan ipBan = super.getOne(new LambdaUpdateWrapper<IpBan>()
|
|
|
.eq(IpBan::getIp, userData.getIp())
|
|
|
- .eq(IpBan::getGameId, userData.getGameId())
|
|
|
- );
|
|
|
- if (ipBan != null && Objects.equals(ipBan.getStatus(), BanStatusEnum.BAN_STATUS.getStatus())) {
|
|
|
- return Tuple2.with(Boolean.TRUE, HttpStatusEnum.IP_HALT);
|
|
|
- }
|
|
|
- //获取游戏维护状态
|
|
|
- Boolean serverMaintain = Optional.ofNullable(gameService.getById(userData.getGameId()))
|
|
|
- .map(Game::getSuperGameId)
|
|
|
- .flatMap(superGameId -> Optional.ofNullable(gameSupperService.getById(superGameId)))
|
|
|
- .map(GameSupper::getServerMaintain)
|
|
|
- .orElse(null);
|
|
|
- //没有维护, 直接放行
|
|
|
- if (!Objects.equals(serverMaintain, Boolean.TRUE)) {
|
|
|
- return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
|
- }
|
|
|
- //维护中, 测试账号直接放行
|
|
|
- if (userEventService.count(new LambdaQueryWrapper<UserEvent>()
|
|
|
- .eq(UserEvent::getGameId, userData.getGameId())
|
|
|
- .eq(UserEvent::getIp, userData.getIp())
|
|
|
+ .eq(IpBan::getStatus, BanStatusEnum.BAN_STATUS.getStatus())
|
|
|
) > 0) {
|
|
|
- return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
|
+ return Tuples.of(Boolean.TRUE, HttpStatusEnum.IP_HALT);
|
|
|
}
|
|
|
- //返回服务器正在维护中
|
|
|
- return Tuple2.with(Boolean.TRUE, HttpStatusEnum.SERVER_MAINTAIN);
|
|
|
+ //设备检测
|
|
|
+ return userBanService.banCheckByDevice(userData);
|
|
|
}
|
|
|
}
|