Skip to content

Commit 618f195

Browse files
committed
more stats pog
1 parent 7f8a399 commit 618f195

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

MultiplayerExtensions/Environments/LobbyEnvironmentManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private void HandleLobbyEnvironmentLoaded(object sender, System.EventArgs e)
6262
_stageManager.transform.localScale = new Vector3(centerScreenScale, centerScreenScale, centerScreenScale);
6363

6464
SetAllPlayerPlaceColors(Color.black);
65-
SetPlayerPlaceColor(_sessionManager.localPlayer, _playerManager.localColor);
65+
SetPlayerPlaceColor(_sessionManager.localPlayer, ExtendedPlayerManager.localColor);
6666
foreach (ExtendedPlayer player in _playerManager.players.Values)
6767
SetPlayerPlaceColor(player, player.playerColor);
6868
}

MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using MultiplayerExtensions.Packets;
33
using MultiplayerExtensions.Sessions;
44
using MultiplayerExtensions.Utilities;
5+
using Polyglot;
56
using System;
67
using System.Collections.Generic;
78
using System.Linq;
@@ -27,6 +28,8 @@ internal GameStateControllerStub(PacketManager packetManager, ExtendedPlayerMana
2728
_lobbyGameState.gameStateDidChangeEvent -= base.HandleGameStateDidChange;
2829
_lobbyGameState.gameStateDidChangeEvent += HandleGameStateDidChange;
2930
base.Activate();
31+
32+
(this as ILobbyGameStateController).levelFinishedEvent += handleLevelFinished;
3033
}
3134

3235
public new void Deactivate()
@@ -37,6 +40,8 @@ internal GameStateControllerStub(PacketManager packetManager, ExtendedPlayerMana
3740
_lobbyGameState.gameStateDidChangeEvent -= HandleGameStateDidChange;
3841
_lobbyGameState.gameStateDidChangeEvent += base.HandleGameStateDidChange;
3942
base.Deactivate();
43+
44+
(this as ILobbyGameStateController).levelFinishedEvent -= handleLevelFinished;
4045
}
4146

4247
public new void StartListeningToGameStart()
@@ -173,15 +178,16 @@ private void HandleCountdown(IPreviewBeatmapLevel previewBeatmapLevel, BeatmapDi
173178
private void StartLevel()
174179
{
175180
starting = false;
176-
if (previewBeatmapLevel != null)
177-
{
178-
string? hash = Utilities.Utils.LevelIdToHash(previewBeatmapLevel.levelID);
179-
if (hash != null)
180-
_ = Statistics.PlayMap(hash);
181-
}
182181
base.HandleMultiplayerLevelLoaderCountdownFinished(previewBeatmapLevel, beatmapDifficulty, beatmapCharacteristic, difficultyBeatmap, gameplayModifiers);
183182
}
184183

184+
private void handleLevelFinished(MultiplayerLevelScenesTransitionSetupDataSO sceneSetupData, MultiplayerResultsData resultsData)
185+
{
186+
string? hash = Utilities.Utils.LevelIdToHash(sceneSetupData.previewBeatmapLevel.levelID);
187+
if (hash != null)
188+
_ = Statistics.PlayMap(hash, sceneSetupData.beatmapDifficulty.ToString(), sceneSetupData.beatmapCharacteristic.serializedName, (int)Math.Floor(resultsData.localPlayerResultData.levelCompletionResults.endSongTime), (int)ExtendedPlayerManager.localPlatform, MPState.CurrentMasterServer.hostname);
189+
}
190+
185191
private bool starting;
186192

187193
private IPreviewBeatmapLevel? previewBeatmapLevel;

MultiplayerExtensions/Plugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using MultiplayerExtensions.UI;
1818
using BeatSaberMarkupLanguage.Settings;
1919
using System.Net.Http;
20+
using MultiplayerExtensions.Sessions;
2021

2122
namespace MultiplayerExtensions
2223
{

MultiplayerExtensions/Sessions/ExtendedPlayerManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public class ExtendedPlayerManager : IInitializable, IDisposable
1414
protected readonly IPlatformUserModel _platformUserModel;
1515

1616
private Dictionary<string, ExtendedPlayer> _players = new Dictionary<string, ExtendedPlayer>();
17-
internal string? localPlatformID;
18-
internal Platform localPlatform;
19-
internal Color localColor;
17+
internal static string? localPlatformID;
18+
internal static Platform localPlatform;
19+
internal static Color localColor;
2020

2121
public Dictionary<string, ExtendedPlayer> players { get => _players; }
2222
public event Action<ExtendedPlayer>? extendedPlayerConnectedEvent;

MultiplayerExtensions/Sessions/SessionManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using MultiplayerExtensions.Utilities;
2+
using System;
23
using Zenject;
34

45
namespace MultiplayerExtensions.Sessions
@@ -35,6 +36,7 @@ public void Dispose()
3536
private void HandleConnected()
3637
{
3738
MPState.LocalPlayerIsHost = _sessionManager.localPlayer.isConnectionOwner;
39+
_ = Statistics.UseMaster(MPState.CurrentMasterServer.hostname, (int)ExtendedPlayerManager.localPlatform, ExtendedPlayerManager.localPlatformID, MPState.LocalPlayerIsHost);
3840
}
3941

4042
private void HandlePlayerStateChanged(IConnectedPlayer player)

MultiplayerExtensions/Utilities/Statistics.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,16 @@ public static async Task<bool> AddUser(string userId, int platform)
6464
return await PerformWebRequest("POST", $"/adduser?userId={userId}&platform={platform}") != null;
6565
}
6666

67-
public static async Task<bool> PlayMap(string hash)
67+
public static async Task<bool> PlayMap(string hash, string difficulty, string characteristic, int timePlayed, int platform, string hostname)
6868
{
69-
return await PerformWebRequest("POST", $"/playmap?mapHash={hash}") != null;
69+
return await PerformWebRequest("POST", $"/playmap?hash={hash}&difficulty={difficulty}&characteristic={characteristic}&timePlayed={timePlayed}&platform={platform}&hostname={hostname}") != null;
70+
}
71+
72+
public static async Task<bool> UseMaster(string hostname, int platform, string? userId = null, bool host = false)
73+
{
74+
if (userId != null)
75+
return await PerformWebRequest("POST", $"/usemaster?hostname={hostname}&userId={userId}&platform={platform}&host={host}") != null;
76+
return await PerformWebRequest("POST", $"/usemaster?hostname={hostname}&platform={platform}&host={host}") != null;
7077
}
7178
}
7279
}

0 commit comments

Comments
 (0)