From 3f85ced4bfbd5b16ff34cbc006bd7edb9e6abf1b Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 16 Feb 2021 19:50:36 -0500 Subject: [PATCH] refactor: rename IEncodable to Encodable --- XIVChatCommon/KeyExchange.cs | 4 ++-- XIVChatCommon/Message/Client/Client.cs | 16 ++++++++-------- XIVChatCommon/Message/Message.cs | 3 ++- XIVChatCommon/Message/Server/Server.cs | 18 +++++++++--------- XIVChatCommon/SecretMessage.cs | 6 +++--- XIVChatPlugin/Client.cs | 2 +- XIVChatPlugin/Server.cs | 6 +++--- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/XIVChatCommon/KeyExchange.cs b/XIVChatCommon/KeyExchange.cs index 9d02de8..dae057b 100644 --- a/XIVChatCommon/KeyExchange.cs +++ b/XIVChatCommon/KeyExchange.cs @@ -47,7 +47,7 @@ namespace XIVChatCommon { return new SessionKeys(rx, tx); } - public async static Task ServerHandshake(KeyPair server, Stream stream) { + public static async Task ServerHandshake(KeyPair server, Stream stream) { // get client public key byte[] clientPublic = new byte[32]; await stream.ReadAsync(clientPublic, 0, clientPublic.Length); @@ -62,7 +62,7 @@ namespace XIVChatCommon { return new HandshakeInfo(clientPublic, keys); } - public async static Task ClientHandshake(KeyPair client, Stream stream) { + public static async Task ClientHandshake(KeyPair client, Stream stream) { // send our public key await stream.WriteAsync(client.PublicKey, 0, client.PublicKey.Length); diff --git a/XIVChatCommon/Message/Client/Client.cs b/XIVChatCommon/Message/Client/Client.cs index 2cbaed2..3ccf69b 100644 --- a/XIVChatCommon/Message/Client/Client.cs +++ b/XIVChatCommon/Message/Client/Client.cs @@ -18,7 +18,7 @@ namespace XIVChatCommon.Message.Client { #region Ping - public class Ping : IEncodable { + public class Ping : Encodable { public static Ping Instance { get; } = new(); [IgnoreMember] @@ -34,7 +34,7 @@ namespace XIVChatCommon.Message.Client { #region Message [MessagePackObject] - public class ClientMessage : IEncodable { + public class ClientMessage : Encodable { [Key(0)] public string Content { get; set; } @@ -58,7 +58,7 @@ namespace XIVChatCommon.Message.Client { #region Shutdown - public class ClientShutdown : IEncodable { + public class ClientShutdown : Encodable { public static ClientShutdown Instance { get; } = new(); [IgnoreMember] @@ -74,7 +74,7 @@ namespace XIVChatCommon.Message.Client { #region Backlog/catch-up [MessagePackObject] - public class ClientBacklog : IEncodable { + public class ClientBacklog : Encodable { [Key(0)] public ushort Amount { get; set; } @@ -90,7 +90,7 @@ namespace XIVChatCommon.Message.Client { } [MessagePackObject] - public class ClientCatchUp : IEncodable { + public class ClientCatchUp : Encodable { [MessagePackFormatter(typeof(MillisecondsDateTimeFormatter))] [Key(0)] public DateTime After { get; set; } @@ -115,7 +115,7 @@ namespace XIVChatCommon.Message.Client { #region Player list [MessagePackObject] - public class ClientPlayerList : IEncodable { + public class ClientPlayerList : Encodable { [Key(0)] public PlayerListType Type { get; set; } @@ -135,7 +135,7 @@ namespace XIVChatCommon.Message.Client { #region Preferences [MessagePackObject] - public class ClientPreferences : IEncodable { + public class ClientPreferences : Encodable { [Key(0)] public Dictionary Preferences { get; set; } = new(); @@ -190,7 +190,7 @@ namespace XIVChatCommon.Message.Client { #region Channel [MessagePackObject] - public class ClientChannel : IEncodable { + public class ClientChannel : Encodable { protected override byte Code => (byte) ClientOperation.Channel; [Key(0)] diff --git a/XIVChatCommon/Message/Message.cs b/XIVChatCommon/Message/Message.cs index a5f4eb6..49fb6ae 100644 --- a/XIVChatCommon/Message/Message.cs +++ b/XIVChatCommon/Message/Message.cs @@ -725,7 +725,8 @@ namespace XIVChatCommon.Message { Online = 47, } - public abstract class IEncodable { + // ReSharper disable once IdentifierTypo + public abstract class Encodable { protected abstract byte Code { get; } protected abstract byte[] PayloadEncode(); diff --git a/XIVChatCommon/Message/Server/Server.cs b/XIVChatCommon/Message/Server/Server.cs index 814e2b9..8261bec 100644 --- a/XIVChatCommon/Message/Server/Server.cs +++ b/XIVChatCommon/Message/Server/Server.cs @@ -20,7 +20,7 @@ namespace XIVChatCommon.Message.Server { #region Pong - public class Pong : IEncodable { + public class Pong : Encodable { public static Pong Instance { get; } = new(); [IgnoreMember] @@ -36,7 +36,7 @@ namespace XIVChatCommon.Message.Server { #region Message [MessagePackObject] - public class ServerMessage : IEncodable { + public class ServerMessage : Encodable { [MessagePackFormatter(typeof(MillisecondsDateTimeFormatter))] [Key(0)] public DateTime Timestamp { get; set; } @@ -201,7 +201,7 @@ namespace XIVChatCommon.Message.Server { #region Shutdown - public class ServerShutdown : IEncodable { + public class ServerShutdown : Encodable { public static ServerShutdown Instance { get; } = new(); [IgnoreMember] @@ -217,7 +217,7 @@ namespace XIVChatCommon.Message.Server { #region Player data [MessagePackObject] - public class PlayerData : IEncodable { + public class PlayerData : Encodable { [Key(0)] public readonly string homeWorld; @@ -250,7 +250,7 @@ namespace XIVChatCommon.Message.Server { } [MessagePackObject] - public class EmptyPlayerData : IEncodable { + public class EmptyPlayerData : Encodable { public static EmptyPlayerData Instance { get; } = new(); [IgnoreMember] @@ -266,7 +266,7 @@ namespace XIVChatCommon.Message.Server { #region Availability [MessagePackObject] - public class Availability : IEncodable { + public class Availability : Encodable { [Key(0)] public readonly bool available; @@ -291,7 +291,7 @@ namespace XIVChatCommon.Message.Server { #region Channel [MessagePackObject] - public class ServerChannel : IEncodable { + public class ServerChannel : Encodable { [Key(0)] public readonly byte channel; @@ -324,7 +324,7 @@ namespace XIVChatCommon.Message.Server { #region Backlog [MessagePackObject] - public class ServerBacklog : IEncodable { + public class ServerBacklog : Encodable { [Key(0)] public readonly ServerMessage[] messages; @@ -348,7 +348,7 @@ namespace XIVChatCommon.Message.Server { #region Player list [MessagePackObject] - public class ServerPlayerList : IEncodable { + public class ServerPlayerList : Encodable { [Key(0)] public PlayerListType Type { get; set; } diff --git a/XIVChatCommon/SecretMessage.cs b/XIVChatCommon/SecretMessage.cs index 9f7cf57..c9144fa 100644 --- a/XIVChatCommon/SecretMessage.cs +++ b/XIVChatCommon/SecretMessage.cs @@ -10,7 +10,7 @@ namespace XIVChatCommon { public static class SecretMessage { private const uint MaxMessageLen = 128_000; - public async static Task ReadSecretMessage(Stream s, byte[] key, CancellationToken token = default) { + public static async Task ReadSecretMessage(Stream s, byte[] key, CancellationToken token = default) { var read = 0; byte[] header = new byte[4 + 24]; @@ -34,7 +34,7 @@ namespace XIVChatCommon { return SecretBox.Open(ciphertext, nonce, key); } - public async static Task SendSecretMessage(Stream s, byte[] key, byte[] message, CancellationToken token = default) { + public static async Task SendSecretMessage(Stream s, byte[] key, byte[] message, CancellationToken token = default) { byte[] nonce = SecretBox.GenerateNonce(); byte[] ciphertext = SecretBox.Create(message, nonce, key); byte[] len = BitConverter.GetBytes((uint)ciphertext.Length); @@ -49,7 +49,7 @@ namespace XIVChatCommon { await s.FlushAsync(token); } - public static async Task SendSecretMessage(Stream s, byte[] key, IEncodable message, CancellationToken token = default) { + public static async Task SendSecretMessage(Stream s, byte[] key, Encodable message, CancellationToken token = default) { await SendSecretMessage(s, key, message.Encode(), token); } diff --git a/XIVChatPlugin/Client.cs b/XIVChatPlugin/Client.cs index b79be84..f0cd0f8 100644 --- a/XIVChatPlugin/Client.cs +++ b/XIVChatPlugin/Client.cs @@ -24,7 +24,7 @@ namespace XIVChatPlugin { public CancellationTokenSource TokenSource { get; } = new(); - public Channel Queue { get; } = Channel.CreateUnbounded(); + public Channel Queue { get; } = Channel.CreateUnbounded(); public void Disconnect() { this.Connected = false; diff --git a/XIVChatPlugin/Server.cs b/XIVChatPlugin/Server.cs index 3e66171..19ef9af 100644 --- a/XIVChatPlugin/Server.cs +++ b/XIVChatPlugin/Server.cs @@ -238,7 +238,7 @@ namespace XIVChatPlugin { continue; } - var playerData = (IEncodable?) this.GeneratePlayerData() ?? EmptyPlayerData.Instance; + var playerData = (Encodable?) this.GeneratePlayerData() ?? EmptyPlayerData.Instance; client.Queue.Writer.TryWrite(playerData); } @@ -711,7 +711,7 @@ namespace XIVChatPlugin { return parts.ToArray(); } - private void BroadcastMessage(IEncodable message) { + private void BroadcastMessage(Encodable message) { foreach (var client in this.Clients.Values) { client.Queue.Writer.TryWrite(message); } @@ -780,7 +780,7 @@ namespace XIVChatPlugin { } private void BroadcastPlayerData() { - var playerData = (IEncodable?) this.GeneratePlayerData() ?? EmptyPlayerData.Instance; + var playerData = (Encodable?) this.GeneratePlayerData() ?? EmptyPlayerData.Instance; this.BroadcastMessage(playerData); }