|
@@ -6,22 +6,18 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.github.sd4324530.jtuple.Tuple2;
|
|
import com.github.sd4324530.jtuple.Tuple2;
|
|
import com.zanxiang.game.module.base.pojo.enums.BanStatusEnum;
|
|
import com.zanxiang.game.module.base.pojo.enums.BanStatusEnum;
|
|
import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
|
|
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.IpBan;
|
|
-import com.zanxiang.game.module.mybatis.entity.UserEvent;
|
|
|
|
|
|
+import com.zanxiang.game.module.mybatis.entity.UserBan;
|
|
import com.zanxiang.game.module.mybatis.mapper.IpBanMapper;
|
|
import com.zanxiang.game.module.mybatis.mapper.IpBanMapper;
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
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.IIpBanService;
|
|
-import com.zanxiang.game.module.sdk.service.IUserEventService;
|
|
|
|
|
|
+import com.zanxiang.game.module.sdk.service.IUserBanService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author : lingfeng
|
|
* @author : lingfeng
|
|
@@ -33,13 +29,7 @@ import java.util.Optional;
|
|
public class IpBanServiceImpl extends ServiceImpl<IpBanMapper, IpBan> implements IIpBanService {
|
|
public class IpBanServiceImpl extends ServiceImpl<IpBanMapper, IpBan> implements IIpBanService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private IUserEventService userEventService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private IGameSupperService gameSupperService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private IGameService gameService;
|
|
|
|
|
|
+ private IUserBanService userBanService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean checkIpBan(UserData userData) {
|
|
public boolean checkIpBan(UserData userData) {
|
|
@@ -50,32 +40,47 @@ public class IpBanServiceImpl extends ServiceImpl<IpBanMapper, IpBan> implements
|
|
return ipBan != null && Objects.equals(ipBan.getStatus(), BanStatusEnum.BAN_STATUS.getStatus());
|
|
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())
|
|
|
|
|
|
+ public Tuple2<Boolean, HttpStatusEnum> banCheck(UserData userData) {
|
|
|
|
+ //IP检测
|
|
|
|
+ if (super.count(new LambdaQueryWrapper<IpBan>()
|
|
.eq(IpBan::getGameId, userData.getGameId())
|
|
.eq(IpBan::getGameId, userData.getGameId())
|
|
- );
|
|
|
|
- if (ipBan != null && Objects.equals(ipBan.getStatus(), BanStatusEnum.BAN_STATUS.getStatus())) {
|
|
|
|
|
|
+ .eq(IpBan::getIp, userData.getIp())
|
|
|
|
+ .eq(IpBan::getStatus, BanStatusEnum.BAN_STATUS.getStatus())
|
|
|
|
+ ) > 0) {
|
|
return Tuple2.with(Boolean.TRUE, HttpStatusEnum.IP_HALT);
|
|
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)) {
|
|
|
|
|
|
+ //封禁检测
|
|
|
|
+ if (StringUtils.isAllBlank(userData.getImei(), userData.getAndroidId(), userData.getOaid())) {
|
|
return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
}
|
|
}
|
|
- //维护中, 测试账号直接放行
|
|
|
|
- if (userEventService.count(new LambdaQueryWrapper<UserEvent>()
|
|
|
|
- .eq(UserEvent::getGameId, userData.getGameId())
|
|
|
|
- .eq(UserEvent::getIp, userData.getIp())
|
|
|
|
- ) > 0) {
|
|
|
|
- return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
|
|
|
|
+ //匹配已封禁设备标识
|
|
|
|
+ LambdaQueryWrapper<UserBan> queryWrapper = new LambdaQueryWrapper<UserBan>();
|
|
|
|
+ queryWrapper.and(qw -> {
|
|
|
|
+ boolean hasCondition = false;
|
|
|
|
+ //安卓id匹配
|
|
|
|
+ if (StringUtils.isNoneBlank(userData.getAndroidId())) {
|
|
|
|
+ qw.or().eq(UserBan::getAndroidId, userData.getAndroidId());
|
|
|
|
+ hasCondition = true;
|
|
|
|
+ }
|
|
|
|
+ //imei匹配
|
|
|
|
+ if (StringUtils.isNoneBlank(userData.getImei())) {
|
|
|
|
+ qw.or().eq(UserBan::getImei, userData.getImei());
|
|
|
|
+ hasCondition = true;
|
|
|
|
+ }
|
|
|
|
+ //oaid匹配
|
|
|
|
+ if (StringUtils.isNoneBlank(userData.getOaid())) {
|
|
|
|
+ qw.or().eq(UserBan::getOaid, userData.getOaid());
|
|
|
|
+ hasCondition = true;
|
|
|
|
+ }
|
|
|
|
+ // 避免无条件的OR查询
|
|
|
|
+ if (!hasCondition) {
|
|
|
|
+ qw.or().apply("1=0");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //查询
|
|
|
|
+ if (userBanService.count(queryWrapper) > 0) {
|
|
|
|
+ return Tuple2.with(Boolean.TRUE, HttpStatusEnum.IP_HALT);
|
|
}
|
|
}
|
|
- //返回服务器正在维护中
|
|
|
|
- return Tuple2.with(Boolean.TRUE, HttpStatusEnum.SERVER_MAINTAIN);
|
|
|
|
|
|
+ return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
}
|
|
}
|
|
}
|
|
}
|