diff --git a/MultiplayerExtensions/Environments/LobbyEnvironmentManager.cs b/MultiplayerExtensions/Environments/LobbyEnvironmentManager.cs index 3b6ee62..2b70f66 100644 --- a/MultiplayerExtensions/Environments/LobbyEnvironmentManager.cs +++ b/MultiplayerExtensions/Environments/LobbyEnvironmentManager.cs @@ -62,7 +62,7 @@ private void HandleLobbyEnvironmentLoaded(object sender, System.EventArgs e) _stageManager.transform.localScale = new Vector3(centerScreenScale, centerScreenScale, centerScreenScale); SetAllPlayerPlaceColors(Color.black); - SetPlayerPlaceColor(_sessionManager.localPlayer, _playerManager.localColor); + SetPlayerPlaceColor(_sessionManager.localPlayer, ExtendedPlayerManager.localColor); foreach (ExtendedPlayer player in _playerManager.players.Values) SetPlayerPlaceColor(player, player.playerColor); } diff --git a/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs b/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs index dfcb141..9c232f8 100644 --- a/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs +++ b/MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs @@ -2,6 +2,7 @@ using MultiplayerExtensions.Packets; using MultiplayerExtensions.Sessions; using MultiplayerExtensions.Utilities; +using Polyglot; using System; using System.Collections.Generic; using System.Linq; @@ -27,6 +28,8 @@ internal GameStateControllerStub(PacketManager packetManager, ExtendedPlayerMana _lobbyGameState.gameStateDidChangeEvent -= base.HandleGameStateDidChange; _lobbyGameState.gameStateDidChangeEvent += HandleGameStateDidChange; base.Activate(); + + (this as ILobbyGameStateController).levelFinishedEvent += handleLevelFinished; } public new void Deactivate() @@ -37,6 +40,8 @@ internal GameStateControllerStub(PacketManager packetManager, ExtendedPlayerMana _lobbyGameState.gameStateDidChangeEvent -= HandleGameStateDidChange; _lobbyGameState.gameStateDidChangeEvent += base.HandleGameStateDidChange; base.Deactivate(); + + (this as ILobbyGameStateController).levelFinishedEvent -= handleLevelFinished; } public new void StartListeningToGameStart() @@ -173,15 +178,16 @@ private void HandleCountdown(IPreviewBeatmapLevel previewBeatmapLevel, BeatmapDi private void StartLevel() { starting = false; - if (previewBeatmapLevel != null) - { - string? hash = Utilities.Utils.LevelIdToHash(previewBeatmapLevel.levelID); - if (hash != null) - _ = Statistics.PlayMap(hash); - } base.HandleMultiplayerLevelLoaderCountdownFinished(previewBeatmapLevel, beatmapDifficulty, beatmapCharacteristic, difficultyBeatmap, gameplayModifiers); } + private void handleLevelFinished(MultiplayerLevelScenesTransitionSetupDataSO sceneSetupData, MultiplayerResultsData resultsData) + { + string? hash = Utilities.Utils.LevelIdToHash(sceneSetupData.previewBeatmapLevel.levelID); + if (hash != null) + _ = Statistics.PlayMap(hash, sceneSetupData.beatmapDifficulty.ToString(), sceneSetupData.beatmapCharacteristic.serializedName, (int)Math.Floor(resultsData.localPlayerResultData.levelCompletionResults.endSongTime), (int)ExtendedPlayerManager.localPlatform, MPState.CurrentMasterServer.hostname); + } + private bool starting; private IPreviewBeatmapLevel? previewBeatmapLevel; diff --git a/MultiplayerExtensions/Plugin.cs b/MultiplayerExtensions/Plugin.cs index c561d46..2019cd4 100644 --- a/MultiplayerExtensions/Plugin.cs +++ b/MultiplayerExtensions/Plugin.cs @@ -17,6 +17,7 @@ using MultiplayerExtensions.UI; using BeatSaberMarkupLanguage.Settings; using System.Net.Http; +using MultiplayerExtensions.Sessions; namespace MultiplayerExtensions { diff --git a/MultiplayerExtensions/Sessions/ExtendedPlayerManager.cs b/MultiplayerExtensions/Sessions/ExtendedPlayerManager.cs index 208f397..4fc39c9 100644 --- a/MultiplayerExtensions/Sessions/ExtendedPlayerManager.cs +++ b/MultiplayerExtensions/Sessions/ExtendedPlayerManager.cs @@ -14,9 +14,9 @@ public class ExtendedPlayerManager : IInitializable, IDisposable protected readonly IPlatformUserModel _platformUserModel; private Dictionary _players = new Dictionary(); - internal string? localPlatformID; - internal Platform localPlatform; - internal Color localColor; + internal static string? localPlatformID; + internal static Platform localPlatform; + internal static Color localColor; public Dictionary players { get => _players; } public event Action? extendedPlayerConnectedEvent; diff --git a/MultiplayerExtensions/Sessions/SessionManager.cs b/MultiplayerExtensions/Sessions/SessionManager.cs index 0676c6a..0a68371 100644 --- a/MultiplayerExtensions/Sessions/SessionManager.cs +++ b/MultiplayerExtensions/Sessions/SessionManager.cs @@ -1,4 +1,5 @@ -using System; +using MultiplayerExtensions.Utilities; +using System; using Zenject; namespace MultiplayerExtensions.Sessions @@ -35,6 +36,7 @@ public void Dispose() private void HandleConnected() { MPState.LocalPlayerIsHost = _sessionManager.localPlayer.isConnectionOwner; + _ = Statistics.UseMaster(MPState.CurrentMasterServer.hostname, (int)ExtendedPlayerManager.localPlatform, ExtendedPlayerManager.localPlatformID, MPState.LocalPlayerIsHost); } private void HandlePlayerStateChanged(IConnectedPlayer player) diff --git a/MultiplayerExtensions/Utilities/Statistics.cs b/MultiplayerExtensions/Utilities/Statistics.cs index 918df35..f40e854 100644 --- a/MultiplayerExtensions/Utilities/Statistics.cs +++ b/MultiplayerExtensions/Utilities/Statistics.cs @@ -64,9 +64,16 @@ public static async Task AddUser(string userId, int platform) return await PerformWebRequest("POST", $"/adduser?userId={userId}&platform={platform}") != null; } - public static async Task PlayMap(string hash) + public static async Task PlayMap(string hash, string difficulty, string characteristic, int timePlayed, int platform, string hostname) { - return await PerformWebRequest("POST", $"/playmap?mapHash={hash}") != null; + return await PerformWebRequest("POST", $"/playmap?hash={hash}&difficulty={difficulty}&characteristic={characteristic}&timePlayed={timePlayed}&platform={platform}&hostname={hostname}") != null; + } + + public static async Task UseMaster(string hostname, int platform, string? userId = null, bool host = false) + { + if (userId != null) + return await PerformWebRequest("POST", $"/usemaster?hostname={hostname}&userId={userId}&platform={platform}&host={host}") != null; + return await PerformWebRequest("POST", $"/usemaster?hostname={hostname}&platform={platform}&host={host}") != null; } } }