static void SpawnOrSendUser(string account_id,
                                    JObject user_data,
                                    long match_type)
        {
            Log.Assert(match_type == (long)MatchmakingType.MatchType.kNoMatching);

            // 1. 사람이 없고 인원이 부족한 서버를 찾아 난입을 시도합니다.
            // 2. 난입에 실패한 경우 새 서버를 생성합니다.

            DedicatedServerHelper.SendUserCallback cb =
                new DedicatedServerHelper.SendUserCallback((bool succeed) => {
                // 난입에 실패했습니다. 새 서버를 생성합니다.
                // 재시도를 하거나, 실패처리할 수 있습니다.
                if (!succeed)
                {
                    Log.Info("Spawning a new dedicated server for: account_id={0}", account_id);
                    DedicatedServerHelper.SpawnDedicatedServer(account_id, user_data);
                    return;
                }

                // 매치 참여에 성공했습니다. 데디케이티드 서버 리다이렉션 메시지는 엔진 내부의
                // 서버 오케스트레이터에서 자동으로 보내기 때문에 처리할 필요가 없습니다.
                // 게임 로직에 따라서는 아래 메시지 전송이 불필요할 수 있습니다.
                // 이 예제에서는 단순히 클라이언트에게 매치 참여 완료 메시지만 전달합니다.
            });

            Log.Info("Trying to send user: account_id={0}", account_id);
            DedicatedServerHelper.SendUser(match_type, account_id, user_data, cb);
        }
        static funapi.Matchmaking.Server.MatchState CheckMatchRequirements(funapi.Matchmaking.Match match)
        {
            //
            // 매치 완료 조건 검사 핸들러 함수입니다.
            //

            long total_players_for_match = MatchmakingType.GetNumberOfMaxPlayers(match.MatchType);

            // 총 플레이어 수가 매치 완료 조건에 부합하는 지 검사합니다.
            if (match.Players.Count != total_players_for_match)
            {
                // 아직 더 많은 플레이어가 필요합니다.
                Log.Info("Waiting for more players: match_id={0}, match_type={1}, total_players_for_match={2}, current players={3}",
                         match.MatchId, match.MatchType, total_players_for_match, match.Players.Count);

                return(funapi.Matchmaking.Server.MatchState.kMatchNeedMorePlayer);
            }

            Log.Info("Matchmaking is done: match_id={0}, match_type={1}, total_players_for_match={2}, current players={3}",
                     match.MatchId, match.MatchType, total_players_for_match, match.Players.Count);

            // 매치메이킹이 끝났으니 이 정보를 토대로 데디케이티드 서버 생성을 요청합니다.
            DedicatedServerHelper.SpawnDedicatedServer(match);
            return(funapi.Matchmaking.Server.MatchState.kMatchComplete);
        }
Ejemplo n.º 3
0
        public static bool Install(ArgumentMap arguments)
        {
            // 세션 열림 및 닫힘 핸들러를 등록합니다.
            NetworkHandlerRegistry.RegisterSessionHandler(
                new NetworkHandlerRegistry.SessionOpenedHandler(OnSessionOpened),
                new NetworkHandlerRegistry.SessionClosedHandler(OnSessionClosed));
            // TCP 연결이 끊어졌을 때 호출할 핸들러를 등록합니다. 세션이 닫힌 건 아니므로
            // 언제든지 다른 트랜스포트를 통해 이 세션을 사용할 수 있습니다.
            // (WIFI -> LTE 이동과 같은 상황이 좋은 예입니다)
            NetworkHandlerRegistry.RegisterTcpTransportDetachedHandler(OnTcpTransportDetached);
            // 로그인 요청 핸들러를 등록합니다.
            NetworkHandlerRegistry.RegisterMessageHandler(
                kLoginMessage, new NetworkHandlerRegistry.JsonMessageHandler(OnLoginRequest));
            // 로그아웃 요청 핸들러를 등록합니다
            NetworkHandlerRegistry.RegisterMessageHandler(
                kLogoutMessage, new NetworkHandlerRegistry.JsonMessageHandler(OnLogoutRequest));
            // 매치메이킹 후 매치가 성사된 유저들을 모아 데디케이티드 서버를 스폰합니다.
            NetworkHandlerRegistry.RegisterMessageHandler(
                kMatchThenSpawnMessage, new NetworkHandlerRegistry.JsonMessageHandler(OnMatchThenSpawnRequest));
            // 매치메이킹 요청을 취소합니다.
            NetworkHandlerRegistry.RegisterMessageHandler(
                kCancelMatchMessage, new NetworkHandlerRegistry.JsonMessageHandler(OnCancelMatchRequest));

            // 데디케이티드 서버 생성이 완료된 클라이언트로
            // 스폰 결과에 대한 응답을 보낼 때 사용합니다.
            DedicatedServerHelper.Install(OnDedicatedServerSpawned);
            // 매치매이킹 서버가 내부적으로 쓰는 핸들러들을 등록합니다.
            MatchmakingServerWrapper.Install();

            return(true);
        }