Ver Fonte

同步后台赛事状态,以及赛事异常处理

xhb há 3 meses atrás
pai
commit
0920c5d579

+ 35 - 0
incubator-game/src/main/java/com/incubator/game/GGame.java

@@ -1,5 +1,8 @@
 package com.incubator.game;
 
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONException;
+import cn.hutool.json.JSONObject;
 import com.incubator.common.MessageHandler;
 import com.incubator.common.env.Environment;
 import com.incubator.common.game.AbstractService;
@@ -15,7 +18,9 @@ import com.incubator.common.util.RandomUtil;
 import com.incubator.core.net.http.HttpHandler;
 import com.incubator.core.quartz.QuartzServer;
 import com.incubator.core.quartz.QuartzTask;
+import com.incubator.game.constant.RedisKeyConstant;
 import com.incubator.game.contest.ContestService;
+import com.incubator.game.data.jedis.RedisUtil;
 import com.incubator.game.listener.CenterClientListener;
 import com.incubator.game.listener.HttpInnerListener;
 import com.incubator.core.net.ws.NetHandler;
@@ -29,6 +34,7 @@ import com.incubator.game.player.PlayerPool;
 import com.incubator.game.room.RoomService;
 import com.incubator.game.timer.FlushDB;
 import com.incubator.game.timer.RefreshNewDay;
+import com.incubator.game.util.ContestUtil;
 import com.incubator.game.util.GameDataUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.reflections.Reflections;
@@ -132,6 +138,8 @@ public class GGame extends AbstractService {
         this.initHandler();
         // 6.初始化网络服务
         this.initNetService();
+        //7.查询赛事信息
+        this.getContestList();
     }
 
     @Override
@@ -178,6 +186,7 @@ public class GGame extends AbstractService {
      */
     private PropertiesUtil loadProperties(String fileName) throws Exception {
         String filePath = env.getConfDir() + "/" + fileName;
+        filePath = "E:\\zjGame\\incubator-game\\conf\\"+fileName;
         Log.info("加载配置文件: {}", filePath);
         return new PropertiesUtil(filePath);
     }
@@ -419,6 +428,32 @@ public class GGame extends AbstractService {
         }
     }
 
+    /**
+     * 7.初始化赛事信息
+     */
+    private void getContestList() {
+        Log.info("初始化赛事信息...");
+        String competeListStr = RedisUtil.get(RedisKeyConstant.COMPETE_LIST);
+        if (StringUtils.isEmpty(competeListStr)) {
+            Log.info("赛事信息为空,跳过初始化...");
+            return;
+        }
+        JSONArray jsonArray = null;
+        try {
+            jsonArray = new JSONArray(competeListStr);
+            Log.info("赛事信息获取成功正在初始化...");
+        } catch (JSONException e) {
+            e.printStackTrace();
+            Log.error("JSON信息转换异常: {}", e.getMessage(), e);
+            return;
+        }
+        for (Object o : jsonArray) {
+            JSONObject jsonObject = (JSONObject) o;
+            ContestUtil.createJsonContest(jsonObject);
+        }
+        Log.info("赛事信息初始化完成");
+    }
+
     /**
      * 生成唯一的用户名,格式为 user_123456
      *

+ 6 - 0
incubator-game/src/main/java/com/incubator/game/constant/RedisKeyConstant.java

@@ -32,4 +32,10 @@ public class RedisKeyConstant {
      * 查看个人消息
      */
     public static final String ZJ_USER_MESSAGE = "zj:user:message:";
+
+
+    /**
+     * 赛事信息
+     */
+    public static final String COMPETE_LIST = "compete:list";
 }

+ 142 - 144
incubator-game/src/main/java/com/incubator/game/contest/Contest.java

@@ -38,43 +38,75 @@ import java.util.stream.Collectors;
  */
 public class Contest {
 
-    /** 比赛数据 **/
+    /**
+     * 比赛数据
+     **/
     public ContestPO data;
-    /** 比赛策划表配置 **/
+    /**
+     * 比赛策划表配置
+     **/
     public ContestExt prop;
-    /** 当前晋级配置 **/
+    /**
+     * 当前晋级配置
+     **/
     public PromotionLvCO propPromotionLv;
 
-    /** 激活标记 **/
+    /**
+     * 激活标记
+     **/
     private boolean isActive;
-    /** 检测标记 **/
+    /**
+     * 检测标记
+     **/
     public boolean flag;
-    /** 时间秒数 **/
+    /**
+     * 时间秒数
+     **/
     public int time;
-    /** 比赛状态(0等待/报名中 1比赛开始 2进行中 3已结束) **/
+    /**
+     * 比赛状态(0等待/报名中 1比赛开始 2进行中 3已结束)
+     **/
     public int state;
 
-    /**比赛当前状态0等待/报名中 1比赛开始 2进行中 3当局结束 */
+    /**
+     * 比赛当前状态0等待/报名中 1比赛开始 2进行中 3当局结束
+     */
     public int contestState;
 
-    /** 每个房间玩家容量 **/
+    /**
+     * 每个房间玩家容量
+     **/
     private final int roomCapacity = 4;
 
-    /** 比赛报名角色 [key:玩家id, value:玩家对象]**/
+    /**
+     * 比赛报名角色 [key:玩家id, value:玩家对象]
+     **/
     public Map<String, Player> actors = new ConcurrentHashMap<>();
-    /** 比赛房间列表 **/
+    /**
+     * 比赛房间列表
+     **/
     public Map<Long, Room> rooms = new ConcurrentHashMap<>();
-    /** 等待队列 **/
+    /**
+     * 等待队列
+     **/
     private final ConcurrentLinkedQueue<String> waitingPlayers = new ConcurrentLinkedQueue<>();
-    /**淘汰队列*/
+    /**
+     * 淘汰队列
+     */
     private final ConcurrentLinkedQueue<String> DieOutPlayers = new ConcurrentLinkedQueue<>();
-    /**替补队列*/
+    /**
+     * 替补队列
+     */
     private final ConcurrentLinkedQueue<String> SubstitutePlayers = new ConcurrentLinkedQueue<>();
 
-    /** 是否进行下一轮 **/
+    /**
+     * 是否进行下一轮
+     **/
     public boolean isNext = true;
 
-    /** 比赛任务主线程 **/
+    /**
+     * 比赛任务主线程
+     **/
     private ScheduledExecutorService scheduler;
 
     public Contest() {
@@ -102,21 +134,21 @@ public class Contest {
         this.data = new ContestPO();
         this.data.contestId = contestId;
         // todo 测试
-        this.data.startTime =  LocalDateTime.parse(this.prop.openTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
-        Log.info("比赛开始时间:{}",this.data.startTime);
+        this.data.startTime = LocalDateTime.parse(this.prop.openTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
+        Log.info("比赛开始时间:{}", this.data.startTime);
         this.data.level = this.prop.level;
     }
 
     /**
      * 根据当前人数刷新晋级配置
      *
-     * @param num   实际报名人数
+     * @param num 实际报名人数
      */
     public void refreshPromotionLv(int num) {
 //        for (PromotionLvCO config : GameData.PromotionLvs.values()) {
-            if (num >= this.propPromotionLv.min && num <= this.propPromotionLv.max) {
-                this.propPromotionLv.num = num/2;
-            }
+        if (num >= this.propPromotionLv.min && num <= this.propPromotionLv.max) {
+            this.propPromotionLv.num = num / 2;
+        }
 //        }
     }
 
@@ -146,7 +178,7 @@ public class Contest {
         //给其他人推送当前
         this.actors.forEach((id, p) -> {
             Map<String, Object> map = ProtoUtil.contestInfoToMessage(this);
-            p.receive(CommonProto.Cmd.GetSignUpNum_VALUE,map);
+            p.receive(CommonProto.Cmd.GetSignUpNum_VALUE, map);
         });
     }
 
@@ -168,7 +200,7 @@ public class Contest {
         //给其他人推送当前
         this.actors.forEach((id, p) -> {
             Map<String, Object> map = ProtoUtil.contestInfoToMessage(this);
-            p.receive(CommonProto.Cmd.GetSignUpNum_VALUE,map);
+            p.receive(CommonProto.Cmd.GetSignUpNum_VALUE, map);
         });
     }
 
@@ -186,7 +218,7 @@ public class Contest {
      * 开启官方比赛主线程
      */
     public void startContestTask() {
-        this.isActive = true;
+        this.isActive = this.prop.getRunStatus().equals("Y");
         this.scheduler.scheduleAtFixedRate(() -> {
             try {
                 if (this.isActive) {
@@ -241,14 +273,14 @@ public class Contest {
                 // 进行中
                 if (!this.flag) {
                     // 检测当轮是否结束
-                    if (this.checkRoomsAllOver()){
+                    if (this.checkRoomsAllOver()) {
                         break;
                     }
                 }
                 break;
             case 3:
                 // 下一轮
-                if (this.isNext&&this.time>=10) {
+                if (this.isNext && this.time >= 10) {
 //                    this.state = 1;
                     this.contestState = 1;
                     this.flag = false;
@@ -293,8 +325,7 @@ public class Contest {
      */
     public boolean isStart(Date date) {
         // 时间是否到了
-        boolean boon = date.getTime() >= this.data.startTime - (3 * 1000);
-        return boon;
+        return date.getTime() >= this.data.startTime - (3 * 1000);
     }
 
     /**
@@ -329,9 +360,9 @@ public class Contest {
             jsonData.put("playerNum", 4);
             // 房间最大局数 分为预赛和决赛
 //            jsonData.put("maxRound", this.prop.maxRound);
-            if (this.waitingPlayers.size() <=4){//决赛
+            if (this.waitingPlayers.size() <= 4) {//决赛
                 this.prop.maxRound = this.prop.finalNum;
-            }else {
+            } else {
                 this.prop.maxRound = this.prop.readyNum;
             }
 
@@ -404,11 +435,11 @@ public class Contest {
      */
     public void doStart() {
         cn.hutool.json.JSONObject object = new cn.hutool.json.JSONObject();
-        object.put("type","updateCompete");
+        object.put("type", "updateCompete");
         // 设置比赛数据
         this.data.curRound += 1;
         // 检测比赛人数是否满足最小人数配置
-        if (this.data.curRound==1 && this.actors.size() < this.propPromotionLv.min) {
+        if (this.data.curRound == 1 && this.actors.size() < this.propPromotionLv.min) {
             // 流局结束
             for (Player tmPlayer : this.actors.values()) {
                 if (tmPlayer != null) {
@@ -423,8 +454,8 @@ public class Contest {
             }
             this.state = 3;
             this.isActive = false;
-            object.put("status","5");
-            object.put("competeId",this.data.contestId);
+            object.put("status", "5");
+            object.put("competeId", this.data.contestId);
             try {
                 RabbitMQUtil.sendMessage(object.toString());
             } catch (Exception e) {
@@ -432,15 +463,15 @@ public class Contest {
             }
             return;
         }
-        object.put("status","3");
-        object.put("competeId",this.data.contestId);
+        object.put("status", "3");
+        object.put("competeId", this.data.contestId);
         try {
             RabbitMQUtil.sendMessage(object.toString());
         } catch (Exception e) {
             e.printStackTrace();
         }
         int i = this.waitingPlayers.size() % 4;
-        if (i!=0){
+        if (i != 0) {
             List<String> list = new ArrayList<>(this.waitingPlayers);
             // 打乱列表顺序
             Collections.shuffle(list);
@@ -474,9 +505,9 @@ public class Contest {
             }
 //            switch (room.data.gameType) {
 //                case 1:
-                    if ( room.data.curRound >= this.prop.maxRound && room.state == 3) {
-                        cnt += 1;
-                    }
+            if (room.data.curRound >= this.prop.maxRound && room.state == 3) {
+                cnt += 1;
+            }
 //                    break;
 //            }
         }
@@ -485,8 +516,8 @@ public class Contest {
             this.flag = true;
             //统计分数 晋级
             this.promotionLv();
-            this.propPromotionLv.num = this.rooms.size()/2;
-            if (this.rooms.size()>1){
+            this.propPromotionLv.num = this.rooms.size() / 2;
+            if (this.rooms.size() > 1) {
                 // 结束
                 this.gameOver();
                 //不结算 ,下一轮
@@ -494,16 +525,16 @@ public class Contest {
                 //清理所有房间数据
                 this.rooms.clear();
                 //加入替补玩家
-                if (this.prop.substituteRule==1){
+                if (this.prop.substituteRule == 1) {
                     String playerId = this.DieOutPlayers.poll();
                     if (!StringUtils.isEmpty(playerId)) {
                         Player tmPlayer = (Player) PlayerUtil.getOnlinePlayer(playerId);
                         Map<String, Object> data = ProtoUtil.contestInfoToMessage(this);
-                        data.put("message", "当前比赛可替补,是否花费"+this.prop.substituteCost+"钻石替补");
+                        data.put("message", "当前比赛可替补,是否花费" + this.prop.substituteCost + "钻石替补");
                         tmPlayer.receive(CommonProto.Cmd.CandidatePlayer_VALUE, data);
                     }
                 }
-            }else {
+            } else {
                 this.contestState = 3;
                 this.state = 3;
                 //结束比赛
@@ -519,7 +550,7 @@ public class Contest {
                 for (GPlayer player : onlinePlayers.values()) {
                     Map<String, Object> map = new HashMap<>();
                     // 官方比赛信息列表
-                    map.put("contestInfo", GetContestListHandler.contestInfoList((Player)player));
+                    map.put("contestInfo", GetContestListHandler.contestInfoList((Player) player));
                     player.receive(CommonProto.Cmd.GetContestListRes_VALUE, map);
                 }
             }
@@ -529,7 +560,7 @@ public class Contest {
     }
 
     /**
-     *统计分数 晋级
+     * 统计分数 晋级
      */
     private void promotionLv() {
         Map<Long, List<Struct.PromotionData>> roomMap = this.data.promotionMap.getOrDefault(this.data.curRound, new HashMap<>());
@@ -537,7 +568,7 @@ public class Contest {
         int cnt;
 
         // 首轮按配置表晋级,后面按头游二游晋级
-        cnt = this.prop.model == 4? 2 : 1;
+        cnt = this.prop.model == 4 ? 2 : 1;
 
         List<Player> objects = new ArrayList<>();
         for (Room room : this.rooms.values()) {
@@ -545,47 +576,47 @@ public class Contest {
                 continue;
             }
             List<Struct.PromotionData> list = roomMap.getOrDefault(room.data.roomId, new ArrayList<>());
-                    if (room.data.result.size() >= room.data.maxNum) {
-                        //计算计分 头游
-                        Player Player1 = this.actors.getOrDefault(room.data.result.get(1).playerId,null);
-                        // 分
-                        int scores = 0;
-
-                        // 头游搭档数据
-                        Struct.TeammateData teammateData = ((ZDRoom)room).getTeammate(Player1.data.teammateId);
-                        switch (teammateData.getRank()) {
-                            case 2:
-                                // 搭档2游, +4
-                                scores = 4;
-                                break;
-                            case 3:
-                                // 搭档3游, +2
-                                scores = 2;
-                                break;
-                            case 4:
-                                // 搭档4游, +1
-                                scores = 1;
-                                break;
-                        }
-                        list.add(new Struct.PromotionData(Player1.getId(), Player1.data.avatarUrl, Player1.data.name,scores, 1, this.rooms.size()==1));
-                        Player Player2 = teammateData.player;
-                        Player1.data.matchPoints = Player1.data.matchPoints + scores;
-                        Player2.data.matchPoints = Player2.data.matchPoints + scores;
-                        list.add(new Struct.PromotionData(Player2.getId(), Player2.data.avatarUrl, Player2.data.name,scores, teammateData.rank, this.rooms.size()==1));
-                        objects.add(Player1);
-                        objects.add(Player2);
-                        for (int i = 1; i <= room.data.result.size(); i++) {
-                            Player tmPlayer =this.actors.getOrDefault(room.data.result.getOrDefault(i, null).playerId,null);
-                            if (tmPlayer != null
-                                    && !tmPlayer.getId().equals(Player1.getId())
-                                    && !tmPlayer.getId().equals(teammateData.player.getId())) {
-                                tmPlayer.data.matchPoints = tmPlayer.data.matchPoints - scores;
-                                list.add(new Struct.PromotionData(tmPlayer.getId(), tmPlayer.data.avatarUrl, tmPlayer.data.name, -scores, i, this.rooms.size()==1));
-                                objects.add(tmPlayer);
-                            }
-                        }
+            if (room.data.result.size() >= room.data.maxNum) {
+                //计算计分 头游
+                Player Player1 = this.actors.getOrDefault(room.data.result.get(1).playerId, null);
+                // 分
+                int scores = 0;
+
+                // 头游搭档数据
+                Struct.TeammateData teammateData = ((ZDRoom) room).getTeammate(Player1.data.teammateId);
+                switch (teammateData.getRank()) {
+                    case 2:
+                        // 搭档2游, +4
+                        scores = 4;
+                        break;
+                    case 3:
+                        // 搭档3游, +2
+                        scores = 2;
+                        break;
+                    case 4:
+                        // 搭档4游, +1
+                        scores = 1;
+                        break;
+                }
+                list.add(new Struct.PromotionData(Player1.getId(), Player1.data.avatarUrl, Player1.data.name, scores, 1, this.rooms.size() == 1));
+                Player Player2 = teammateData.player;
+                Player1.data.matchPoints = Player1.data.matchPoints + scores;
+                Player2.data.matchPoints = Player2.data.matchPoints + scores;
+                list.add(new Struct.PromotionData(Player2.getId(), Player2.data.avatarUrl, Player2.data.name, scores, teammateData.rank, this.rooms.size() == 1));
+                objects.add(Player1);
+                objects.add(Player2);
+                for (int i = 1; i <= room.data.result.size(); i++) {
+                    Player tmPlayer = this.actors.getOrDefault(room.data.result.getOrDefault(i, null).playerId, null);
+                    if (tmPlayer != null
+                            && !tmPlayer.getId().equals(Player1.getId())
+                            && !tmPlayer.getId().equals(teammateData.player.getId())) {
+                        tmPlayer.data.matchPoints = tmPlayer.data.matchPoints - scores;
+                        list.add(new Struct.PromotionData(tmPlayer.getId(), tmPlayer.data.avatarUrl, tmPlayer.data.name, -scores, i, this.rooms.size() == 1));
+                        objects.add(tmPlayer);
+                    }
+                }
 //                        objects.addAll(list);
-                        //开始循环
+                //开始循环
 //                        for (int i = 1; i <= ((GDRoom) room).data.result.size(); i++) {
 //                            Player player = ((GDRoom) room).data.result.getOrDefault(i, null);
 //                            if (player != null) {
@@ -652,13 +683,13 @@ public class Contest {
 //                                }
 //                            }
 //                        }
-                    }
+            }
             roomMap.put(room.data.roomId, list);
         }
         //排序
         objects.sort((o1, o2) -> Long.compare(o2.data.matchPoints, o1.data.matchPoints));
-        for (int i = 1; i <=objects.size(); i++) {
-            Player player = objects.get(i-1);
+        for (int i = 1; i <= objects.size(); i++) {
+            Player player = objects.get(i - 1);
             player.data.roomId = 0;
             Map<String, Object> messageMap = new HashMap<>();
             String message;
@@ -672,13 +703,13 @@ public class Contest {
                         processRank(1, player, rewards, map);
                         break;
                     case 2:
-                        processRank(2,player, rewards, map);
+                        processRank(2, player, rewards, map);
                         break;
                     case 3:
-                        processRank(3,player, rewards, map);
+                        processRank(3, player, rewards, map);
                         break;
                     case 4:
-                        processRank(4,player, rewards, map);
+                        processRank(4, player, rewards, map);
                         break;
                 }
                 cmd = CommonProto.Cmd.FirstPlayer_VALUE;
@@ -689,22 +720,22 @@ public class Contest {
                 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 // 格式化Date对象为字符串
                 String formattedDateTime = formatter.format(now);
-                map.put("date",formattedDateTime);
+                map.put("date", formattedDateTime);
                 map.put("contestName", this.prop.desc);
                 messageMap.put("message", map);
                 player.receive(cmd, messageMap);
 
                 cn.hutool.json.JSONObject object = new cn.hutool.json.JSONObject();
-                object.put("type","GetCompeteReward");
-                object.put("userId",player.data.playerId);
-                object.put("competeId",this.data.contestId);
-                object.put("rank",i);
+                object.put("type", "GetCompeteReward");
+                object.put("userId", player.data.playerId);
+                object.put("competeId", this.data.contestId);
+                object.put("rank", i);
                 try {
                     RabbitMQUtil.sendMessage(object.toString());
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
-            }else {
+            } else {
                 if (i <= this.propPromotionLv.num) {
                     roomMap.forEach((key, value) -> {
                         Optional<Struct.PromotionData> first = value.stream()
@@ -720,7 +751,7 @@ public class Contest {
                     cmd = CommonProto.Cmd.PromotePlayer_VALUE;
                     messageMap.put("message", message);
                     player.receive(cmd, messageMap);
-                } else{
+                } else {
                     roomMap.forEach((key, value) -> {
                         Optional<Struct.PromotionData> first = value.stream()
                                 .filter(promotionData -> promotionData.getPlayerId().equals(player.getId()))
@@ -750,15 +781,15 @@ public class Contest {
                 cn.hutool.json.JSONObject reward = (cn.hutool.json.JSONObject) o;
                 String rank1 = (String) reward.get("rank");
                 String[] split = rank1.split("-");
-                if (split.length>1){
-                    int min =  Integer.parseInt(split[0]);
-                    int max =  Integer.parseInt(split[1]);
-                    if (rank>=min&&rank<=max){
-                        getReward(reward,msg);//领奖品处理
+                if (split.length > 1) {
+                    int min = Integer.parseInt(split[0]);
+                    int max = Integer.parseInt(split[1]);
+                    if (rank >= min && rank <= max) {
+                        getReward(reward, msg);//领奖品处理
                     }
-                }else {
-                    if (Integer.parseInt(split[0])==rank) {
-                        getReward(reward,msg);//领奖品处理
+                } else {
+                    if (Integer.parseInt(split[0]) == rank) {
+                        getReward(reward, msg);//领奖品处理
                     }
                 }
             }
@@ -768,7 +799,7 @@ public class Contest {
         map.put("name", player.data.name);
     }
 
-    private static void getReward(cn.hutool.json.JSONObject reward,StringBuilder msg){
+    private static void getReward(cn.hutool.json.JSONObject reward, StringBuilder msg) {
         JSONArray objects = new JSONArray(reward.get("reward"));
         for (Object object : objects) {
             cn.hutool.json.JSONObject obj = (cn.hutool.json.JSONObject) object;
@@ -776,39 +807,6 @@ public class Contest {
         }
     }
 
-    /**
-     * 比赛结算
-     */
-    private void settlement() {
-        this.isActive = false;
-        Log.info("开始结算");
-        //推送第一名
-        Map<Long, List<Struct.PromotionData>> longListMap = this.data.promotionMap.get(this.data.curRound);
-        longListMap.forEach((key, value) -> {
-//            if (key == this.data.curRound){
-                value.forEach(promotionData -> {
-                    // 推送第一名奖状
-                    if(promotionData.rank==1){
-                        String playerId = promotionData.playerId;
-                        Player player = (Player)PlayerUtil.getOnlinePlayer(playerId);
-                        if (player != null) {
-                            Map<String, Object> map = new HashMap<>();
-                            map.put("message", "恭喜你获得第一名");
-                            player.receive(CommonProto.Cmd.FirstPlayer_VALUE, map);
-                        }
-                    }
-                });
-//            }
-        });
-        Log.info("比赛结算完成");
-
-        // 计算排行榜
-
-        // 解散房间
-
-        //
-    }
-
     /**
      * 比赛结束
      */

+ 10 - 0
incubator-game/src/main/java/com/incubator/game/data/data/ContestCO.java

@@ -79,6 +79,16 @@ public class ContestCO {
 	/**替补费用*/
 	public BigDecimal substituteCost;
 
+	/**赛事运行状态  Y上线N下线E初始D删除*/
+	public String runStatus;
+
+	public String getRunStatus() {
+		return runStatus;
+	}
+
+	public void setRunStatus(String runStatus) {
+		this.runStatus = runStatus;
+	}
 
 	public Integer getSubstituteRule() {
 		return substituteRule;

+ 28 - 30
incubator-game/src/main/java/com/incubator/game/handler/contest/GetContestListHandler.java

@@ -26,13 +26,13 @@ import java.util.Map;
  * Description: 获取比赛列表处理器
  */
 @MessageHandler(id = CommonProto.Cmd.GetContestListReq_VALUE)
-public class GetContestListHandler  extends NetHandler {
+public class GetContestListHandler extends NetHandler {
     @Override
     public void onDate(Connection session, WSRequest request, WSResponse response) {
         response.setCmd(CommonProto.Cmd.GetContestListRes_VALUE);
 
         String uid = session.getUid();
-        Player player = (Player)PlayerUtil.getOnlinePlayer(uid);
+        Player player = (Player) PlayerUtil.getOnlinePlayer(uid);
         Map<String, Object> map = new HashMap<>();
         // 官方比赛信息列表
 
@@ -42,45 +42,43 @@ public class GetContestListHandler  extends NetHandler {
     }
 
 
-    public static List<Object> contestInfoList(Player player){
+    public static List<Object> contestInfoList(Player player) {
         List<Object> list = new ArrayList<>();
         for (Contest contest : ContestService.getInstance().contestMap.values()) {
             Log.info(contest.toString());
-            if (contest.prop != null&&contest.prop.getCompeteType() == 0) {
-//                contest.prop.getCompeteType() == 0
-                list.add(contestInfoToMessageByUId(contest,player.getId()));
+            if (contest.prop != null && contest.prop.getCompeteType() == 0 && contest.prop.runStatus.equals("Y")) {
+                list.add(contestInfoToMessageByUId(contest, player.getId()));
             }
         }
         return list;
     }
 
-    public static Map<String, Object> contestInfoToMessageByUId(Contest contest,String uid) {
+    public static Map<String, Object> contestInfoToMessageByUId(Contest contest, String uid) {
         Map<String, Object> data = new HashMap<>();
         if (contest != null) {
-//            if (contest.prop.getCompeteType() == 0){
-                data.put("contestId", contest.data.contestId);
-                data.put("contestName", contest.prop.desc);
-                data.put("contestType", contest.data.contestType);
-                data.put("contestPlayType", contest.prop.gameType);
-                data.put("contestLevel", contest.data.level);
-                data.put("contestTime", contest.data.startTime);
-                data.put("contestState", contest.state);
-                data.put("contestPhotoUrl", contest.prop.url);
-                data.put("contestSystem", contest.prop.contestSystem);
-                JSONArray rewards = contest.prop.rewards;
-                List<Map<String, Object>> mapList1 = JsonToMapUtil.parseJsonArrayToMapList(rewards);
-                data.put("rewards",mapList1);
-                data.put("regisCount", 0);
-                data.put("regisMoney", "");
-                data.put("regisMoneyType", "");
-                List<Map<String, Object>> mapList = ProtoUtil.contestRegisListToMessage(contest);
-                data.put("regisList", mapList);
-                data.put("isSign", false);
-                for (Map<String, Object> map : mapList) {
-                    if (map.get("id").equals(uid)){
-                        data.put("isSign", true);
-                    }
+            data.put("contestId", contest.data.contestId);
+            data.put("contestName", contest.prop.desc);
+            data.put("contestType", contest.data.contestType);
+            data.put("contestPlayType", contest.prop.gameType);
+            data.put("contestLevel", contest.data.level);
+            data.put("contestTime", contest.data.startTime);
+            data.put("contestState", contest.state);
+            data.put("contestPhotoUrl", contest.prop.url);
+            data.put("contestSystem", contest.prop.contestSystem);
+            JSONArray rewards = contest.prop.rewards;
+            List<Map<String, Object>> mapList1 = JsonToMapUtil.parseJsonArrayToMapList(rewards);
+            data.put("rewards", mapList1);
+            data.put("regisCount", 0);
+            data.put("regisMoney", "");
+            data.put("regisMoneyType", "");
+            List<Map<String, Object>> mapList = ProtoUtil.contestRegisListToMessage(contest);
+            data.put("regisList", mapList);
+            data.put("isSign", false);
+            for (Map<String, Object> map : mapList) {
+                if (map.get("id").equals(uid)) {
+                    data.put("isSign", true);
                 }
+            }
 //            }
         }
         return data;

+ 3 - 42
incubator-game/src/main/java/com/incubator/game/handler/http/CompeteHandler.java

@@ -20,6 +20,7 @@ import com.incubator.game.handler.contest.GetClubCompetitionListHandler;
 import com.incubator.game.handler.contest.GetContestListHandler;
 import com.incubator.game.player.GPlayer;
 import com.incubator.game.player.Player;
+import com.incubator.game.util.ContestUtil;
 import com.incubator.game.util.MapToObject;
 import com.incubator.game.util.ProtoUtil;
 import com.incubator.message.proto.CommonProto;
@@ -64,7 +65,7 @@ public class CompeteHandler extends HttpHandler {
                 String clubId = (String) object;
                 contestCO.setClubId(clubId);
                 contestCO.setClubMode(Integer.parseInt(params.get("clubMode")));
-                creteContest(params,contestCO);
+                ContestUtil.createContest(params,contestCO);
             }
             onlinePlayers.forEach((key, value) -> {
                 Player player = (Player) value;
@@ -76,7 +77,7 @@ public class CompeteHandler extends HttpHandler {
             });
             return httpResponse;
         }
-        creteContest(params,contestCO);
+        ContestUtil.createContest(params,contestCO);
 
         //推送比赛列表
         onlinePlayers.forEach((key, value) -> {
@@ -89,44 +90,4 @@ public class CompeteHandler extends HttpHandler {
         });
         return httpResponse;
     }
-
-    private static void creteContest( Map<String, String> params,ContestExt contestCO) {
-        contestCO.setiD(Integer.parseInt(params.get("iD")));
-        contestCO.setGameType(Integer.parseInt(params.get("GameType")));
-        contestCO.setDesc(params.get("Desc"));
-        contestCO.setSubstituteNum(Integer.parseInt(params.get("SubstituteNum")));
-        contestCO.setModel(Integer.parseInt(params.get("Model")));
-        contestCO.setIsOpen(Integer.parseInt(params.get("IsOpen")));
-        contestCO.setOpenTime(params.get("OpenTime"));
-        contestCO.setMaxRound(Integer.parseInt(params.get("MaxRound")));
-        contestCO.setReadyNum(Integer.parseInt(params.get("readyNum")));
-        contestCO.setFinalNum(Integer.parseInt(params.get("finalNum")));
-        contestCO.setLevel(Integer.parseInt(params.get("competeLevel")));
-        contestCO.setCost(new BigDecimal(params.get("cost")));
-        contestCO.setCurrencyType(params.get("currencyType"));
-        contestCO.setContestSystem("规则:预赛"+Integer.parseInt(params.get("readyNum"))+"局,决赛"+Integer.parseInt(params.get("finalNum"))+"局 不可复活 报名费"+Double.parseDouble(params.get("cost"))+getCurrencyType(contestCO.getCurrencyType()) +
-                "\n赛制:转蛋,双下4分,淘汰赛");
-        JSONArray objects1 = new JSONArray(params.get("rewards"));
-        contestCO.setRewards(objects1);
-        contestCO.setMax(Integer.parseInt(params.get("max")));
-        contestCO.setMin(Integer.parseInt(params.get("min")));
-        int candidateRule = Integer.parseInt(params.get("candidateRule"));
-        contestCO.setSubstituteRule(candidateRule);
-        if (candidateRule==1){
-            contestCO.setSubstituteCost(new BigDecimal(params.get("candidateCost")));
-            contestCO.setSubstituteTime(Integer.parseInt(params.get("SubstituteTime")));
-        }
-        ContestService.getInstance().creatContest(contestCO.getGameType(),contestCO.getiD(),contestCO);
-        List<Object> objects = ProtoUtil.contestListToMessage();
-        Log.info("比赛列表 : List={}", objects);
-    }
-
-    private static String getCurrencyType(String competeType){
-        switch (competeType){
-            case "1": return "金币";
-            case "2": return "钻石";
-            case "3": return "福卡";
-            default: return null;
-        }
-    }
 }

+ 48 - 0
incubator-game/src/main/java/com/incubator/game/handler/http/UpdateCompeteHandler.java

@@ -0,0 +1,48 @@
+package com.incubator.game.handler.http;
+
+import com.incubator.common.MessageHandler;
+import com.incubator.core.net.http.HttpHandler;
+import com.incubator.core.net.http.HttpRequest;
+import com.incubator.core.net.http.HttpResponse;
+import com.incubator.game.contest.Contest;
+import com.incubator.game.contest.ContestService;
+import com.incubator.game.data.data.ext.ContestExt;
+import com.incubator.game.util.ProtoUtil;
+import com.incubator.message.proto.CommonProto;
+
+import java.util.Map;
+
+/**
+ * Author:  xhb
+ * Date:  2025-01-07 11:12
+ */
+@MessageHandler(httpPath = "/updateCompete")
+public class UpdateCompeteHandler extends HttpHandler {
+
+    /**
+     * 修改官方赛事回执信息
+     **/
+    @Override
+    public HttpResponse onDate(HttpRequest request, Map<String, String> params) throws Exception {
+        HttpResponse httpResponse = new HttpResponse();
+        httpResponse.setCode(200);
+        httpResponse.setMessage("成功!");
+        long contestId = Long.parseLong(params.get("iD"));
+        Contest contest = ContestService.getInstance().contestMap.getOrDefault(contestId, null);
+        ContestExt prop = contest.prop;
+        String runStatus = params.get("runStatus");
+        prop.setRunStatus(runStatus);
+        if (runStatus.equals("Y")){//如果是Y 开启主线程处理
+            contest.startContestTask();
+        }else { // 如果不是运行状态则踢出所有玩家告知当前比赛异常结束
+            contest.actors.forEach((playerId, player1) -> {
+                player1.data.contestId = 0;
+                player1.data.roomId = 0;
+                Map<String, Object> data = ProtoUtil.contestInfoToMessage(contest);
+                data.put("message", "当前比赛异常结束,参加的费用将会原路返回");
+                player1.receive(CommonProto.Cmd.EndOfRace_VALUE, data);
+            });
+        }
+        return httpResponse;
+    }
+}

+ 1 - 1
incubator-game/src/main/java/com/incubator/game/handler/login/LoginGameHandler.java

@@ -108,7 +108,7 @@ public class LoginGameHandler extends NetHandler {
 		// 玩家绑定的官方比赛id
 		map.put("contestId", player.data.contestId);
 		// 官方比赛信息列表
-		map.put("contestInfo", ProtoUtil.contestListToMessage());
+		map.put("contestInfo", ProtoUtil.contestListByRunToMessage());
 
 		//奖励弹窗
 		String eventStr = RedisUtil.get(RedisKeyConstant.ZJ_USER_EVENT_KEY + userId);

+ 122 - 0
incubator-game/src/main/java/com/incubator/game/util/ContestUtil.java

@@ -0,0 +1,122 @@
+package com.incubator.game.util;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.incubator.common.log4j.Log;
+import com.incubator.game.contest.ContestService;
+import com.incubator.game.data.data.ext.ContestExt;
+import com.incubator.game.handler.contest.GetClubCompetitionListHandler;
+import com.incubator.game.handler.contest.GetContestListHandler;
+import com.incubator.game.player.Player;
+import com.incubator.message.proto.CommonProto;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Author:  xhb
+ * Date:  2025-01-07 11:13
+ */
+public class ContestUtil {
+
+    public static void createContest(Map<String, String> params, ContestExt contestCO) {
+        contestCO.setiD(Integer.parseInt(params.get("iD")));
+        contestCO.setGameType(Integer.parseInt(params.get("GameType")));
+        contestCO.setDesc(params.get("Desc"));
+        contestCO.setSubstituteNum(Integer.parseInt(params.get("SubstituteNum")));
+        contestCO.setModel(Integer.parseInt(params.get("Model")));
+        contestCO.setIsOpen(Integer.parseInt(params.get("IsOpen")));
+        contestCO.setOpenTime(params.get("OpenTime"));
+        contestCO.setMaxRound(Integer.parseInt(params.get("MaxRound")));
+        contestCO.setReadyNum(Integer.parseInt(params.get("readyNum")));
+        contestCO.setFinalNum(Integer.parseInt(params.get("finalNum")));
+        contestCO.setLevel(Integer.parseInt(params.get("competeLevel")));
+        contestCO.setRunStatus(params.get("runStatus"));
+        contestCO.setCost(new BigDecimal(params.get("cost")));
+        contestCO.setCurrencyType(params.get("currencyType"));
+        contestCO.setContestSystem("规则:预赛"+Integer.parseInt(params.get("readyNum"))+"局,决赛"+Integer.parseInt(params.get("finalNum"))+"局 不可复活 报名费"+Double.parseDouble(params.get("cost"))+getCurrencyType(contestCO.getCurrencyType()) +
+                "\n赛制:转蛋,双下4分,淘汰赛");
+        JSONArray objects1 = new JSONArray(params.get("rewards"));
+        contestCO.setRewards(objects1);
+        contestCO.setMax(Integer.parseInt(params.get("max")));
+        contestCO.setMin(Integer.parseInt(params.get("min")));
+        int candidateRule = Integer.parseInt(params.get("candidateRule"));
+        contestCO.setSubstituteRule(candidateRule);
+        if (candidateRule==1){
+            contestCO.setSubstituteCost(new BigDecimal(params.get("candidateCost")));
+            contestCO.setSubstituteTime(Integer.parseInt(params.get("SubstituteTime")));
+        }
+        ContestService.getInstance().creatContest(contestCO.getGameType(),contestCO.getiD(),contestCO);
+        List<Object> objects = ProtoUtil.contestListToMessage();
+        Log.info("比赛列表 : List={}", objects);
+    }
+
+    public static void createJsonContest(JSONObject params) {
+        ContestExt contestCO = new ContestExt();
+        Integer competeType = (Integer)params.get("competeType");
+        contestCO.setCompeteType(competeType);
+        JSONObject Rule = (JSONObject)params.get("Rule");
+        contestCO.setRule(Rule);
+        if (competeType==2){
+            String clubList = (String)params.get("clubList");
+            JSONArray objects = new JSONArray(clubList);
+            for (Object object : objects) {
+                contestCO = new ContestExt();
+                contestCO.setRule(Rule);
+                contestCO.setCompeteType(competeType);
+                String clubId = (String) object;
+                contestCO.setClubId(clubId);
+                contestCO.setClubMode((Integer)params.get("clubMode"));
+                ContestUtil.createContest(params,contestCO);
+            }
+            return;
+        }
+        ContestUtil.createContest(params,contestCO);
+    }
+
+    public static void createContest(JSONObject params, ContestExt contestCO) {
+        contestCO.setiD((Integer)params.get("iD"));
+        contestCO.setGameType((Integer)params.get("GameType"));
+        contestCO.setDesc((String)params.get("Desc"));
+        contestCO.setSubstituteNum((Integer)params.get("SubstituteNum"));
+        contestCO.setModel((Integer)params.get("Model"));
+        contestCO.setIsOpen((Integer)params.get("IsOpen"));
+        contestCO.setOpenTime((String)params.get("OpenTime"));
+        contestCO.setMaxRound((Integer)params.get("MaxRound"));
+        contestCO.setReadyNum((Integer)params.get("readyNum"));
+        contestCO.setFinalNum((Integer)params.get("finalNum"));
+        contestCO.setLevel(Integer.parseInt((String)params.get("competeLevel")));
+        contestCO.setRunStatus((String)params.get("runStatus"));
+        contestCO.setCost(new BigDecimal((Integer)params.get("cost")));
+        contestCO.setCurrencyType((String)params.get("currencyType"));
+        contestCO.setContestSystem("规则:预赛"+params.get("readyNum")+"局,决赛"+params.get("finalNum")+"局 不可复活 报名费"+params.get("cost")+getCurrencyType(contestCO.getCurrencyType()) +
+                "\n赛制:转蛋,双下4分,淘汰赛");
+        JSONArray objects1 = new JSONArray(params.get("rewards"));
+        contestCO.setRewards(objects1);
+        contestCO.setMax((Integer)params.get("max"));
+        contestCO.setMin((Integer)params.get("min"));
+        int candidateRule = Integer.parseInt((String)params.get("candidateRule"));
+        contestCO.setSubstituteRule(candidateRule);
+        if (candidateRule==1){
+            contestCO.setSubstituteCost(new BigDecimal((Integer)params.get("candidateCost")));
+            contestCO.setSubstituteTime((Integer)params.get("SubstituteTime"));
+        }
+        ContestService.getInstance().creatContest(contestCO.getGameType(),contestCO.getiD(),contestCO);
+        List<Object> objects = ProtoUtil.contestListToMessage();
+        Log.info("比赛列表 : List={}", objects);
+    }
+
+
+
+    private static String getCurrencyType(String competeType){
+        switch (competeType){
+            case "1": return "金币";
+            case "2": return "钻石";
+            case "3": return "福卡";
+            default: return null;
+        }
+    }
+}

+ 16 - 0
incubator-game/src/main/java/com/incubator/game/util/ProtoUtil.java

@@ -100,6 +100,22 @@ public final class ProtoUtil {
         return list;
     }
 
+    /**
+     * 官方比赛运行状态集合转消息
+     *
+     * @return
+     */
+    public static List<Object> contestListByRunToMessage() {
+        List<Object> list = new ArrayList<>();
+        for (Contest contest : ContestService.getInstance().contestMap.values()) {
+            if (contest != null&&contest.prop.runStatus.equals("Y")) {
+                list.add(ProtoUtil.contestInfoToMessage(contest));
+            }
+        }
+        return list;
+    }
+
+
     /**
      * 官方比赛集合转消息
      *