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); }
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); } }
public void LoadParticlesLibrary(string file) { if (file.Contains(".mwl")) { MyParticlesLibrary.Deserialize(file); } else { MyDataIntegrityChecker.HashInFile(file); MyObjectBuilder_Definitions objectBuilder = null; MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_Definitions>(file, out objectBuilder); if ((objectBuilder != null) && (objectBuilder.ParticleEffects != null)) { MyParticlesLibrary.Close(); foreach (MyObjectBuilder_ParticleEffect effect in objectBuilder.ParticleEffects) { MyParticleEffect local1 = MyParticlesManager.EffectsPool.Allocate(false); local1.DeserializeFromObjectBuilder(effect); MyParticlesLibrary.AddParticleEffect(local1); } } } }
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); }
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(GameServerItem server) { if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION) { var sb = new StringBuilder(); sb.AppendFormat(MyTexts.GetString(MySpaceTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion); MyGuiSandbox.Show(sb, MySpaceTexts.MessageBoxCaptionError); return; } if (MyFakes.ENABLE_MP_DATA_HASHES) { var serverHash = server.GetGameTagByPrefix("datahash"); if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64()) { MyGuiSandbox.Show(MySpaceTexts.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); StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningWorld); MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel); MyGuiSandbox.AddScreen(progress); progress.ProgressCancelled += () => { multiplayer.Dispose(); MyGuiScreenMainMenu.ReturnToMainMenu(); }; multiplayer.OnJoin += delegate { MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo() { EnterState = LobbyEnterResponseEnum.Success }, multiplayer); }; }
public static bool HasSameData(IMyLobby lobby) { string dataHash = GetDataHash(lobby); return((dataHash != "") ? (dataHash == MyDataIntegrityChecker.GetHashBase64()) : true); }
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); }