diff --git a/LibreMetaverse.Types/Utils.cs b/LibreMetaverse.Types/Utils.cs index a80376a6..e91fadfd 100644 --- a/LibreMetaverse.Types/Utils.cs +++ b/LibreMetaverse.Types/Utils.cs @@ -211,13 +211,20 @@ namespace OpenMetaverse double sCubed = s * s * s; double sSquared = s * s; - result = amount switch + if (amount == 0f) { - 0f => value1, - 1f => value2, - _ => (2d * v1 - 2d * v2 + t2 + t1) * sCubed + (3d * v2 - 3d * v1 - 2d * t1 - t2) * sSquared + t1 * s + - v1 - }; + result = value1; + } + else if (amount == 1f) + { + result = value2; + } + else + { + result = (2d * v1 - 2d * v2 + t2 + t1) * sCubed + + (3d * v2 - 3d * v1 - 2d * t1 - t2) * sSquared + + t1 * s + v1; + } return (float)result; } @@ -388,10 +395,8 @@ namespace OpenMetaverse /// /// Calculates a PBKDF2 hash of a given string /// - /// Rfc2989 is outdated and insecure. Use at your own risk! /// The string to hash /// The PBKDF2 hash of the supplied string - [Obsolete("Rfc2989 is outdated and insecure. Use at your own risk!")] public static string PBKDF2(string str) { var derivebytes = new Rfc2898DeriveBytes(str, 32) {IterationCount = 10000}; diff --git a/LibreMetaverse.Voice/VoiceControl.cs b/LibreMetaverse.Voice/VoiceControl.cs index 1f633196..9a8be6a1 100644 --- a/LibreMetaverse.Voice/VoiceControl.cs +++ b/LibreMetaverse.Voice/VoiceControl.cs @@ -136,7 +136,7 @@ namespace LibreMetaverse.Voice public void Start() { // Start the background thread - if (posThread is { IsAlive: true }) + if (posThread != null && posThread.IsAlive) { posRestart.Set(); posTokenSource.Cancel(); diff --git a/LibreMetaverse/AgentManager.cs b/LibreMetaverse/AgentManager.cs index bcf262c0..f71b5096 100644 --- a/LibreMetaverse/AgentManager.cs +++ b/LibreMetaverse/AgentManager.cs @@ -3118,7 +3118,8 @@ namespace OpenMetaverse public void RequestTeleport(ulong regionHandle, Vector3 position, Vector3 lookAt) { if (Client.Network.CurrentSim != null && - Client.Network.CurrentSim.Caps is { IsEventQueueRunning: true }) + Client.Network.CurrentSim.Caps != null && + Client.Network.CurrentSim.Caps.IsEventQueueRunning) { TeleportLocationRequestPacket teleport = new TeleportLocationRequestPacket { diff --git a/LibreMetaverse/AssetManager.cs b/LibreMetaverse/AssetManager.cs index 7f51a5e6..4d287a23 100644 --- a/LibreMetaverse/AssetManager.cs +++ b/LibreMetaverse/AssetManager.cs @@ -1120,7 +1120,7 @@ namespace OpenMetaverse if (uploadUrl != null) { // POST the asset data - Task req = Client.HttpCapsClient.PostRequestAsync(uploadUrl, "application/octet-stream", textureData, + Task postReq = Client.HttpCapsClient.PostRequestAsync(uploadUrl, "application/octet-stream", textureData, CancellationToken.None, (responseMessage, responseData, except) => { if (except != null) diff --git a/LibreMetaverse/Capabilities/HttpCapsClient.cs b/LibreMetaverse/Capabilities/HttpCapsClient.cs index fb3d2f00..ff55fd7e 100644 --- a/LibreMetaverse/Capabilities/HttpCapsClient.cs +++ b/LibreMetaverse/Capabilities/HttpCapsClient.cs @@ -57,8 +57,10 @@ namespace LibreMetaverse public async Task GetRequestAsync(Uri uri, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { - using var request = new HttpRequestMessage(HttpMethod.Get, uri); - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Get, uri)) + { + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task GetRequestAsync(Uri uri, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler) @@ -73,10 +75,12 @@ namespace LibreMetaverse public async Task PostRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { - using var request = new HttpRequestMessage(HttpMethod.Post, uri); - request.Content = new ByteArrayContent(payload); - request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Post, uri)) + { + request.Content = new ByteArrayContent(payload); + request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task PostRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, @@ -89,10 +93,12 @@ namespace LibreMetaverse DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { SerializeData(format, payload, out var serialized, out var contentType); - using var request = new HttpRequestMessage(HttpMethod.Post, uri); - request.Content = new ByteArrayContent(serialized); - request.Content.Headers.ContentType = contentType; - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Post, uri)) + { + request.Content = new ByteArrayContent(serialized); + request.Content.Headers.ContentType = contentType; + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task PostRequestAsync(Uri uri, OSDFormat format, OSD payload, CancellationToken? cancellationToken, @@ -108,10 +114,12 @@ namespace LibreMetaverse public async Task PutRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { - using var request = new HttpRequestMessage(HttpMethod.Put, uri); - request.Content = new ByteArrayContent(payload); - request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Put, uri)) + { + request.Content = new ByteArrayContent(payload); + request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task PutRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, @@ -124,10 +132,12 @@ namespace LibreMetaverse DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { SerializeData(format, payload, out var serialized, out var contentType); - using var request = new HttpRequestMessage(HttpMethod.Put, uri); - request.Content = new ByteArrayContent(serialized); - request.Content.Headers.ContentType = contentType; - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Put, uri)) + { + request.Content = new ByteArrayContent(serialized); + request.Content.Headers.ContentType = contentType; + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task PutRequestAsync(Uri uri, OSDFormat format, OSD payload, CancellationToken? cancellationToken, @@ -143,10 +153,13 @@ namespace LibreMetaverse public async Task PatchRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { - using var request = new HttpRequestMessage(HttpMethod.Patch, uri); - request.Content = new ByteArrayContent(payload); - request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + // TODO: 2.1 Standard has built in HttpMethod.Patch. Fix when the time comes we can utilize it. + using (var request = new HttpRequestMessage(new HttpMethod("PATCH"), uri)) + { + request.Content = new ByteArrayContent(payload); + request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task PatchRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, @@ -159,10 +172,13 @@ namespace LibreMetaverse DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { SerializeData(format, payload, out var serialized, out var contentType); - using var request = new HttpRequestMessage(HttpMethod.Patch, uri); - request.Content = new ByteArrayContent(serialized); - request.Content.Headers.ContentType = contentType; - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + // TODO: 2.1 Standard has built in HttpMethod.Patch. Fix when the time comes we can utilize it. + using (var request = new HttpRequestMessage(new HttpMethod("PATCH"), uri)) + { + request.Content = new ByteArrayContent(serialized); + request.Content.Headers.ContentType = contentType; + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task PatchRequestAsync(Uri uri, OSDFormat format, OSD payload, CancellationToken? cancellationToken, @@ -178,10 +194,12 @@ namespace LibreMetaverse public async Task DeleteRequestAsync(Uri uri, string contentType, byte[] payload, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { - using var request = new HttpRequestMessage(HttpMethod.Delete, uri); - request.Content = new ByteArrayContent(payload); - request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Delete, uri)) + { + request.Content = new ByteArrayContent(payload); + request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task DeleteRequestAsync(Uri uri, string contentType, byte[] payload, @@ -195,10 +213,12 @@ namespace LibreMetaverse DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { SerializeData(format, payload, out var serialized, out var contentType); - using var request = new HttpRequestMessage(HttpMethod.Delete, uri); - request.Content = new ByteArrayContent(serialized); - request.Content.Headers.ContentType = contentType; - await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + using (var request = new HttpRequestMessage(HttpMethod.Delete, uri)) + { + request.Content = new ByteArrayContent(serialized); + request.Content.Headers.ContentType = contentType; + await SendRequestAsync(request, cancellationToken, completeHandler, progressHandler, connectedHandler); + } } public async Task DeleteRequestAsync(Uri uri, OSDFormat format, OSD payload, CancellationToken? cancellationToken, @@ -214,24 +234,27 @@ namespace LibreMetaverse private async Task SendRequestAsync(HttpRequestMessage request, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler, ConnectedHandler connectedHandler) { - using var response = (cancellationToken.HasValue) - ? await SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken.Value) - : await SendAsync(request, HttpCompletionOption.ResponseHeadersRead); - if (!response.IsSuccessStatusCode) + using (var response = (cancellationToken.HasValue) + ? await SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken.Value) + : await SendAsync(request, HttpCompletionOption.ResponseHeadersRead)) { - completeHandler?.Invoke(response, null, - new HttpRequestException(response.StatusCode + " " + response.ReasonPhrase)); - } - connectedHandler?.Invoke(response); + if (!response.IsSuccessStatusCode) + { + completeHandler?.Invoke(response, null, + new HttpRequestException(response.StatusCode + " " + response.ReasonPhrase)); + } - await ProcessResponseAsync(response, cancellationToken, completeHandler, progressHandler); + connectedHandler?.Invoke(response); + + await ProcessResponseAsync(response, cancellationToken, completeHandler, progressHandler); + } } private static async Task ProcessResponseAsync(HttpResponseMessage response, CancellationToken? cancellationToken, DownloadCompleteHandler completeHandler, DownloadProgressHandler progressHandler) { var totalBytes = response.Content.Headers.ContentLength; - await using var contentStream = await response.Content.ReadAsStreamAsync(); + Stream contentStream = response.Content.ReadAsStreamAsync().Result; var length = (int)(totalBytes ?? 8192); var totalSize = totalBytes ?? 0; @@ -280,7 +303,7 @@ namespace LibreMetaverse { responseData = ms.ToArray(); ms.Close(); - await ms.DisposeAsync(); + ms.Dispose(); } } catch (Exception ex) diff --git a/LibreMetaverse/Caps.cs b/LibreMetaverse/Caps.cs index e068e4b8..c7fa0817 100644 --- a/LibreMetaverse/Caps.cs +++ b/LibreMetaverse/Caps.cs @@ -71,7 +71,7 @@ namespace OpenMetaverse /// Whether the capabilities event queue is connected and /// listening for incoming events - public bool IsEventQueueRunning => _EventQueueCap is { Running: true }; + public bool IsEventQueueRunning => _EventQueueCap != null && _EventQueueCap.Running; /// /// Default constructor diff --git a/LibreMetaverse/InventoryAISClient.cs b/LibreMetaverse/InventoryAISClient.cs index 56a871e6..4e3e3418 100644 --- a/LibreMetaverse/InventoryAISClient.cs +++ b/LibreMetaverse/InventoryAISClient.cs @@ -364,8 +364,8 @@ namespace LibreMetaverse return; } - - using (var message = new HttpRequestMessage(HttpMethod.Patch, uri)) + // TODO: 2.1 Standard has built in HttpMethod.Patch. Fix when the time comes we can utilize it. + using (var message = new HttpRequestMessage(new HttpMethod("PATCH"), uri)) { var payload = OSDParser.SerializeLLSDXmlString(updates); @@ -417,8 +417,8 @@ namespace LibreMetaverse return; } - - using (var message = new HttpRequestMessage(HttpMethod.Patch, uri)) + // TODO: 2.1 Standard has built in HttpMethod.Patch. Fix when the time comes we can utilize it. + using (var message = new HttpRequestMessage(new HttpMethod("PATCH"), uri)) { var payload = OSDParser.SerializeLLSDXmlString(updates); diff --git a/LibreMetaverse/InventoryManager.cs b/LibreMetaverse/InventoryManager.cs index ff91efc9..2afc1146 100644 --- a/LibreMetaverse/InventoryManager.cs +++ b/LibreMetaverse/InventoryManager.cs @@ -3681,10 +3681,10 @@ namespace OpenMetaverse // the problem of HttpRequestState not knowing anything about simulators Task req = Client.HttpCapsClient.PostRequestAsync(new Uri(uploadURL), "application/octet-stream", itemData, CancellationToken.None, - (response, responseData, error) => + (response, responseData, err) => { CreateItemFromAssetResponse(callback, itemData, request, - OSDParser.Deserialize(responseData), error); + OSDParser.Deserialize(responseData), err); }); } else if (status == "complete") diff --git a/LibreMetaverse/ParcelManager.cs b/LibreMetaverse/ParcelManager.cs index b7a0928f..9169b779 100644 --- a/LibreMetaverse/ParcelManager.cs +++ b/LibreMetaverse/ParcelManager.cs @@ -1738,7 +1738,7 @@ namespace OpenMetaverse AsyncHelper.Sync(() => Client.HttpCapsClient.GetRequestAsync( Client.Network.CurrentSim.Caps.CapabilityURI("ScriptResourceSummary"), CancellationToken.None, - (response, data, err) => summaryResponse = OSDParser.Deserialize(data))); + (response, respData, err) => summaryResponse = OSDParser.Deserialize(respData))); LandResourcesInfo resInfo = new LandResourcesInfo(); resInfo.Deserialize((OSDMap)summaryResponse); @@ -1749,7 +1749,7 @@ namespace OpenMetaverse AsyncHelper.Sync(() => Client.HttpCapsClient.GetRequestAsync( Client.Network.CurrentSim.Caps.CapabilityURI("ScriptResourceDetails"), CancellationToken.None, - (response, data, err) => detailResponse = OSDParser.Deserialize(data))); + (response, respData, err) => detailResponse = OSDParser.Deserialize(respData))); resInfo.Deserialize((OSDMap)detailResponse); } diff --git a/Programs/VoiceTest/VoiceTest.cs b/Programs/VoiceTest/VoiceTest.cs index 1e54c33a..16a54791 100644 --- a/Programs/VoiceTest/VoiceTest.cs +++ b/Programs/VoiceTest/VoiceTest.cs @@ -163,7 +163,7 @@ namespace VoiceTest catch(Exception e) { Console.WriteLine(e.Message); - if (e is VoiceException { LoggedIn: true } exception) + if (e is VoiceException exception && exception.LoggedIn) { client.Network.Logout(); } diff --git a/Programs/examples/TestClient/ClientManager.cs b/Programs/examples/TestClient/ClientManager.cs index 6c9acb97..f7766d94 100644 --- a/Programs/examples/TestClient/ClientManager.cs +++ b/Programs/examples/TestClient/ClientManager.cs @@ -113,7 +113,10 @@ namespace OpenMetaverse.TestClient } // Otherwise, use the center of the named region - account.StartLocation ??= NetworkManager.StartLocation(args[3], 128, 128, 40); + if (account.StartLocation == null) + { + account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40); + } } } @@ -137,8 +140,8 @@ namespace OpenMetaverse.TestClient { // Check if this client is already logged in foreach (var c in Clients.Values.Where( - client => client.Self.FirstName == account.FirstName - && client.Self.LastName == account.LastName)) + tc => tc.Self.FirstName == account.FirstName + && tc.Self.LastName == account.LastName)) { Logout(c); break; @@ -146,8 +149,10 @@ namespace OpenMetaverse.TestClient ++PendingLogins; - TestClient client = new TestClient(this); - client.Settings.MFA_ENABLED = true; + TestClient client = new TestClient(this) + { + Settings = { MFA_ENABLED = true } + }; client.Network.LoginProgress += delegate(object sender, LoginProgressEventArgs e) { diff --git a/Programs/examples/TestClient/Commands/Appearance/CloneCommand.cs b/Programs/examples/TestClient/Commands/Appearance/CloneCommand.cs index 4f5d58a3..50914244 100644 --- a/Programs/examples/TestClient/Commands/Appearance/CloneCommand.cs +++ b/Programs/examples/TestClient/Commands/Appearance/CloneCommand.cs @@ -9,7 +9,8 @@ namespace OpenMetaverse.TestClient public class CloneCommand : Command { uint _serialNum = 2; - readonly CacheDictionary Appearances = new(100, new LruRemovalStrategy()); + readonly CacheDictionary Appearances = + new CacheDictionary(100, new LruRemovalStrategy()); public CloneCommand(TestClient testClient) { diff --git a/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs b/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs index 49ac79ae..b119416b 100644 --- a/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs +++ b/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs @@ -111,7 +111,7 @@ namespace OpenMetaverse.TestClient if (!primDone.WaitOne(10000, false)) return "Rez failed, timed out while creating the root prim."; - Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[^1].LocalID, linkset.RootPrim.Position); + Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[primsCreated.Count - 1].LocalID, linkset.RootPrim.Position); state = ImporterState.RezzingChildren; @@ -126,7 +126,7 @@ namespace OpenMetaverse.TestClient if (!primDone.WaitOne(10000, false)) return "Rez failed, timed out while creating child prim."; - Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[^1].LocalID, currentPosition); + Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[primsCreated.Count - 1].LocalID, currentPosition); }