Skip to content

Commit

Permalink
Improved GetUserInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingabopp committed Apr 7, 2020
1 parent 28a00b7 commit 5d90bec
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions BeatSaberMultiplayer/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void Awake()
instance = this;
DontDestroyOnLoad(this);
GetUserInfo.UpdateUserInfo();
playerInfo = new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID());
playerInfo = new PlayerInfo(Plugin.Username, Plugin.UserId);
NetPeerConfiguration Config = new NetPeerConfiguration("BeatSaberMultiplayer") { MaximumHandshakeAttempts = 2, AutoFlushSendQueue = false };
networkClient = new NetClient(Config);

Expand Down Expand Up @@ -193,7 +193,7 @@ public void Connect(string IP, int Port)
byte[] version = new byte[4] { (byte)assemblyVersion.Major, (byte)assemblyVersion.Minor, (byte)assemblyVersion.Build, (byte)assemblyVersion.Revision };

outMsg.Write(version);
playerInfo = new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID());
playerInfo = new PlayerInfo(Plugin.Username, Plugin.UserId);
playerInfo.AddToMessage(outMsg);

Plugin.log.Debug($"Connecting to {ip}:{port} with player name \"{playerInfo.playerName}\" and ID {playerInfo.playerId}");
Expand Down
21 changes: 14 additions & 7 deletions BeatSaberMultiplayer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Plugin
private static string joinSecret;
public static bool DownloaderExists { get; private set; }

public static string Username;
public static ulong UserId;

public static void LogLocation(string message,
[CallerFilePath] string memberPath = "",
[CallerMemberName] string memberName = "",
Expand Down Expand Up @@ -71,17 +74,11 @@ public void Init(IPA.Logging.Logger logger, PluginMetadata pluginMetadata)
PluginVersion = $"{v.Major}.{v.Minor}.{v.Build}";
log.Info($"{PluginMetadata.Name} v{PluginVersion} initialized. Current culture is {CultureInfo.CurrentCulture.Name}");
}

[OnStart]
public void OnApplicationStart()
{
instance = this;
var votingMeta = PluginManager.GetPluginFromId("BeatSaverVoting");
if (votingMeta != null)
{
log.Error($"votingMeta is not null: {votingMeta.File}");
}
else
log.Warn($"votingMeta is null.");
//BS_Utils.Utilities.BSEvents.OnLoad();
BS_Utils.Utilities.BSEvents.menuSceneLoadedFresh += MenuSceneLoadedFresh;
BS_Utils.Utilities.BSEvents.menuSceneLoaded += MenuSceneLoaded;
Expand Down Expand Up @@ -158,12 +155,22 @@ public void OnActivityJoin(object sender, string secret)
}
}

public static bool ReadUserInfo()
{
UserId = GetUserInfo.GetUserID();
Username = GetUserInfo.GetUserName();
if (UserId != 0)
return true;
return false;
}

private void MenuSceneLoadedFresh()
{
//ModelSaberAPI.HashAllAvatars();
PluginUI.OnLoad();
InGameOnlineController.OnLoad();
SpectatingController.OnLoad();
BS_Utils.Gameplay.GetUserInfo.UpdateUserInfo();
GetUserInfo.UpdateUserInfo();
if (joinAfterRestart)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void GetRooms()
byte[] version = new byte[4] { (byte)assemblyVersion.Major, (byte)assemblyVersion.Minor, (byte)assemblyVersion.Build, (byte)assemblyVersion.Revision };

outMsg.Write(version);
new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()).AddToMessage(outMsg);
new PlayerInfo(Plugin.Username, Plugin.UserId).AddToMessage(outMsg);

Plugin.log.Debug($"Connecting to {ip}:{port}...");

Expand Down
3 changes: 2 additions & 1 deletion BeatSaberMultiplayer/UI/PluginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private void CreateOnlineButton()
{
try
{
Plugin.ReadUserInfo();
SetLobbyDiscordActivity();

MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll<MainFlowCoordinator>().First();
Expand All @@ -166,7 +167,7 @@ private void CreateOnlineButton()
_noUserInfoWarning = Instantiate(dialogOrig.gameObject).GetComponent<SimpleDialogPromptViewController>();
}

if (GetUserInfo.GetUserID() == 0 && string.IsNullOrWhiteSpace(GetUserInfo.GetUserName()) || GetUserInfo.GetUserID() == 0)
if (Plugin.UserId == 0 && string.IsNullOrWhiteSpace(Plugin.Username) || Plugin.UserId == 0)
{
_noUserInfoWarning.Init("Invalid username and ID", $"Your username and ID are invalid\nMake sure you are logged in", "Go back", "Continue anyway",
(selectedButton) =>
Expand Down

0 comments on commit 5d90bec

Please sign in to comment.