Пример #1
0
        private static void AttemptLogin()
        {
            if (ApiCredentials.Load())
            {
                System.Action <bool> onAuthed = delegate(bool isSuccess) {
                    if (isSuccess)
                    {
                        refreshWindow = true;
                    }
                    else
                    {
                        Login();
                    }
                };

                switch (ApiCredentials.GetAuthTokenProvider())
                {
                case "vrchat":
                    AuthenticateWithVRChat(onAuthed);
                    break;
                }
            }
            else
            {
                Login();
            }
        }
Пример #2
0
        internal static void Update()
        {
            if (State == ConnectionState.CONNECTED)
            {
                lock (userDatasLock)
                {
                    // Check if user changed
                    string uuid        = APIUser.CurrentUser?.id ?? "";
                    string displayName = APIUser.CurrentUser?.displayName ?? "";
                    string authToken   = ApiCredentials.GetAuthToken() ?? "";

                    if (!uuid.Equals(userUuid))
                    {
                        VRCModLogger.Log("new UUID: " + uuid);
                        DiscordManager.UserChanged(displayName);

                        if (uuid.Equals(""))
                        {
                            userUuid = uuid;
                            VRCModLogger.Log("Resetting data");
                            ResetDatas();
                            VRCModLogger.Log("Logging out");
                            LogoutCommand logoutCommand = CommandManager.CreateInstance("LOGOUT", client) as LogoutCommand;
                            logoutCommand.LogOut();
                            VRCModLogger.Log("Done");
                        }
                        else
                        {
                            if (ApiCredentials.GetAuthTokenProvider() == "steam")
                            {
                                authToken = "st_" + GetSteamTicket();
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(credentials))
                                {
                                    authToken   = "login " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)) + " " + ApiCredentials.GetAuthToken();
                                    credentials = "";
                                    VRCTools.ModPrefs.SetBool("vrctools", "hasvrcmnwtoken", true);
                                }
                                else
                                {
                                    authToken = ApiCredentials.GetAuthToken();
                                }
                            }

                            userUuid = uuid;
                            VRCModLogger.Log("Getting current instanceId");
                            if (RoomManager.currentRoom != null && RoomManager.currentRoom.id != null && RoomManager.currentRoom.currentInstanceIdWithTags != null)
                            {
                                userInstanceId = RoomManager.currentRoom.id + ":" + RoomManager.currentRoom.currentInstanceIdWithTags;
                            }
                            VRCModLogger.Log("Getting current modList");
                            modlist = ModDesc.GetAllMods();
                            VRCModLogger.Log("Getting current environment");
                            ApiServerEnvironment env = VRCApplicationSetup._instance.ServerEnvironment;
                            string stringEnv         = "";
                            if (env == ApiServerEnvironment.Dev)
                            {
                                stringEnv = "dev";
                            }
                            if (env == ApiServerEnvironment.Beta)
                            {
                                stringEnv = "beta";
                            }
                            if (env == ApiServerEnvironment.Release)
                            {
                                stringEnv = "release";
                            }
                            VRCModLogger.Log("Env: " + env);
                            VRCModLogger.Log("Authenticating");
                            AuthCommand authCommand = CommandManager.CreateInstance("AUTH", client, false) as AuthCommand;
                            authCommand.Auth(authToken, stringEnv, userInstanceId, roomSecret, modlist);
                            VRCModLogger.Log("Done");
                        }
                    }

                    if (IsAuthenticated)
                    {
                        string roomId = "";
                        if (RoomManager.currentRoom?.currentInstanceIdOnly != null)
                        {
                            roomId = RoomManager.currentRoom.id + ":" + RoomManager.currentRoom.currentInstanceIdWithTags;
                        }
                        if (!userInstanceId.Equals(roomId))
                        {
                            VRCModLogger.Log("Updating instance id. Current room: " + roomId);
                            userInstanceId = roomId;
                            roomSecret     = "";
                            if (roomId != "")
                            {
                                roomSecret = DiscordManager.RoomChanged(RoomManager.currentRoom.name, RoomManager.currentRoom.id + ":" + RoomManager.currentRoom.currentInstanceIdOnly, RoomManager.currentRoom.currentInstanceIdWithTags, RoomManager.currentRoom.currentInstanceAccess, RoomManager.currentRoom.capacity);
                            }
                            else
                            {
                                DiscordManager.RoomChanged("", "", "", ApiWorldInstance.AccessType.InviteOnly, 0);
                            }
                            ((InstanceChangedCommand)CommandManager.CreateInstance("INSTANCECHANGED", client)).Send(roomId, roomSecret);
                            VRCModLogger.Log("Done");
                        }
                    }
                }
            }
        }
Пример #3
0
        internal static void Update()
        {
            lock (sheduled)
            {
                foreach (Action a in sheduled)
                {
                    try
                    {
                        a?.Invoke();
                    }
                    catch (Exception e)
                    {
                        VRCModLogger.LogError("[VRCModNetwork] An error occured while running sheduled action: " + e);
                    }
                }
                sheduled.Clear();
            }

            if (State == ConnectionState.CONNECTED || State == ConnectionState.NEED_REAUTH)
            {
                lock (userDatasLock)
                {
                    // Check if user changed
                    string uuid = APIUser.CurrentUser?.id ?? "";

                    if (!uuid.Equals(userUuid))
                    {
                        VRCModLogger.Log("[VRCModNetwork] new UUID: " + uuid);

                        userUuid = uuid; // use it as a lock to avoid spamming
                        if (uuid.Equals(""))
                        {
                            VRCModLogger.Log("[VRCModNetwork] Resetting data");
                            ResetDatas();
                            VRCModLogger.Log("[VRCModNetwork] Logging out");
                            LogoutCommand logoutCommand = CommandManager.CreateInstance("LOGOUT", client) as LogoutCommand;
                            logoutCommand.LogOut();
                            VRCModLogger.Log("[VRCModNetwork] Done");
                        }
                        else
                        {
                            if (SecurePlayerPrefs.HasKey("vrcmnw_token_" + uuid))
                            {
                                VRCModLogger.Log("[VRCModNetwork] Logging in using VRCModNetwork token");
                                TryAuthenticate("vrcmnw " + uuid + " " + SecurePlayerPrefs.GetString("vrcmnw_token_" + uuid, "vl9u1grTnvXA"));
                            }
                            else if (ApiCredentials.GetAuthTokenProvider() == "steam")
                            {
                                VRCModLogger.Log("[VRCModNetwork] Logging in using Steam token");
                                TryAuthenticate("st_" + SteamUtils.GetSteamTicket());
                            }
                            else if (!string.IsNullOrEmpty(credentials))
                            {
                                VRCModLogger.Log("[VRCModNetwork] Logging in using VRChat credentials");
                                TryAuthenticate("login " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
                                credentials = "";
                                VRCTools.ModPrefs.SetBool("vrctools", "hasvrcmnwtoken", true);
                            }
                            else
                            {
                                VRCModLogger.LogError("[VRCModNetwork] Unable to auth: Required auth datas are missing");
                                State = ConnectionState.NEED_REAUTH;
                                return;
                            }
                        }
                    }

                    if (IsAuthenticated)
                    {
                        string roomId = "";
                        if (RoomManagerBase.currentRoom?.currentInstanceIdOnly != null)
                        {
                            roomId = RoomManagerBase.currentRoom.id + ":" + RoomManagerBase.currentRoom.currentInstanceIdWithTags;
                        }
                        if (!userInstanceId.Equals(roomId))
                        {
                            VRCModLogger.Log("[VRCModNetwork] Updating instance id. Current room: " + roomId);
                            userInstanceId = roomId;
                            ((InstanceChangedCommand)CommandManager.CreateInstance("INSTANCECHANGED", client)).Send(roomId);
                            VRCModLogger.Log("[VRCModNetwork] Done");
                        }
                    }
                }
            }
        }
Пример #4
0
        internal static void Update()
        {
            lock (sheduled)
            {
                foreach (Action a in sheduled)
                {
                    try
                    {
                        a?.Invoke();
                    }
                    catch (Exception e)
                    {
                        VRCModLogger.LogError("[VRCModNetwork] An error occured while running sheduled action: " + e);
                    }
                }
                sheduled.Clear();
            }

            if (State == ConnectionState.CONNECTED)
            {
                lock (userDatasLock)
                {
                    // Check if user changed
                    string uuid = APIUser.CurrentUser?.id ?? "";

                    if (!uuid.Equals(userUuid))
                    {
                        VRCModLogger.Log("[VRCModNetwork] new UUID: " + uuid);
                        string displayName = APIUser.CurrentUser?.displayName ?? "";
                        DiscordManager.UserChanged(displayName);

                        userUuid = uuid; // use it as a lock to avoid spamming
                        if (uuid.Equals(""))
                        {
                            VRCModLogger.Log("[VRCModNetwork] Resetting data");
                            ResetDatas();
                            VRCModLogger.Log("[VRCModNetwork] Logging out");
                            LogoutCommand logoutCommand = CommandManager.CreateInstance("LOGOUT", client) as LogoutCommand;
                            logoutCommand.LogOut();
                            VRCModLogger.Log("[VRCModNetwork] Done");
                        }
                        else
                        {
                            if (SecurePlayerPrefs.HasKey("vrcmnw_token_" + uuid))
                            {
                                TryAuthenticate("vrcmnw " + uuid + " " + SecurePlayerPrefs.GetString("vrcmnw_token_" + uuid, "vl9u1grTnvXA"));
                            }
                            else if (ApiCredentials.GetAuthTokenProvider() == "steam")
                            {
                                TryAuthenticate("st_" + SteamUtils.GetSteamTicket());
                            }
                            else if (ApiCredentials.GetAuthTokenProvider() == "oculus")
                            {
                                OculusUtils.GetAccessToken(
                                    ticket => TryAuthenticate($"oculus {ticket} {OculusUtils.OculusId} {OculusUtils.OculusName}"),
                                    error => VRCModLogger.LogError("[VRCModNetwork] Error while fetching oculus ticket: " + error));
                            }
                            else if (!string.IsNullOrEmpty(credentials))
                            {
                                TryAuthenticate("login " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
                                credentials = "";
                                VRCTools.ModPrefs.SetBool("vrctools", "hasvrcmnwtoken", true);
                            }
                            else
                            {
                                VRCModLogger.LogError("[VRCModNetwork] Unable to auth: Required auth datas are missing");
                                return;
                            }
                        }
                    }

                    if (IsAuthenticated)
                    {
                        string roomId = "";
                        if (RoomManagerBase.currentRoom?.currentInstanceIdOnly != null)
                        {
                            roomId = RoomManagerBase.currentRoom.id + ":" + RoomManagerBase.currentRoom.currentInstanceIdWithTags;
                        }
                        if (!userInstanceId.Equals(roomId))
                        {
                            VRCModLogger.Log("[VRCModNetwork] Updating instance id. Current room: " + roomId);
                            userInstanceId = roomId;
                            roomSecret     = "";
                            if (roomId != "")
                            {
                                roomSecret = DiscordManager.RoomChanged(RoomManagerBase.currentRoom.name, RoomManagerBase.currentRoom.id + ":" + RoomManagerBase.currentRoom.currentInstanceIdOnly, RoomManagerBase.currentRoom.currentInstanceIdWithTags, RoomManager.currentRoom.currentInstanceAccess, RoomManager.currentRoom.capacity);
                            }
                            else
                            {
                                DiscordManager.RoomChanged("", "", "", ApiWorldInstance.AccessType.InviteOnly, 0);
                            }
                            ((InstanceChangedCommand)CommandManager.CreateInstance("INSTANCECHANGED", client)).Send(roomId, roomSecret);
                            VRCModLogger.Log("[VRCModNetwork] Done");
                        }
                    }
                }
            }
        }
Пример #5
0
        private void OnApplicationStart()
        {
            if (!ApiCredentials.Load())
            {
                VRCModLogger.Log("No credential founds");
            }
            else
            {
                VRCModLogger.Log("Credentials:\n - Token: " + ApiCredentials.GetAuthToken() + "\n - Provider: " + ApiCredentials.GetAuthTokenProvider() + "\n - UserId: " + ApiCredentials.GetAuthTokenProviderUserId());
            }


            String lp    = "";
            bool   first = true;

            foreach (var lp2 in Environment.GetCommandLineArgs())
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    lp += " " + lp2;
                }
            }
            VRCModLogger.Log("Launch parameters:" + lp);

            ModPrefs.RegisterCategory("vrctools", "VRCTools");
            ModPrefs.RegisterPrefBool("vrctools", "remoteauthcheckasked", false, null, true);
            ModPrefs.RegisterPrefBool("vrctools", "remoteauthcheck", false, "Allow VRCModNetwork Auth");
            ModPrefs.RegisterPrefBool("vrctools", "avatarfavdownloadasked", false, null, true);
            ModPrefs.RegisterPrefBool("vrctools", "avatarfavdownload", false, "Enable AvatarFav Updater");

            ModPrefs.RegisterPrefBool("vrctools", "enablediscordrichpresence", true, "Enable Discord RichPresence");
            ModPrefs.RegisterPrefBool("vrctools", "enabledebugconsole", false, "Enable Debug Console");

            ModPrefs.RegisterPrefBool("vrctools", "hasvrcmnwtoken", false, null, true);

            ModPrefs.RegisterPrefBool("vrctools", "allowdiscordjoinrequests", true, "Allow Discord join requests");

            //Reset the credentials to ask login again if this is the first time the user login to the VRCMNW
            if (!ModPrefs.GetBool("vrctools", "hasvrcmnwtoken"))
            {
                ApiCredentials.Clear();
            }
        }