Skip to content

Commit

Permalink
more stats pog
Browse files Browse the repository at this point in the history
  • Loading branch information
Goobwabber committed May 29, 2021
1 parent 7f8a399 commit 618f195
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 12 additions & 6 deletions MultiplayerExtensions/OverrideClasses/GameStateControllerStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MultiplayerExtensions.Packets;
using MultiplayerExtensions.Sessions;
using MultiplayerExtensions.Utilities;
using Polyglot;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions MultiplayerExtensions/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using MultiplayerExtensions.UI;
using BeatSaberMarkupLanguage.Settings;
using System.Net.Http;
using MultiplayerExtensions.Sessions;

namespace MultiplayerExtensions
{
Expand Down
6 changes: 3 additions & 3 deletions MultiplayerExtensions/Sessions/ExtendedPlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class ExtendedPlayerManager : IInitializable, IDisposable
protected readonly IPlatformUserModel _platformUserModel;

private Dictionary<string, ExtendedPlayer> _players = new Dictionary<string, ExtendedPlayer>();
internal string? localPlatformID;
internal Platform localPlatform;
internal Color localColor;
internal static string? localPlatformID;
internal static Platform localPlatform;
internal static Color localColor;

public Dictionary<string, ExtendedPlayer> players { get => _players; }
public event Action<ExtendedPlayer>? extendedPlayerConnectedEvent;
Expand Down
4 changes: 3 additions & 1 deletion MultiplayerExtensions/Sessions/SessionManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MultiplayerExtensions.Utilities;
using System;
using Zenject;

namespace MultiplayerExtensions.Sessions
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions MultiplayerExtensions/Utilities/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ public static async Task<bool> AddUser(string userId, int platform)
return await PerformWebRequest("POST", $"/adduser?userId={userId}&platform={platform}") != null;
}

public static async Task<bool> PlayMap(string hash)
public static async Task<bool> 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<bool> 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;
}
}
}

0 comments on commit 618f195

Please sign in to comment.