Bladeren bron

修改俱乐部bug和赛事刷新问题

xhb 2 maanden geleden
bovenliggende
commit
127885c823

+ 1 - 1
incubator-center/conf/log4j2.xml

@@ -11,7 +11,7 @@
 		<!-- 控制台输出 -->
 		<Console name="Console" target="SYSTEM_OUT">
 			<ThresholdFilter level="${LOG_LEVEL_CONSOLE}" onMatch="ACCEPT" onMismatch="DENY"/>
-			<PatternLayout pattern="${LOG_PATTERN}"/>
+			<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
 		</Console>
 
 		<!-- 日志文件输出 -->

+ 29 - 2
incubator-game/src/main/java/com/incubator/game/contest/Contest.java

@@ -90,7 +90,8 @@ public class Contest {
         this.data = new ContestPO();
         this.data.contestId = contestId;
         // todo 测试
-        this.data.startTime =  LocalDateTime.parse(prop.getOpenTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+        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 = prop.startTime;
 //        this.data.startTime = System.currentTimeMillis() + (2 * 60 * 1000);
         this.data.contestType = 1;
@@ -133,6 +134,11 @@ public class Contest {
             Log.error("根据报名人数刷新晋级配置出错...比赛 : {}, {}, 人数 : {}",
                     this.data.contestId, this.prop.desc, this.actors.size());
         }
+        //给其他人推送当前
+        this.actors.forEach((id, p) -> {
+            Map<String, Object> map = ProtoUtil.contestInfoToMessage(this);
+            p.receive(CommonProto.Cmd.GetSignUpNum_VALUE,map);
+        });
     }
 
     /**
@@ -150,6 +156,11 @@ public class Contest {
             Log.error("根据报名人数刷新晋级配置出错...比赛 : {}, {}, 人数 : {}",
                     this.data.contestId, this.prop.desc, this.actors.size());
         }
+        //给其他人推送当前
+        this.actors.forEach((id, p) -> {
+            Map<String, Object> map = ProtoUtil.contestInfoToMessage(this);
+            p.receive(CommonProto.Cmd.GetSignUpNum_VALUE,map);
+        });
     }
 
     /**
@@ -382,6 +393,8 @@ public class Contest {
      * 比赛开始
      */
     public void doStart() {
+        cn.hutool.json.JSONObject object = new cn.hutool.json.JSONObject();
+        object.put("type","updateCompete");
         // 设置比赛数据
         this.data.curRound += 1;
         // 检测比赛人数是否满足最小人数配置
@@ -393,14 +406,28 @@ public class Contest {
                     data.put("contestState", 3);
                     data.put("contestTime", new Date());
                     Log.debug("比赛结束 : 比赛 : {}, 结束时间 : {}, 人数 : {}", this.data.contestId, DateUtils.formatFullDate(new Date(this.data.startTime)), this.actors.size());
-                    tmPlayer.receive(CommonProto.Cmd.EndOfRace_VALUE, data);
+                    tmPlayer.receive(CommonProto.Cmd.FlowOffice_VALUE, data);
                     tmPlayer.data.contestId = 0;
                 }
             }
             this.state = 3;
             this.isActive = false;
+            object.put("status","5");
+            object.put("competeId",this.data.contestId);
+            try {
+                RabbitMQUtil.sendMessage(object.toString());
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
             return;
         }
+        object.put("status","3");
+        object.put("competeId",this.data.contestId);
+        try {
+            RabbitMQUtil.sendMessage(object.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         // 动态分配比赛房间
         this.allocateRooms();
         Log.info("当前轮次 :{}", this.data.curRound);

+ 3 - 3
incubator-game/src/main/java/com/incubator/game/handler/club/ApplyJoinClub.java

@@ -59,7 +59,7 @@ public class ApplyJoinClub extends NetHandler {
         ZjUserLobbyPo lobbyUser = JSONUtil.toBean((JSONObject) lobbyUserObj, ZjUserLobbyPo.class);
 
         JSONArray appJoinList = userObject.getJSONArray("appJoinList");
-        if (appJoinList != null) {
+        if (appJoinList != null&&appJoinList.size()>0) {
             appJoinList.add(clubId);
             userObject.put("appJoinList", appJoinList);
 
@@ -68,7 +68,6 @@ public class ApplyJoinClub extends NetHandler {
             appJoinList.add(clubId);
         }
         userObject.put("appJoinList", appJoinList);
-        RedisUtil.set(RedisKeyConstant.USER_BASE + newClubMember.getUserId(), userObject.toString());
 
         //创建成员信息
         newClubMember.setMemberId(UtilCore.getDateRandomId());
@@ -79,7 +78,7 @@ public class ApplyJoinClub extends NetHandler {
         String memBerList = RedisUtil.get(RedisKeyConstant.CLUB_MEMBER + newClubMember.getClubId());
         JSONArray clubMember = JSONUtil.parseObj(memBerList).getJSONArray("clubMember");
         List<ZjClubMemberPo> clubMemberPos = clubMember.toList(ZjClubMemberPo.class);
-        if (clubMemberPos.stream().anyMatch(x -> x.getUserId().equals(userId))) {
+        if (clubMemberPos.stream().anyMatch(x -> x.getUserId().equals(userId)&&x.getMemberStatus().equals("0"))) {
             response.setCode(CommonProto.Code.PARAMETER_ERR_VALUE);
             response.setMessage("您已经申请过该俱乐部了!");
             return;
@@ -104,6 +103,7 @@ public class ApplyJoinClub extends NetHandler {
         JSONObject object = new JSONObject();
         object.put("clubMember", clubMember);
         RedisUtil.set(RedisKeyConstant.CLUB_MEMBER + newClubMember.getClubId(), object.toString());
+        RedisUtil.set(RedisKeyConstant.USER_BASE + newClubMember.getUserId(), userObject.toString());
         response.setMessage("申请成功!");
     }
 }

+ 2 - 3
incubator-game/src/main/java/com/incubator/game/handler/club/CreateClub.java

@@ -228,9 +228,8 @@ public class CreateClub extends NetHandler {
 
         //查询当前用户的主俱乐部
         String userClub = lobbyUser.getUserClub();
-        if (userClub == null||userClub.equals("")) {
-            lobbyUser.setUserClub(newClub.getClubId());
-        }else {
+        lobbyUser.setUserClub(newClub.getClubId());
+        if (userClub != null&&!userClub.equals("")) {
             String oldClub = RedisUtil.get(RedisKeyConstant.CLUB_MEMBER + userClub);
             JSONObject oldClubJO = JSONUtil.parseObj(oldClub);
             JSONArray clubArray = oldClubJO.getJSONArray("clubMember");

+ 3 - 3
incubator-game/src/main/java/com/incubator/game/handler/club/DeleteMember.java

@@ -67,7 +67,7 @@ public class DeleteMember extends NetHandler {
 
             ZjClubMember zjClubMember1 = new ZjClubMember();
             zjClubMember1.setMemberId(zjClubMember.getMemberId());
-            zjClubMember1.setMemberStatus(zjClubMember1.getMemberStatus());
+            zjClubMember1.setMemberStatus(zjClubMember.getMemberStatus());
             JSONObject object1 = new JSONObject();
             object1.put("type", "saveClubMember");
             object1.put("data", zjClubMember1);
@@ -107,7 +107,7 @@ public class DeleteMember extends NetHandler {
 
             if (lobbyUser.getUserClub().equals(clubId)) {
                 if (clubPoList.isEmpty()) {
-                    lobbyUser.setUserClub(null);
+                    lobbyUser.setUserClub("");
                 } else {
                     ZjClubPo newClub = clubPoList.get(0); // 直接选择第一个作为主俱乐部
                     lobbyUser.setUserClub(newClub.getClubId());
@@ -123,7 +123,7 @@ public class DeleteMember extends NetHandler {
                     e.printStackTrace();
                 }
             }
-            userObject.put("clubList", userClubList);
+            userObject.put("clubList", clubPoList);
             RedisUtil.set(RedisKeyConstant.USER_BASE + userId, userObject.toString());
         }
         response.setMessage("删除成功");

+ 1 - 1
incubator-game/src/main/java/com/incubator/game/handler/club/DissolveClub.java

@@ -107,7 +107,7 @@ public class DissolveClub extends NetHandler {
             userClubPoList.removeIf(clubPo -> clubId.equals(clubPo.getClubId()));
             if (lobbyUser.getUserClub().equals(clubId)) {
                 if (userClubPoList.isEmpty()) {
-                    lobbyUser.setUserClub(null);
+                    lobbyUser.setUserClub("");
                 } else {
                     ZjClubPo newClub = userClubPoList.get(0); // 直接选择第一个作为主俱乐部
                     lobbyUser.setUserClub(newClub.getClubId());

+ 1 - 1
incubator-game/src/main/java/com/incubator/game/handler/club/QuitClub.java

@@ -124,7 +124,7 @@ public class QuitClub extends NetHandler {
         String userClub = lobbyUser.getUserClub();
         if (userClub != null && userClub.equals(clubId)) {
             if (clubList.isEmpty()) {
-                lobbyUser.setUserClub(null);
+                lobbyUser.setUserClub("");
             } else {
                 Random random = new Random();
                 int randomIndex = random.nextInt(clubList.size());

+ 1 - 1
incubator-game/src/main/java/com/incubator/game/handler/club/SearchClub.java

@@ -38,7 +38,7 @@ public class SearchClub extends NetHandler {
 
         String userId = session.getUid();
         String type = request.getDataValue("type", String.class, "");
-        String name = request.getDataValue("name", String.class, "");
+        String name = request.getDataValue("searchText", String.class, "");
         Map<String, Object> map = new HashMap<>();
         switch (type){
             case "club":

+ 12 - 3
incubator-game/src/main/java/com/incubator/game/handler/contest/GetClubCompetitionListHandler.java

@@ -13,7 +13,9 @@ import com.incubator.game.contest.Contest;
 import com.incubator.game.contest.ContestService;
 import com.incubator.game.data.jedis.RedisUtil;
 import com.incubator.game.data.po.ZjClubPo;
+import com.incubator.game.player.Player;
 import com.incubator.game.util.JsonToMapUtil;
+import com.incubator.game.util.PlayerUtil;
 import com.incubator.game.util.ProtoUtil;
 import com.incubator.message.proto.CommonProto;
 
@@ -36,18 +38,25 @@ public class GetClubCompetitionListHandler extends NetHandler {
         response.setCmd(CommonProto.Cmd.GetClubCompetitionListRes_VALUE);
 
         String uid = session.getUid();
+        Player player = (Player) PlayerUtil.getOnlinePlayer(uid);
         Map<String, Object> map = new HashMap<>();
         // 俱乐部比赛信息列表
+
+        map.put("contestInfo", contestInfoList(player));
+        response.setData(map);
+    }
+
+    public static List<Object> contestInfoList( Player player){
         List<Object> list = new ArrayList<>();
         for (Contest contest : ContestService.getInstance().contestMap.values()) {
             if (contest != null&&contest.prop.getCompeteType() == 2) {
-                list.add(contestInfoToMessageByUId(contest,uid));
+                list.add(contestInfoToMessageByUId(contest,player.getUid()));
             }
         }
-        map.put("contestInfo", list);
-        response.setData(map);
+        return list;
     }
 
+
     public static Map<String, Object> contestInfoToMessageByUId(Contest contest,String uid) {
         Map<String, Object> data = new HashMap<>();
         if (contest != null) {

+ 12 - 3
incubator-game/src/main/java/com/incubator/game/handler/contest/GetContestListHandler.java

@@ -11,6 +11,7 @@ import com.incubator.game.contest.Contest;
 import com.incubator.game.contest.ContestService;
 import com.incubator.game.player.Player;
 import com.incubator.game.util.JsonToMapUtil;
+import com.incubator.game.util.PlayerUtil;
 import com.incubator.game.util.ProtoUtil;
 import com.incubator.message.proto.CommonProto;
 
@@ -31,18 +32,26 @@ public class GetContestListHandler  extends NetHandler {
         response.setCmd(CommonProto.Cmd.GetContestListRes_VALUE);
 
         String uid = session.getUid();
+        Player player = (Player)PlayerUtil.getOnlinePlayer(uid);
         Map<String, Object> map = new HashMap<>();
         // 官方比赛信息列表
+
+
+        map.put("contestInfo", contestInfoList(player));
+        response.setData(map);
+    }
+
+
+    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,uid));
+                list.add(contestInfoToMessageByUId(contest,player.getId()));
             }
         }
-        map.put("contestInfo", list);
-        response.setData(map);
+        return list;
     }
 
     public static Map<String, Object> contestInfoToMessageByUId(Contest contest,String uid) {

+ 26 - 0
incubator-game/src/main/java/com/incubator/game/handler/http/CompeteHandler.java

@@ -10,15 +10,22 @@ import com.incubator.common.util.RandomUtil;
 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.GGame;
 import com.incubator.game.contest.ContestService;
 import com.incubator.game.data.data.ContestCO;
 import com.incubator.game.data.data.GameData;
 import com.incubator.game.data.data.PromotionLvCO;
 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.GPlayer;
+import com.incubator.game.player.Player;
 import com.incubator.game.util.MapToObject;
 import com.incubator.game.util.ProtoUtil;
+import com.incubator.message.proto.CommonProto;
 
 import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -40,6 +47,7 @@ public class CompeteHandler extends HttpHandler {
         HttpResponse httpResponse = new HttpResponse();
         httpResponse.setCode(200);
         httpResponse.setMessage("成功!");
+        Map<String, GPlayer> onlinePlayers = GGame.onlinePlayers;
         Integer competeType = Integer.parseInt(params.get("competeType"));
         ContestExt contestCO = new ContestExt();
         contestCO.setCompeteType(competeType);
@@ -58,9 +66,27 @@ public class CompeteHandler extends HttpHandler {
                 contestCO.setClubMode(Integer.parseInt(params.get("clubMode")));
                 creteContest(params,contestCO);
             }
+            onlinePlayers.forEach((key, value) -> {
+                Player player = (Player) value;
+                List<Object> objects1 = GetClubCompetitionListHandler.contestInfoList(player);
+                Map<String, Object> map = new HashMap<>();
+                // 官方比赛信息列表
+                map.put("contestInfo", objects1);
+                player.receive(CommonProto.Cmd.GetClubCompetitionListRes_VALUE,map);
+            });
             return httpResponse;
         }
         creteContest(params,contestCO);
+
+        //推送比赛列表
+        onlinePlayers.forEach((key, value) -> {
+            Player player = (Player) value;
+            List<Object> objects = GetContestListHandler.contestInfoList(player);
+            Map<String, Object> map = new HashMap<>();
+            // 官方比赛信息列表
+            map.put("contestInfo", objects);
+            player.receive(CommonProto.Cmd.GetContestListRes_VALUE,map);
+        });
         return httpResponse;
     }
 

+ 2 - 1
incubator-game/src/main/java/com/incubator/game/util/ProtoUtil.java

@@ -116,7 +116,8 @@ public final class ProtoUtil {
             data.put("contestTime", contest.data.startTime);
             data.put("contestState", contest.state);
             data.put("contestPhotoUrl", contest.prop.url);
-            data.put("regisCount", 0);
+//            data.put("regisCount", 0);
+            data.put("regisCount", contest.actors.size());
             data.put("regisMoney", "");
             data.put("regisMoneyType", "");
             data.put("regisList", ProtoUtil.contestRegisListToMessage(contest));

+ 2 - 0
incubator-message/src/main/proto/CommonProto.proto

@@ -148,6 +148,7 @@ enum Cmd {
     GetContestListRes = 200708;  // 获取官方比赛响应
     QuitContestReq = 200709;  // 取消报名请求
     QuitContestRes = 200710;  // 取消报名响应
+    GetSignUpNum = 200712;  // 获取报名人数
 
     //个人活动
     EventInfoReq = 200801;     // 活动信息请求
@@ -190,6 +191,7 @@ enum Cmd {
     DieOutPlayer = 900036;   // 淘汰推送
     EndOfRace = 900038;   // 比赛结束推送
     FirstPlayer = 900040;   // 比赛第一名推送
+    FlowOffice = 900042;   // 比赛流局推送
 
 
     ShopUpdate = 900016;        // 商城更新推送