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); }
public static void SendUser( long match_type, string account_id, JObject user_data, DedicatedServerHelper.SendUserCallback send_callback) { Log.Assert(MatchmakingType.IsValidMatchType(match_type)); bool found = false; Guid target_match_id; JObject target_match_data = new JObject(); // 매치 타입과 일치하는 플레이어 수를 선택합니다. long total_players_for_match = MatchmakingType.GetNumberOfMaxPlayers(match_type); do { lock (match_lock) { // 현재 활성화된 매치를 검사하여 플레이어가 부족한 서버를 찾습니다. // 순서는 UUID 를 따르므로 별다른 우선 순위가 없습니다. // 조금 더 공정한 절차가 필요하다면 MyMatchInfo 에 모든 플레이어 없이 게임을 진행한 // 시간을 기록한 후, 이를 기준으로 우선순위를 부여할 수 있습니다. // // 1. 먼저 매치 타입으로 매치 ID 맵을 가져옵니다. if (!match_type_map.ContainsKey(match_type)) { break; } // 2. ID 에 해당하는 매치 목록을 순회하면서 필요한 플레이어보다 부족한 // 서버를 찾습니다. foreach (Guid match_id in match_type_map[match_type]) { Log.Assert(match_map.ContainsKey(match_id)); MyMatchInfo info = match_map[match_id]; if (info.players.Count < total_players_for_match) { // 서버를 찾았습니다. target_match_id = info.match_id; target_match_data = info.match_data; found = true; break; } } } }while (false); if (!found) { // 모든 서버가 매치에 필요한 플레이어를 확보했거나 서버가 없습니다. // 더 이상 진행할 수 없습니다. Log.Info("There's no available server to send user"); send_callback(false); } else { // 난입을 요청합니다. List <string> account_ids = new List <string> { account_id }; List <JObject> user_data_list = new List <JObject> { user_data }; DedicatedServerManager.SendCallback send_cb = new DedicatedServerManager.SendCallback( (Guid match_id2, List <string> users2, bool success2) => { OnUserSent(match_id2, users2, success2, target_match_data, match_type, send_callback); }); DedicatedServerManager.SendUsers( target_match_id, target_match_data, account_ids, user_data_list, send_cb); } }