Exemplo n.º 1
0
        internal void SendGameTagsToSteam()
        {
            if (SteamSDK.SteamServerAPI.Instance != null)
            {
                var serverName = MySandboxGame.ConfigDedicated.ServerName.Replace(":", "a58").Replace(";", "a59");

                var gamemode = new StringBuilder();

                switch (GameMode)
                {
                case MyGameModeEnum.Survival:
                    gamemode.Append(String.Format("S{0}-{1}-{2}", (int)InventoryMultiplier, (int)AssemblerMultiplier, (int)RefineryMultiplier));
                    break;

                case MyGameModeEnum.Creative:
                    gamemode.Append("C");
                    break;

                default:
                    Debug.Fail("Unknown game type");
                    break;
                }

                SteamSDK.SteamServerAPI.Instance.GameServer.SetGameTags(
                    "groupId" + m_groupId.ToString() +
                    " version" + MyFinalBuildConstants.APP_VERSION.ToString() +
                    " datahash" + MyDataIntegrityChecker.GetHashBase64() +
                    " " + MyMultiplayer.ModCountTag + ModCount +
                    " gamemode" + gamemode +
                    " " + MyMultiplayer.ViewDistanceTag + ViewDistance);
            }
        }
Exemplo n.º 2
0
 internal override void SendGameTagsToSteam()
 {
     if (MyGameService.GameServer != null)
     {
         StringBuilder  builder  = new StringBuilder();
         MyGameModeEnum gameMode = this.GameMode;
         if (gameMode == MyGameModeEnum.Creative)
         {
             builder.Append("C");
         }
         else if (gameMode == MyGameModeEnum.Survival)
         {
             builder.Append($"S{(int) this.InventoryMultiplier}-{(int) this.BlocksInventoryMultiplier}-{(int) this.AssemblerMultiplier}-{(int) this.RefineryMultiplier}");
         }
         object[] objArray2 = new object[12];
         objArray2[0]  = "groupId";
         objArray2[1]  = base.m_groupId;
         objArray2[2]  = " version";
         objArray2[3]  = MyFinalBuildConstants.APP_VERSION;
         objArray2[4]  = " datahash";
         objArray2[5]  = MyDataIntegrityChecker.GetHashBase64();
         objArray2[6]  = " mods";
         objArray2[7]  = this.ModCount;
         objArray2[8]  = " gamemode";
         objArray2[9]  = builder;
         objArray2[10] = " view";
         objArray2[11] = this.SyncDistance;
         string tags = string.Concat(objArray2);
         MyGameService.GameServer.SetGameTags(tags);
         MyGameService.GameServer.SetGameData(MyFinalBuildConstants.APP_VERSION.ToString());
     }
 }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        public static bool HasSameData(Lobby lobby)
        {
            string remoteHash = GetDataHash(lobby);

            // If the data hash is not set, the server does not want to check the data consistency
            if (remoteHash == "")
            {
                return(true);
            }

            if (remoteHash == MyDataIntegrityChecker.GetHashBase64())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        internal override void SendGameTagsToSteam()
        {
            if (SteamSDK.SteamServerAPI.Instance != null)
            {
                var serverName = MySandboxGame.ConfigDedicated.ServerName.Replace(":", "a58").Replace(";", "a59");

                Debug.Assert(GameMode == MyGameModeEnum.Survival);

                var gamemode = new StringBuilder();
                gamemode.Append("B");

                SteamSDK.SteamServerAPI.Instance.GameServer.SetGameTags(
                    "groupId" + m_groupId.ToString() +
                    " version" + MyFinalBuildConstants.APP_VERSION.ToString() +
                    " datahash" + MyDataIntegrityChecker.GetHashBase64() +
                    " " + MyMultiplayer.ModCountTag + ModCount +
                    " gamemode" + gamemode +
                    " " + MyMultiplayer.ViewDistanceTag + ViewDistance);
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public static bool HasSameData(IMyLobby lobby)
        {
            string dataHash = GetDataHash(lobby);

            return((dataHash != "") ? (dataHash == MyDataIntegrityChecker.GetHashBase64()) : true);
        }
Exemplo n.º 9
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);
        }