private static bool JoinGameTest(Lobby lobby) { if (!lobby.IsValid) { return(false); } if (lobby.GetLobbyType() == LobbyTypeEnum.FriendsOnly && !MySteam.API.Friends.HasFriend(lobby.GetOwner())) { MyGuiSandbox.Show(MySpaceTexts.OnlyFriendsCanJoinThisGame); return(false); } if (!MyMultiplayerLobby.IsLobbyCorrectVersion(lobby)) { var formatString = MyTexts.GetString(MySpaceTexts.MultiplayerError_IncorrectVersion); var myVersion = MyBuildNumbers.ConvertBuildNumberFromIntToString(MyFinalBuildConstants.APP_VERSION); var serverVersion = MyBuildNumbers.ConvertBuildNumberFromIntToString(MyMultiplayerLobby.GetLobbyAppVersion(lobby)); MyGuiSandbox.Show(new StringBuilder(String.Format(formatString, myVersion, serverVersion))); return(false); } if (MyFakes.ENABLE_MP_DATA_HASHES && !MyMultiplayerLobby.HasSameData(lobby)) { MyGuiSandbox.Show(MySpaceTexts.MultiplayerError_DifferentData); MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + MyMultiplayerLobby.GetDataHash(lobby)); return(false); } return(true); }
public static void JoinGame(Lobby lobby, bool requestData = true) { // Data not received if (requestData && String.IsNullOrEmpty(lobby.GetLobbyData(MyMultiplayer.AppVersionTag))) { var helper = new MyLobbyHelper(lobby); helper.OnSuccess += (l) => JoinGame(l, false); if (helper.RequestData()) { return; } } if (!JoinGameTest(lobby)) { return; } if (MyMultiplayerLobby.GetLobbyScenario(lobby)) { MyJoinGameHelper.JoinScenarioGame(lobby.LobbyId); } else { JoinGame(lobby.LobbyId); } }
internal static void SetLobbyTypeFromOnlineMode(MyOnlineModeEnum onlineMode) { MyMultiplayerLobby lobby = MyMultiplayer.Static as MyMultiplayerLobby; if (lobby == null) { Debug.Fail("Multiplayer lobby not found"); return; } LobbyTypeEnum lobbyType = LobbyTypeEnum.Private; switch (onlineMode) { case MyOnlineModeEnum.FRIENDS: lobbyType = LobbyTypeEnum.FriendsOnly; break; case MyOnlineModeEnum.PUBLIC: lobbyType = LobbyTypeEnum.Public; break; } lobby.SetLobbyType(lobbyType); }
private void JoinSelectedLobby() { var selectedRow = m_gamesTable.SelectedRow; if (selectedRow == null) { return; } Lobby selectedLobby = (Lobby)selectedRow.UserData; bool isBattle = MyMultiplayerLobby.GetLobbyBattle(selectedLobby); if (MyFakes.ENABLE_BATTLE_SYSTEM && isBattle) { MyJoinGameHelper.JoinBattleGame(selectedLobby); } else { MyJoinGameHelper.JoinGame(selectedLobby); } }
internal static MyOnlineModeEnum GetOnlineModeFromCurrentLobbyType() { MyMultiplayerLobby lobby = MyMultiplayer.Static as MyMultiplayerLobby; if (lobby == null) { Debug.Fail("Multiplayer lobby not found"); return MyOnlineModeEnum.PRIVATE; } switch (lobby.GetLobbyType()) { case LobbyTypeEnum.Private: return MyOnlineModeEnum.PRIVATE; case LobbyTypeEnum.FriendsOnly: return MyOnlineModeEnum.FRIENDS; case LobbyTypeEnum.Public: return MyOnlineModeEnum.PUBLIC; } return MyOnlineModeEnum.PRIVATE; }
private static void LobbiesRequestCompleted(Result result) { // if the request is ok if (result != Result.OK) { return; } var lobbies = new List <Lobby>(); // Add all lobbies LobbySearch.AddPublicLobbies(lobbies); LobbySearch.AddFriendLobbies(lobbies); // search for new lobby foreach (var lobby in lobbies) { var owner = MyMultiplayerLobby.GetLobbyHostSteamId(lobby); if (owner == m_ownerId && lobby.LobbyId != m_oldLobbyId) { // MyScreenManager.RemoveScreenByType(typeof(MyGuiScreenProgress)); // Join the game MyJoinGameHelper.JoinGame(lobby); return; } } // Exit if the search is taking too long m_elapsedMs += 5000; if (m_elapsedMs > 120000) { // Remove the progress wheel MyScreenManager.RemoveScreenByType(typeof(MyGuiScreenProgress)); return; } // Repeat the search FindLobby(); }
public static void JoinGame(Lobby lobby, bool requestData = true) { // Data not received if (requestData && String.IsNullOrEmpty(lobby.GetLobbyData(MyMultiplayer.AppVersionTag))) { var helper = new MyLobbyHelper(lobby); helper.OnSuccess += (l) => JoinGame(l, false); if (helper.RequestData()) { return; } } if (!JoinGameTest(lobby)) { return; } if (MyMultiplayerLobby.GetLobbyScenario(lobby)) { MyJoinGameHelper.JoinScenarioGame(lobby.LobbyId); } else if (MyFakes.ENABLE_BATTLE_SYSTEM && MyMultiplayerLobby.GetLobbyBattle(lobby)) { bool canBeJoined = MyMultiplayerLobby.GetLobbyBattleCanBeJoined(lobby); // Check also valid faction ids in battle lobby. long faction1Id = MyMultiplayerLobby.GetLobbyBattleFaction1Id(lobby); long faction2Id = MyMultiplayerLobby.GetLobbyBattleFaction2Id(lobby); if (canBeJoined && faction1Id != 0 && faction2Id != 0) { MyJoinGameHelper.JoinBattleGame(lobby.LobbyId); } } else { JoinGame(lobby.LobbyId); } }
private void RefreshGameList() { m_gamesTable.Clear(); AddHeaders(); m_textCache.Clear(); m_gameTypeText.Clear(); m_gameTypeToolTip.Clear(); m_lobbyPage.Text = MyTexts.Get(MySpaceTexts.JoinGame_TabTitle_Lobbies); if (m_lobbies != null) { int shownGames = 0; for (int i = 0; i < m_lobbies.Count; ++i) { var lobby = m_lobbies[i]; var row = new MyGuiControlTable.Row(lobby); string sessionName = MyMultiplayerLobby.GetLobbyWorldName(lobby); ulong sessionSize = MyMultiplayerLobby.GetLobbyWorldSize(lobby); int appVersion = MyMultiplayerLobby.GetLobbyAppVersion(lobby); int modCount = MyMultiplayerLobby.GetLobbyModCount(lobby); var searchName = m_blockSearch.Text.Trim(); if (!string.IsNullOrWhiteSpace(searchName) && !sessionName.ToLower().Contains(searchName.ToLower())) { continue; } m_gameTypeText.Clear(); m_gameTypeToolTip.Clear(); //TODO: refactor - split to ME a SE versions if (appVersion > 01022000 && MySteam.AppId == 244850) { var inventory = MyMultiplayerLobby.GetLobbyFloat(MyMultiplayer.InventoryMultiplierTag, lobby, 1); var refinery = MyMultiplayerLobby.GetLobbyFloat(MyMultiplayer.RefineryMultiplierTag, lobby, 1); var assembler = MyMultiplayerLobby.GetLobbyFloat(MyMultiplayer.AssemblerMultiplierTag, lobby, 1); MyGameModeEnum gameMode = MyMultiplayerLobby.GetLobbyGameMode(lobby); if (MyMultiplayerLobby.GetLobbyScenario(lobby)) { m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameScenario)); DateTime started = MyMultiplayerLobby.GetLobbyDateTime(MyMultiplayer.ScenarioStartTimeTag, lobby, DateTime.MinValue); if (started > DateTime.MinValue) { TimeSpan timeRunning = DateTime.UtcNow - started; var hrs = Math.Truncate(timeRunning.TotalHours); int mins = (int)((timeRunning.TotalHours - hrs) * 60); m_gameTypeText.Append(" ").Append(hrs).Append(":").Append(mins.ToString("D2")); } else { m_gameTypeText.Append(" Lobby"); } } else { switch (gameMode) { case MyGameModeEnum.Creative: m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative)); break; case MyGameModeEnum.Survival: m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival)); m_gameTypeText.Append(String.Format(" {0}-{1}-{2}", inventory, assembler, refinery)); break; default: Debug.Fail("Unknown game type"); break; } } m_gameTypeToolTip.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_MultipliersFormat).ToString(), inventory, assembler, refinery); var viewDistance = MyMultiplayerLobby.GetLobbyViewDistance(lobby); m_gameTypeToolTip.AppendLine(); m_gameTypeToolTip.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_ViewDistance).ToString(), viewDistance); } else { MyGameModeEnum gameMode = MyMultiplayerLobby.GetLobbyGameMode(lobby); switch (gameMode) { case MyGameModeEnum.Creative: m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative)); m_gameTypeToolTip.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative)); break; case MyGameModeEnum.Survival: bool isBattle = MyMultiplayerLobby.GetLobbyBattle(lobby); if (MyFakes.ENABLE_BATTLE_SYSTEM && isBattle) { // Cannot join already started battles bool battleCanBeJoined = MyMultiplayerLobby.GetLobbyBattleCanBeJoined(lobby); if (!battleCanBeJoined) { continue; } m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_Battle)); m_gameTypeToolTip.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_Battle)); } else { m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival)); m_gameTypeToolTip.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival)); } break; default: Debug.Fail("Unknown game type"); break; } } // Skip world without name (not fully initialized) if (string.IsNullOrEmpty(sessionName)) { continue; } // Show only same app versions if (m_showOnlyCompatibleGames.IsChecked && appVersion != MyFinalBuildConstants.APP_VERSION) { continue; } // Show only if the game data match if (m_showOnlyWithSameMods.IsChecked && MyFakes.ENABLE_MP_DATA_HASHES && !MyMultiplayerLobby.HasSameData(lobby)) { continue; } float sessionFormattedSize = (float)sessionSize; string owner = MyMultiplayerLobby.GetLobbyHostName(lobby); string limit = lobby.MemberLimit.ToString(); string userCount = lobby.MemberCount + "/" + limit; var prefixSize = MyUtils.FormatByteSizePrefix(ref sessionFormattedSize); var modListToolTip = new StringBuilder(); int displayedModsMax = 15; int lastMod = Math.Min(displayedModsMax, modCount - 1); foreach (var mod in MyMultiplayerLobby.GetLobbyMods(lobby)) { if (displayedModsMax-- <= 0) { modListToolTip.Append("..."); break; } if (lastMod-- <= 0) { modListToolTip.Append(mod.FriendlyName); } else { modListToolTip.AppendLine(mod.FriendlyName); } } //row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(MyMultiplayerLobby.HasSameData(lobby) ? "" : "*"))); row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(sessionName), userData: lobby.LobbyId, toolTip: m_textCache.ToString())); row.AddCell(new MyGuiControlTable.Cell(text: m_gameTypeText, toolTip: (m_gameTypeToolTip.Length > 0) ? m_gameTypeToolTip.ToString() : null)); row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(sessionFormattedSize.ToString("0.") + prefixSize + "B "))); row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(owner), toolTip: m_textCache.ToString())); row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(userCount))); row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(modCount == 0 ? "---" : modCount.ToString()), toolTip: modListToolTip.ToString())); m_gamesTable.Add(row); shownGames++; } m_lobbyPage.Text = new StringBuilder().Append(MyTexts.Get(MySpaceTexts.JoinGame_TabTitle_Lobbies).ToString()).Append(" (").Append(shownGames).Append(")"); } //m_gameDataLabel.Visible = m_incompatibleGameData; m_gamesTable.SelectedRowIndex = null; }