コード例 #1
0
        public static void JoinGame(GameServerItem server)
        {
            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Join);
            if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION)
            {
                var sb = new StringBuilder();
                sb.AppendFormat(MyTexts.GetString(MyCommonTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion);
                MyGuiSandbox.Show(sb, MyCommonTexts.MessageBoxCaptionError);
                return;
            }
            if (MyFakes.ENABLE_MP_DATA_HASHES)
            {
                var serverHash = server.GetGameTagByPrefix("datahash");
                if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64())
                {
                    MyGuiSandbox.Show(MyCommonTexts.MultiplayerError_DifferentData);
                    MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + serverHash);
                    return;
                }
            }

            UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            SteamAPI.Instance.AddFavoriteGame(server.AppID, System.Net.IPAddressExtensions.ToIPv4NetworkOrder(server.NetAdr.Address), (UInt16)server.NetAdr.Port, (UInt16)server.NetAdr.Port, FavoriteEnum.History, unixTimestamp);

            MyMultiplayerClient multiplayer = new MyMultiplayerClient(server, new MySyncLayer(new MyTransportLayer(MyMultiplayer.GameEventChannel)));

            MyMultiplayer.Static = multiplayer;
            MyMultiplayer.Static.SyncLayer.AutoRegisterGameEvents = false;
            MyMultiplayer.Static.SyncLayer.RegisterGameEvents();

            multiplayer.SendPlayerData(MySteam.UserName);

            string        gamemode = server.GetGameTagByPrefix("gamemode");
            StringBuilder text     = MyTexts.Get(MyCommonTexts.DialogTextJoiningWorld);

            MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel);

            MyGuiSandbox.AddScreen(progress);
            progress.ProgressCancelled += () =>
            {
                multiplayer.Dispose();
                MySessionLoader.UnloadAndExitToMenu();
                if (MyMultiplayer.Static != null)
                {
                    MyMultiplayer.Static.Dispose();
                }
            };

            multiplayer.OnJoin += delegate
            {
                MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo()
                {
                    EnterState = LobbyEnterResponseEnum.Success
                }, multiplayer);
            };

            VRage.Profiler.MyRenderProfiler.GetProfilerFromServer = MyMultiplayer.Static.DownloadProfiler;
        }
コード例 #2
0
        private void AddServerItem(GameServerItem server, string sessionName, StringBuilder gamemodeSB, StringBuilder gamemodeToolTipSB)
        {
            ulong modCount = server.GetGameTagByPrefixUlong(MyMultiplayer.ModCountTag);

            string        limit     = server.MaxPlayers.ToString();
            StringBuilder userCount = new StringBuilder(server.Players + "/" + limit);

            var viewDistance = server.GetGameTagByPrefix(MyMultiplayer.ViewDistanceTag);

            //TODO: refactor
            if (!String.IsNullOrEmpty(viewDistance) && server.AppID == 244850)
            {
                gamemodeToolTipSB.AppendLine();
                gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_ViewDistance).ToString(), viewDistance);
            }

            var row = new MyGuiControlTable.Row(server);

            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(sessionName), userData: server.SteamID, toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: gamemodeSB, toolTip: gamemodeToolTipSB.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Name), toolTip: m_gameTypeToolTip.Clear().AppendLine(server.Name).Append(server.NetAdr.ToString()).ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: userCount, toolTip: userCount.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Ping), toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(modCount == 0 ? "---" : modCount.ToString()), toolTip: MyTexts.GetString(MySpaceTexts.JoinGame_SelectServerToShowModList)));
            m_gamesTable.Add(row);

            var selectedRow = m_gamesTable.SelectedRow;

            m_gamesTable.Sort(false);

            m_gamesTable.SelectedRowIndex = m_gamesTable.FindRow(selectedRow);
        }
コード例 #3
0
        bool AddServerItem(GameServerItem server, Action onAddedServerItem, bool isFiltered = false)
        {
            if (m_allowedGroups.IsChecked && !SteamAPI.Instance.Friends.IsUserInGroup(server.GetGameTagByPrefixUlong("groupId")))
            {
                return(false);
            }

            if (server.AppID != MySteam.AppId)
            {
                return(false);
            }

            if (!isFiltered && !string.IsNullOrWhiteSpace(m_blockSearch.Text)) // this must be here for filtering LAN games
            {
                if (!server.Name.ToLower().Contains(m_blockSearch.Text.ToLower()))
                {
                    return(false);
                }
            }

            string sessionName = server.Map;
            int    appVersion  = server.ServerVersion;

            m_gameTypeText.Clear();
            m_gameTypeToolTip.Clear();

            // Skip world without name (not fully initialized)
            if (string.IsNullOrEmpty(sessionName))
            {
                return(false);
            }

            // Show only same app versions
            if (m_showOnlyCompatibleGames.IsChecked && appVersion != MyFinalBuildConstants.APP_VERSION)
            {
                return(false);
            }

            // Show only if the game data match
            string remoteHash = server.GetGameTagByPrefix("datahash");

            if (m_showOnlyWithSameMods.IsChecked && MyFakes.ENABLE_MP_DATA_HASHES && remoteHash != "" && remoteHash != MyDataIntegrityChecker.GetHashBase64())
            {
                return(false);
            }

            var gamemodeSB        = new StringBuilder();
            var gamemodeToolTipSB = new StringBuilder();

            string gamemode = server.GetGameTagByPrefix("gamemode");

            if (gamemode == "C")
            {
                gamemodeSB.Append(MyTexts.Get(MyCommonTexts.WorldSettings_GameModeCreative));
                gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MyCommonTexts.WorldSettings_GameModeCreative));
            }
            else if (gamemode == "B")
            {
                IPEndPoint endpoint = server.NetAdr;
                if (endpoint == null)
                {
                    return(false);
                }

                // Started battle write key value "BattleCanBeJoinedTag" "0" to server which can be accessed asynchronously from rules.
                MySandboxGame.Services.SteamService.SteamAPI.GetServerRules(endpoint.Address.ToIPv4NetworkOrder(), (ushort)endpoint.Port, delegate(Dictionary <string, string> rules)
                {
                    if (rules == null)
                    {
                        return;
                    }

                    bool canBeJoined = true;
                    string strCanBeJoined;
                    if (rules.TryGetValue(MyMultiplayer.BattleCanBeJoinedTag, out strCanBeJoined))
                    {
                        canBeJoined = strCanBeJoined != 0.ToString();
                    }

                    if (canBeJoined)
                    {
                        string remainingTimeText   = null;
                        float?remainingTimeSeconds = null;
                        if (MyFakes.ENABLE_JOIN_SCREEN_REMAINING_TIME && rules.TryGetValue(MyMultiplayer.BattleRemainingTimeTag, out remainingTimeText))
                        {
                            float remainingTime;
                            if (float.TryParse(remainingTimeText, NumberStyles.Float, CultureInfo.InvariantCulture, out remainingTime))
                            {
                                if (remainingTime >= 0f)
                                {
                                    remainingTimeSeconds = remainingTime;
                                    remainingTimeText    = null;
                                }
                                else if (remainingTime == -1f)
                                {
                                    remainingTimeText = MyTexts.Get(MyCommonTexts.JoinGame_Lobby).ToString();
                                }
                                else if (remainingTime == -2f)
                                {
                                    remainingTimeText = MyTexts.Get(MyCommonTexts.JoinGame_Waiting).ToString();
                                }
                            }
                        }

                        gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));
                        gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));

                        AddServerItem(server, sessionName, gamemodeSB, gamemodeToolTipSB, remainingTimeText: remainingTimeText, remainingTimeSeconds: remainingTimeSeconds);

                        if (onAddedServerItem != null)
                        {
                            onAddedServerItem();
                        }
                    }
                },
                                                                            delegate() { });

                return(false);
            }
            else if (!string.IsNullOrWhiteSpace(gamemode))
            {
                var multipliers = gamemode.Substring(1);
                var split       = multipliers.Split('-');
                //TODO: refactor
                if (split.Length == 3 && server.AppID == 244850)
                {
                    gamemodeSB.Append(MyTexts.Get(MyCommonTexts.WorldSettings_GameModeSurvival)).Append(" ").Append(multipliers);
                    gamemodeToolTipSB.AppendFormat(MyTexts.Get(MyCommonTexts.JoinGame_GameTypeToolTip_MultipliersFormat).ToString(), split[0], split[1], split[2]);
                }
                else
                {
                    gamemodeSB.Append(MyTexts.Get(MyCommonTexts.WorldSettings_GameModeSurvival));
                    gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MyCommonTexts.WorldSettings_GameModeSurvival));
                }
            }

            AddServerItem(server, sessionName, gamemodeSB, gamemodeToolTipSB);

            if (onAddedServerItem != null)
            {
                onAddedServerItem();
            }

            return(true);
        }
コード例 #4
0
        private void AddServerItem(GameServerItem server, string sessionName, StringBuilder gamemodeSB, StringBuilder gamemodeToolTipSB)
        {
            ulong modCount = server.GetGameTagByPrefixUlong(MyMultiplayer.ModCountTag);

            string limit = server.MaxPlayers.ToString();
            StringBuilder userCount = new StringBuilder(server.Players + "/" + limit);

            var viewDistance = server.GetGameTagByPrefix(MyMultiplayer.ViewDistanceTag);
            //TODO: refactor
            if (!String.IsNullOrEmpty(viewDistance) && server.AppID == 244850)
            {
                gamemodeToolTipSB.AppendLine();
                gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_ViewDistance).ToString(), viewDistance);
            }

            var row = new MyGuiControlTable.Row(server);
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(sessionName), userData: server.SteamID, toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: gamemodeSB, toolTip: gamemodeToolTipSB.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Name), toolTip: m_gameTypeToolTip.Clear().AppendLine(server.Name).Append(server.NetAdr.ToString()).ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: userCount, toolTip: userCount.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Ping), toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(modCount == 0 ? "---" : modCount.ToString()), toolTip: MyTexts.GetString(MySpaceTexts.JoinGame_SelectServerToShowModList)));
            m_gamesTable.Add(row);

            var selectedRow = m_gamesTable.SelectedRow;
            m_gamesTable.Sort(false);

            m_gamesTable.SelectedRowIndex = m_gamesTable.FindRow(selectedRow);
        }
コード例 #5
0
        bool AddServerItem(GameServerItem server, Action onAddedServerItem, bool isFiltered = false)
        {
            if (m_allowedGroups.IsChecked && !SteamAPI.Instance.Friends.IsUserInGroup(server.GetGameTagByPrefixUlong("groupId")))
                return false;

            if (server.AppID != MySteam.AppId)
                return false;

            if (!isFiltered && !string.IsNullOrWhiteSpace(m_blockSearch.Text)) // this must be here for filtering LAN games
            {
                if (!server.Name.ToLower().Contains(m_blockSearch.Text.ToLower()))
                    return false;
            }

            string sessionName = server.Map;
            int appVersion = server.ServerVersion;
            m_gameTypeText.Clear();
            m_gameTypeToolTip.Clear();

            // Skip world without name (not fully initialized)
            if (string.IsNullOrEmpty(sessionName))
                return false;

            // Show only same app versions
            if (m_showOnlyCompatibleGames.IsChecked && appVersion != MyFinalBuildConstants.APP_VERSION)
                return false;
            
            // Show only if the game data match
            string remoteHash = server.GetGameTagByPrefix("datahash");
            if (m_showOnlyWithSameMods.IsChecked && MyFakes.ENABLE_MP_DATA_HASHES && remoteHash != "" && remoteHash != MyDataIntegrityChecker.GetHashBase64())
                return false;

            var gamemodeSB = new StringBuilder();
            var gamemodeToolTipSB = new StringBuilder();

            string gamemode = server.GetGameTagByPrefix("gamemode");
            if (gamemode == "C")
            {
                gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
                gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
            }
            else if (gamemode == "B")
            {
                IPEndPoint endpoint = server.NetAdr;
                if (endpoint == null)
                    return false;

                // Started battle write key value "BattleCanBeJoinedTag" "0" to server which can be accessed asynchronously from rules.
                MySandboxGame.Services.SteamService.SteamAPI.GetServerRules(endpoint.Address.ToIPv4NetworkOrder(), (ushort)endpoint.Port, delegate(Dictionary<string, string> rules)
                {
                    if (rules == null)
                        return;

                    bool canBeJoined = true;
                    string strCanBeJoined;
                    if (rules.TryGetValue(MyMultiplayer.BattleCanBeJoinedTag, out strCanBeJoined))
                    {
                        canBeJoined = strCanBeJoined != 0.ToString();
                    }

                    if (canBeJoined)
                    {
                        gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));
                        gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));

                        AddServerItem(server, sessionName, gamemodeSB, gamemodeToolTipSB);

                        if (onAddedServerItem != null)
                            onAddedServerItem();
                    }
                },
                delegate() { });

                return false;
            }
            else if(!string.IsNullOrWhiteSpace(gamemode))
            {
                var multipliers = gamemode.Substring(1);
                var split = multipliers.Split('-');
                //TODO: refactor
                if (split.Length == 3 && server.AppID == 244850)
                {
                    gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival)).Append(" ").Append(multipliers);
                    gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_MultipliersFormat).ToString(), split[0], split[1], split[2]);
                }
                else
                {
                    gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                    gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                }
            }

            AddServerItem(server, sessionName, gamemodeSB, gamemodeToolTipSB);

            if (onAddedServerItem != null)
                onAddedServerItem();

            return true;
        }
コード例 #6
0
        public static void JoinGame(GameServerItem server)
        {
            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Join);
            if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION)
            {
                var sb = new StringBuilder();
                sb.AppendFormat(MyTexts.GetString(MyCommonTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion);
                MyGuiSandbox.Show(sb, MyCommonTexts.MessageBoxCaptionError);
                return;
            }
            if (MyFakes.ENABLE_MP_DATA_HASHES)
            {
                var serverHash = server.GetGameTagByPrefix("datahash");
                if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64())
                {
                    MyGuiSandbox.Show(MyCommonTexts.MultiplayerError_DifferentData);
                    MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + serverHash);
                    return;
                }
            }

            UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            SteamAPI.Instance.AddFavoriteGame(server.AppID, System.Net.IPAddressExtensions.ToIPv4NetworkOrder(server.NetAdr.Address), (UInt16)server.NetAdr.Port, (UInt16)server.NetAdr.Port, FavoriteEnum.History, unixTimestamp);

            MyMultiplayerClient multiplayer = new MyMultiplayerClient(server, new MySyncLayer(new MyTransportLayer(MyMultiplayer.GameEventChannel)));
            MyMultiplayer.Static = multiplayer;
            MyMultiplayer.Static.SyncLayer.AutoRegisterGameEvents = false;
            MyMultiplayer.Static.SyncLayer.RegisterGameEvents();

            multiplayer.SendPlayerData(MySteam.UserName);

            string gamemode = server.GetGameTagByPrefix("gamemode");
            if (MyFakes.ENABLE_BATTLE_SYSTEM && gamemode == "B")
            {
                StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningBattle);

                MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel);
                MyGuiSandbox.AddScreen(progress);
                progress.ProgressCancelled += () =>
                {
                    multiplayer.Dispose();
                    MySessionLoader.UnloadAndExitToMenu();
                };

                multiplayer.OnJoin += delegate
                {
                    MyJoinGameHelper.OnJoinBattle(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer);
                };
            }
            else
            {
                StringBuilder text = MyTexts.Get(MyCommonTexts.DialogTextJoiningWorld);

                MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel);
                MyGuiSandbox.AddScreen(progress);
                progress.ProgressCancelled += () =>
                {
                    multiplayer.Dispose();
                    if (MyMultiplayer.Static != null)
                    {
                        MyMultiplayer.Static.Dispose();
                    }
                };

                multiplayer.OnJoin += delegate
                {
                    MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer);
                };
            }
        }
コード例 #7
0
        bool AddServerItem(GameServerItem server, bool isFiltered = false)
        {
            if (m_allowedGroups.IsChecked && !SteamAPI.Instance.Friends.IsUserInGroup(server.GetGameTagByPrefixUlong("groupId")))
                return false;

            if (server.AppID != MySteam.AppId)
                return false;

            if (!isFiltered && !string.IsNullOrWhiteSpace(m_blockSearch.Text)) // this must be here for filtering LAN games
            {
                if (!server.Name.ToLower().Contains(m_blockSearch.Text.ToLower()))
                    return false;
            }

            var row = new MyGuiControlTable.Row(server);

            string sessionName = server.Map;
            int appVersion = server.ServerVersion;
            m_gameTypeText.Clear();
            m_gameTypeToolTip.Clear();

            // Skip world without name (not fully initialized)
            if (string.IsNullOrEmpty(sessionName))
                return false;

            // Show only same app versions
            if (m_showOnlyCompatibleGames.IsChecked && appVersion != MyFinalBuildConstants.APP_VERSION)
                return false;
            
            // Show only if the game data match
            string remoteHash = server.GetGameTagByPrefix("datahash");
            if (m_showOnlyWithSameMods.IsChecked && MyFakes.ENABLE_MP_DATA_HASHES && remoteHash != "" && remoteHash != MyDataIntegrityChecker.GetHashBase64())
                return false;

            var gamemodeSB = new StringBuilder();
            var gamemodeToolTipSB = new StringBuilder();

            string gamemode = server.GetGameTagByPrefix("gamemode");
            if (gamemode == "C")
            {
                gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
                gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
            }
            else if(!string.IsNullOrWhiteSpace(gamemode))
            {
                var multipliers = gamemode.Substring(1);
                var split = multipliers.Split('-');
                //TODO: refactor
                if (split.Length == 3 && server.AppID == 244850)
                {
                    gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival)).Append(" ").Append(multipliers);
                    gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_MultipliersFormat).ToString(), split[0], split[1], split[2]);
                }
                else
                {
                    gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                    gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                }
            }

            ulong modCount = server.GetGameTagByPrefixUlong(MyMultiplayer.ModCountTag);

            string limit = server.MaxPlayers.ToString();
            StringBuilder userCount = new StringBuilder(server.Players + "/" + limit);

            var viewDistance = server.GetGameTagByPrefix(MyMultiplayer.ViewDistanceTag);
            //TODO: refactor
            if (!String.IsNullOrEmpty(viewDistance) && server.AppID == 244850)
            {
                gamemodeToolTipSB.AppendLine();
                gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_ViewDistance).ToString(), viewDistance);
            }

            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(sessionName), userData: server.SteamID, toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: gamemodeSB, toolTip: gamemodeToolTipSB.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Name), toolTip: m_gameTypeToolTip.Clear().AppendLine(server.Name).Append(server.NetAdr.ToString()).ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: userCount, toolTip: userCount.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Ping), toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(modCount == 0 ? "---" : modCount.ToString()), toolTip: MyTexts.GetString(MySpaceTexts.JoinGame_SelectServerToShowModList)));
            m_gamesTable.Add(row);
            
            var selectedRow = m_gamesTable.SelectedRow;
            m_gamesTable.Sort(false);

            m_gamesTable.SelectedRowIndex = m_gamesTable.FindRow(selectedRow);

            return true;
        }
コード例 #8
0
        bool AddServerItem(GameServerItem server, bool isFiltered = false)
        {
            if (m_allowedGroups.IsChecked && !SteamAPI.Instance.Friends.IsUserInGroup(server.GetGameTagByPrefixUlong("groupId")))
            {
                return(false);
            }

            if (server.AppID != MySteam.AppId)
            {
                return(false);
            }

            if (!isFiltered && !string.IsNullOrWhiteSpace(m_blockSearch.Text)) // this must be here for filtering LAN games
            {
                if (!server.Name.ToLower().Contains(m_blockSearch.Text.ToLower()))
                {
                    return(false);
                }
            }

            var row = new MyGuiControlTable.Row(server);

            string sessionName = server.Map;
            int    appVersion  = server.ServerVersion;

            m_gameTypeText.Clear();
            m_gameTypeToolTip.Clear();

            // Skip world without name (not fully initialized)
            if (string.IsNullOrEmpty(sessionName))
            {
                return(false);
            }

            // Show only same app versions
            if (m_showOnlyCompatibleGames.IsChecked && appVersion != MyFinalBuildConstants.APP_VERSION)
            {
                return(false);
            }

            // Show only if the game data match
            string remoteHash = server.GetGameTagByPrefix("datahash");

            if (m_showOnlyWithSameMods.IsChecked && MyFakes.ENABLE_MP_DATA_HASHES && remoteHash != "" && remoteHash != MyDataIntegrityChecker.GetHashBase64())
            {
                return(false);
            }

            var gamemodeSB        = new StringBuilder();
            var gamemodeToolTipSB = new StringBuilder();

            string gamemode = server.GetGameTagByPrefix("gamemode");

            if (gamemode == "C")
            {
                gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
                gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
            }
            else if (gamemode == "B")
            {
                gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));
                gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));
            }
            else if (!string.IsNullOrWhiteSpace(gamemode))
            {
                var multipliers = gamemode.Substring(1);
                var split       = multipliers.Split('-');
                //TODO: refactor
                if (split.Length == 3 && server.AppID == 244850)
                {
                    gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival)).Append(" ").Append(multipliers);
                    gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_MultipliersFormat).ToString(), split[0], split[1], split[2]);
                }
                else
                {
                    gamemodeSB.Append(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                    gamemodeToolTipSB.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                }
            }

            ulong modCount = server.GetGameTagByPrefixUlong(MyMultiplayer.ModCountTag);

            string        limit     = server.MaxPlayers.ToString();
            StringBuilder userCount = new StringBuilder(server.Players + "/" + limit);

            var viewDistance = server.GetGameTagByPrefix(MyMultiplayer.ViewDistanceTag);

            //TODO: refactor
            if (!String.IsNullOrEmpty(viewDistance) && server.AppID == 244850)
            {
                gamemodeToolTipSB.AppendLine();
                gamemodeToolTipSB.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_ViewDistance).ToString(), viewDistance);
            }

            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(sessionName), userData: server.SteamID, toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: gamemodeSB, toolTip: gamemodeToolTipSB.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Name), toolTip: m_gameTypeToolTip.Clear().AppendLine(server.Name).Append(server.NetAdr.ToString()).ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: userCount, toolTip: userCount.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(server.Ping), toolTip: m_textCache.ToString()));
            row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(modCount == 0 ? "---" : modCount.ToString()), toolTip: MyTexts.GetString(MySpaceTexts.JoinGame_SelectServerToShowModList)));
            m_gamesTable.Add(row);

            var selectedRow = m_gamesTable.SelectedRow;

            m_gamesTable.Sort(false);

            m_gamesTable.SelectedRowIndex = m_gamesTable.FindRow(selectedRow);

            return(true);
        }