瀏覽代碼

fix : 新增服务器维护状态禁止登录功能, 暂未应用

bilingfeng 3 周之前
父節點
當前提交
85f74b21c7

+ 5 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/enums/HttpStatusEnum.java

@@ -92,6 +92,11 @@ public enum HttpStatusEnum {
      */
     ACCOUNT_NOT_BIND_PHONE(41110, "账户未绑定手机"),
 
+    /**
+     * 服务器正在维护中
+     */
+    SERVER_MAINTAIN(41111, "服务器正在维护中"),
+
     /**
      * 手机号请使用手机注册
      */

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameSupper.java

@@ -60,6 +60,11 @@ public class GameSupper implements Serializable {
      */
     private String cpServerKey;
 
+    /**
+     * 服务器维护中
+     */
+    private Boolean serverMaintain;
+
     /**
      * 1 删除  0 正常
      */

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/UserEvent.java

@@ -42,4 +42,9 @@ public class UserEvent implements Serializable {
      * 绑定手机号码
      */
     private String mobile;
+
+    /**
+     * 公网IP
+     */
+    private String ip;
 }

+ 48 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/IpBanServiceImpl.java

@@ -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);
+    }
 }