예제 #1
0
        private static void TryAuthenticate(string authData)
        {
            VRCModLogger.Log("[VRCModNetwork] Getting current instanceId");
            if (RoomManagerBase.currentRoom != null && RoomManagerBase.currentRoom.id != null && RoomManagerBase.currentRoom.currentInstanceIdWithTags != null)
            {
                userInstanceId = RoomManagerBase.currentRoom.id + ":" + RoomManagerBase.currentRoom.currentInstanceIdWithTags;
            }
            VRCModLogger.Log("[VRCModNetwork] Getting current modList");
            modlist = ModDesc.GetAllMods();
            VRCModLogger.Log("[VRCModNetwork] 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("[VRCModNetwork] Env: " + env);
            VRCModLogger.Log("[VRCModNetwork] Authenticating");
            AuthCommand authCommand = CommandManager.CreateInstance("AUTH", client, false) as AuthCommand;

            authCommand.Auth(userUuid, authData, stringEnv, userInstanceId, roomSecret, modlist);
            VRCModLogger.Log("[VRCModNetwork] Done");
        }
예제 #2
0
 private static void ModCheckThread()
 {
     while (true)
     {
         lock (userDatasLock)
         {
             if (IsAuthenticated)
             {
                 List <ModDesc> newModlist = ModDesc.GetAllMods();
                 bool           identical  = true;
                 if (newModlist.Count != modlist.Count)
                 {
                     identical = false;
                 }
                 else
                 {
                     foreach (ModDesc mod in newModlist)
                     {
                         bool found = false;
                         foreach (ModDesc mod2 in modlist)
                         {
                             if (
                                 mod2.name.Equals(mod.name) &&
                                 mod2.version.Equals(mod.version) &&
                                 mod2.author.Equals(mod.author) &&
                                 ((mod2.downloadLink == null && mod.downloadLink == null) || (mod2.downloadLink != null && mod2.downloadLink.Equals(mod.downloadLink))) &&
                                 mod2.baseClass.Equals(mod.baseClass))
                             {
                                 found = true;
                                 break;
                             }
                         }
                         if (!found)
                         {
                             identical = false;
                             break;
                         }
                     }
                 }
                 if (!identical)
                 {
                     modlist = newModlist;
                     ((ModListChangedCommand)CommandManager.CreateInstance("MODLISTCHANGED", client)).Send("{\"modlist\":[" + ModDesc.CreateModlistJson(modlist) + "]}");
                 }
             }
         }
         Thread.Sleep(1000);
     }
 }
예제 #3
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");
                        }
                    }
                }
            }
        }
예제 #4
0
        internal static void Update()
        {
            if (State == ConnectionState.CONNECTED)
            {
                lock (userDatasLock)
                {
                    // Check if user changed
                    string uuid        = APIUser.CurrentUser == null ? "" : APIUser.CurrentUser.id ?? "";
                    string displayName = APIUser.CurrentUser == null ? "" : APIUser.CurrentUser.displayName ?? "";
                    string authToken   = ApiCredentials.GetAuthToken() ?? "";

                    Credentials c = ApiCredentials.GetWebCredentials() as Credentials;

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

                        if (!uuid.Equals("") && "".Equals(authToken))
                        {
                            string password = typeof(ApiCredentials).GetField("password", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) as string;
                            authToken = Convert.ToBase64String(Encoding.UTF8.GetBytes(ApiCredentials.GetUsername() + ":" + password));
                        }

                        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
                        {
                            userUuid = uuid;
                            VRCModLogger.Log("Getting current instanceId");
                            if (RoomManager.currentRoom != null && RoomManager.currentRoom.id != null && RoomManager.currentRoom.currentInstanceIdOnly != null)
                            {
                                userInstanceId = RoomManager.currentRoom.id + ":" + RoomManager.currentRoom.currentInstanceIdOnly;
                            }
                            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, modlist);
                            VRCModLogger.Log("Done");
                        }
                    }

                    if (IsAuthenticated)
                    {
                        string roomId = "";
                        if (RoomManager.currentRoom != null && RoomManager.currentRoom.id != null && RoomManager.currentRoom.currentInstanceIdOnly != null)
                        {
                            roomId = RoomManager.currentRoom.id + ":" + RoomManager.currentRoom.currentInstanceIdOnly;
                        }
                        if (!userInstanceId.Equals(roomId))
                        {
                            VRCModLogger.Log("Updating instance id");
                            userInstanceId = roomId;
                            if (roomId != "")
                            {
                                DiscordManager.RoomChanged(RoomManager.currentRoom.name, roomId, RoomManager.currentRoom.currentInstanceAccess, RoomManager.currentRoom.capacity);
                            }
                            else
                            {
                                DiscordManager.RoomChanged("", roomId, ApiWorldInstance.AccessType.InviteOnly, 0);
                            }
                            ((InstanceChangedCommand)CommandManager.CreateInstance("INSTANCECHANGED", client)).Send(userInstanceId);
                            VRCModLogger.Log("Done");
                        }
                    }
                }
            }
        }