refactor: rename IEncodable to Encodable
This commit is contained in:
parent
c834921400
commit
3f85ced4bf
|
@ -47,7 +47,7 @@ namespace XIVChatCommon {
|
|||
return new SessionKeys(rx, tx);
|
||||
}
|
||||
|
||||
public async static Task<HandshakeInfo> ServerHandshake(KeyPair server, Stream stream) {
|
||||
public static async Task<HandshakeInfo> 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<HandshakeInfo> ClientHandshake(KeyPair client, Stream stream) {
|
||||
public static async Task<HandshakeInfo> ClientHandshake(KeyPair client, Stream stream) {
|
||||
// send our public key
|
||||
await stream.WriteAsync(client.PublicKey, 0, client.PublicKey.Length);
|
||||
|
||||
|
|
|
@ -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<ClientPreference, object> 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)]
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace XIVChatCommon {
|
|||
public static class SecretMessage {
|
||||
private const uint MaxMessageLen = 128_000;
|
||||
|
||||
public async static Task<byte[]> ReadSecretMessage(Stream s, byte[] key, CancellationToken token = default) {
|
||||
public static async Task<byte[]> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace XIVChatPlugin {
|
|||
|
||||
public CancellationTokenSource TokenSource { get; } = new();
|
||||
|
||||
public Channel<IEncodable> Queue { get; } = Channel.CreateUnbounded<IEncodable>();
|
||||
public Channel<Encodable> Queue { get; } = Channel.CreateUnbounded<Encodable>();
|
||||
|
||||
public void Disconnect() {
|
||||
this.Connected = false;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue