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"); } } } } }