コード例 #1
0
        /// <summary>
        /// TODO:关闭一个玩家现场在匹配系统的存在
        /// 安全操作,尽管退出
        /// </summary>
        /// <param name="toMatchPlayerShutdownMessage"></param>
        private void OnShutdownPlayer(ToMatchPlayerShutdownMessage message)
        {
            Log.Info("收到了玩家现场发来的关闭消息");
            var       playerId  = message.playerId;
            var       teamId    = FindMatchTeamById(playerId);
            MatchTeam matchTeam = null;

            if (teamId == default)
            {
                return;
            }
            if (!m_teamDic.TryGetValue(teamId, out matchTeam))
            {
                return;
            }

            lock (matchTeam)
            {
                if (matchTeam.State == MatchTeam.MatchTeamState.INBATTLE)
                {
                    Log.Info("玩家掉线,重连超时,退出队伍  TeamId" + matchTeam.Id + "Team State = " + matchTeam.State);
                    OnExitMatchTeam(teamId, playerId);
                    return;
                }
                //匹配队列正在匹配,需要将队伍从匹配队列中删除
                if (matchTeam.State == MatchTeam.MatchTeamState.Matching)
                {
                    Log.Info("玩家掉线,重连超时,退出队伍  TeamId" + matchTeam.Id + "Team State = " + matchTeam.State);

                    OnExitMatchTeam(teamId, playerId);
                    return;
                }
                //最简单的退出 直接交给退出队伍执行
                if (matchTeam.State == MatchTeam.MatchTeamState.OPEN)
                {
                    Log.Info("玩家掉线,重连超时,退出队伍  TeamId" + matchTeam.Id + "Team State = " + matchTeam.State);
                    OnExitMatchTeam(teamId, playerId);
                    return;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 以下要处理收到的消息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override Task OnMessage(ILocalMessage msg)
        {
            switch (msg.MessageId)
            {
            case GameServerConstDefine.MatchSystemCreateMatchTeam:
                CreateMatchTeamMessage createMatchTeamMessage = msg as CreateMatchTeamMessage;
                OnCreateMatchTeam(createMatchTeamMessage.playerId);
                break;

            case GameServerConstDefine.MatchSystemJoinMatchTeam:
                JoinMatchTeamMessage joinMatchTeamMessage = msg as JoinMatchTeamMessage;
                OnJoinMatchTeam(joinMatchTeamMessage.teamId, joinMatchTeamMessage.playerId);
                break;

            case GameServerConstDefine.MatchSystemExitMatchTeam:
                ExitMatchTeamMessage exitMatchTeamMessage = msg as ExitMatchTeamMessage;
                OnExitMatchTeam(exitMatchTeamMessage.teamId, exitMatchTeamMessage.playerId);
                break;

            case GameServerConstDefine.MatchSystemJoinMatchQueue:
                JoinMatchQueueMessage joinMatchQueueMessage = msg as JoinMatchQueueMessage;
                OnJoinMatchQueue(joinMatchQueueMessage.teamId, joinMatchQueueMessage.playerId, joinMatchQueueMessage.barrierId);
                break;

            case GameServerConstDefine.MatchSystemExitMatchQueue:
                ExitMatchQueueMessage exitMatchQueueMessage = msg as ExitMatchQueueMessage;
                OnExitMatchQueue(exitMatchQueueMessage.teamId, exitMatchQueueMessage.playerId);
                break;

            case GameServerConstDefine.MatchQueueCompleteSingle:    //来自 MatcingSystemQueue 的消息,通知system匹配完成
                MatchQueueCompleteSingleMessage matchQueueCompleteSingleMessage = msg as MatchQueueCompleteSingleMessage;
                OnCompleteMatching(matchQueueCompleteSingleMessage.teamIds, matchQueueCompleteSingleMessage.barrierId);
                break;

            case GameServerConstDefine.MatchSysteamMatchTeamUpdateInfo:
                MatchTeamUpdateInfoMessage matchTeamUpdateInfoMessage = msg as MatchTeamUpdateInfoMessage;
                OnUpdateMatchTeam(matchTeamUpdateInfoMessage.teamId);
                break;

            case GameServerConstDefine.MatchSystemPlayerShutdown:
                ToMatchPlayerShutdownMessage toMatchPlayerShutdownMessage = msg as ToMatchPlayerShutdownMessage;
                OnShutdownPlayer(toMatchPlayerShutdownMessage);
                break;

            case GameServerConstDefine.UpdateOnlinePlayerList:    //更新客户端在线玩家状态
                UpdateOnlinePlayerMessage updateOnlinePlayerMessage = msg as UpdateOnlinePlayerMessage;
                OnUpdateOnlinePlayerRpc(updateOnlinePlayerMessage);
                break;

            case GameServerConstDefine.ReleaseBattleToMatchTeam:
                ReleaseBattleToMatchTeamMessage releaseBattleToMatchTeamMessage = msg as ReleaseBattleToMatchTeamMessage;
                OnReleaseBattle(releaseBattleToMatchTeamMessage);
                break;

            default:
                break;
            }


            return(base.OnMessage(msg));
        }