|
@@ -1,16 +1,27 @@
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author : lingfeng
|
|
@@ -21,6 +32,15 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
public class IpBanServiceImpl extends ServiceImpl<IpBanMapper, IpBan> implements IIpBanService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserEventService userEventService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameSupperService gameSupperService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameService gameService;
|
|
|
+
|
|
|
@Override
|
|
|
public boolean checkIpBan(UserData userData) {
|
|
|
IpBan ipBan = super.getOne(new LambdaUpdateWrapper<IpBan>()
|
|
@@ -30,4 +50,32 @@ public class IpBanServiceImpl extends ServiceImpl<IpBanMapper, IpBan> implements
|
|
|
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())
|
|
|
+ ) > 0) {
|
|
|
+ return Tuple2.with(Boolean.FALSE, HttpStatusEnum.SUCCESS);
|
|
|
+ }
|
|
|
+ //返回服务器正在维护中
|
|
|
+ return Tuple2.with(Boolean.TRUE, HttpStatusEnum.SERVER_MAINTAIN);
|
|
|
+ }
|
|
|
}
|