private static HostedGameData GenerateAnnounce() { var sessionManager = MpSession.SessionManager; var localPlayer = sessionManager.localPlayer; var connectedPlayers = sessionManager.connectedPlayers; if (_mpExVersion == null) { _mpExVersion = MpExHelper.GetInstalledVersion(); if (_mpExVersion != null) { Plugin.Log?.Info($"Detected MultiplayerExtensions, version {_mpExVersion}"); } } var lobbyAnnounce = new HostedGameData() { ServerCode = _lobbyCode, GameName = MpSession.GetHostGameName(), OwnerId = localPlayer.userId, OwnerName = localPlayer.userName, PlayerCount = MpSession.GetPlayerCount(), PlayerLimit = MpSession.GetPlayerLimit(), IsModded = localPlayer.HasState("modded") || localPlayer.HasState("customsongs") || _mpExVersion != null, LobbyState = MpLobbyStatePatch.LobbyState, LevelId = _level?.levelID, SongName = _level?.songName, SongAuthor = _level?.songAuthorName, Difficulty = _difficulty, Platform = MpLocalPlayer.PlatformId, MasterServerHost = MpConnect.LastUsedMasterServer != null ? MpConnect.LastUsedMasterServer.hostName : null, MasterServerPort = MpConnect.LastUsedMasterServer != null ? MpConnect.LastUsedMasterServer.port : MpConnect.DEFAULT_MASTER_PORT, MpExVersion = _mpExVersion }; lobbyAnnounce.Players = new List <HostedGamePlayer>(); lobbyAnnounce.Players.Add(new HostedGamePlayer() { SortIndex = localPlayer.sortIndex, UserId = localPlayer.userId, UserName = localPlayer.userName, IsHost = localPlayer.isConnectionOwner, Latency = localPlayer.currentLatency }); foreach (var connectedPlayer in connectedPlayers) { lobbyAnnounce.Players.Add(new HostedGamePlayer() { SortIndex = connectedPlayer.sortIndex, UserId = connectedPlayer.userId, UserName = connectedPlayer.userName, IsHost = connectedPlayer.isConnectionOwner, Latency = connectedPlayer.currentLatency }); } return(lobbyAnnounce); }
public static void Join(HostedGameData game) { // MpEx version check if (game.MpExVersion != null) { var ourMpExVersion = MpExHelper.GetInstalledVersion(); if (ourMpExVersion == null || !ourMpExVersion.Equals(game.MpExVersion)) { var ourMpExVersionStr = (ourMpExVersion != null ? ourMpExVersion.ToString() : "Not installed"); var theirMpExVersionStr = game.MpExVersion.ToString(); Plugin.Log.Warn($"Blocking game join because of MultiplayerExtensions version mismatch " + $"(ours: {ourMpExVersionStr}, theirs: {theirMpExVersionStr})"); var mpExError = new StringBuilder(); mpExError.AppendLine($"MultiplayerExtensions version difference detected!"); mpExError.AppendLine($"Please ensure you and the host are both using the latest version."); mpExError.AppendLine(); mpExError.AppendLine($"Your version: {ourMpExVersionStr}"); mpExError.AppendLine($"Their version: {theirMpExVersionStr}"); MpModeSelection.PresentConnectionFailedError ( errorTitle: "Incompatible game", errorMessage: mpExError.ToString(), canRetry: false ); return; } } // Master server switching if (game.MasterServerHost == null || game.MasterServerHost.EndsWith(OFFICIAL_MASTER_SUFFIX)) { // Game is hosted on the player platform's official master server if (_usingModdedServer || _officialEndPoint == null) { // If we normally use a modded server (e.g. because BeatTogether is installed), we need to now force-connect to our official server switch (MpLocalPlayer.Platform) { case UserInfo.Platform.Oculus: SetMasterServerOverride(OFFICIAL_MASTER_OCULUS); break; case UserInfo.Platform.PS4: // lmao SetMasterServerOverride(OFFICIAL_MASTER_PS4); break; case UserInfo.Platform.Test: // hmmm SetMasterServerOverride(OFFICIAL_MASTER_TEST); break; default: case UserInfo.Platform.Steam: case null: SetMasterServerOverride(OFFICIAL_MASTER_STEAM); break; } } else { // Clearing the override should fall back to the correct official server ClearMasterServerOverride(); } } else { // Game is hosted on a custom master server, we need to override SetMasterServerOverride(game.MasterServerHost, game.MasterServerPort.HasValue ? game.MasterServerPort.Value : DEFAULT_MASTER_PORT); } // Trigger the actual join via server code MpModeSelection.ConnectToHostedGame(game); }