2023-04-03 11:04:31 +08:00

241 lines
6.6 KiB
C#

using System;
using System.Net;
namespace BF
{
internal enum CommandCategory
{
RecycleMessage,
ReadMessage,
SendRaw,
SendMessage,
CreateMessage,
GetConnectStatus,
Close,
Reconnect,
ConnectIPAddress,
ConnectDomainName,
Shutdown,
GetServerTimestamp,
//temporary
GetConnectIP,
}
internal abstract class BaseCommandMethod
{
public abstract CommandCategory Command { get; }
public abstract void ResetMethod();
}
internal class RecycleMessageMethod : BaseCommandMethod
{
public static readonly RecycleMessageMethod DefaultInstance = new RecycleMessageMethod();
public override CommandCategory Command => CommandCategory.RecycleMessage;
public string UniqueIdentifier { get; set; }
public INetIncomingMessage Message { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
}
}
internal class ReadMessageMethod : BaseCommandMethod
{
public static readonly ReadMessageMethod DefaultInstance = new ReadMessageMethod();
public override CommandCategory Command => CommandCategory.ReadMessage;
public string UniqueIdentifier { get; set; }
public INetIncomingMessage Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
Result = null;
}
}
internal class SendRawMethod : BaseCommandMethod
{
public static readonly SendRawMethod DefaultInstance = new SendRawMethod();
public override CommandCategory Command => CommandCategory.SendRaw;
public string UniqueIdentifier { get; set; }
public uint Group{ get; set; }
public byte CMD{ get; set; }
public byte[] Data{ get; set; }
public NetSendResult Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
Result = NetSendResult.FailedNotConnected;
}
}
internal class SendMessageMethod : BaseCommandMethod
{
public static readonly SendMessageMethod DefaultInstance = new SendMessageMethod();
public override CommandCategory Command => CommandCategory.SendMessage;
public string UniqueIdentifier { get; set; }
public INetOutgoingMessage Message { get; set; }
public NetSendResult Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
Result = NetSendResult.FailedNotConnected;
}
}
internal class CreateMessageMethod : BaseCommandMethod
{
public static readonly CreateMessageMethod DefaultInstance = new CreateMessageMethod();
public override CommandCategory Command => CommandCategory.CreateMessage;
public string UniqueIdentifier { get; set; }
public INetOutgoingMessage Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
Result = null;
}
}
internal class GetConnectStatusMethod : BaseCommandMethod
{
public static readonly GetConnectStatusMethod DefaultInstance = new GetConnectStatusMethod();
public override CommandCategory Command => CommandCategory.GetConnectStatus;
public string UniqueIdentifier { get; set; }
public NetConnectStatus Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = string.Empty;
Result = NetConnectStatus.InvalidConnect;
}
}
internal class GetConnectIPMethod : BaseCommandMethod
{
public static readonly GetConnectIPMethod DefaultInstance = new GetConnectIPMethod();
public override CommandCategory Command => CommandCategory.GetConnectIP;
public string UniqueIdentifier { get; set; }
public string Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = string.Empty;
Result = string.Empty;
}
}
internal class GetConnectServerTimestampMethod : BaseCommandMethod
{
public static readonly GetConnectServerTimestampMethod DefaultInstance = new GetConnectServerTimestampMethod();
public override CommandCategory Command => CommandCategory.GetServerTimestamp;
public string UniqueIdentifier { get; set; }
public long Result { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = string.Empty;
Result = 0;
}
}
internal class CloseMethod : BaseCommandMethod
{
public static readonly CloseMethod DefaultInstance = new CloseMethod();
public override CommandCategory Command => CommandCategory.Close;
public string UniqueIdentifier { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
}
}
internal class ReconnectMethod : BaseCommandMethod
{
public static readonly ReconnectMethod DefaultInstance = new ReconnectMethod();
public override CommandCategory Command => CommandCategory.Reconnect;
public string UniqueIdentifier { get; set; }
public override void ResetMethod()
{
UniqueIdentifier = String.Empty;
}
}
internal class ConnectIPAddressMethod : BaseCommandMethod
{
public static readonly ConnectIPAddressMethod DefaultInstance = new ConnectIPAddressMethod();
public override CommandCategory Command => CommandCategory.ConnectIPAddress;
public NetConnectConfiguration Configuration { get; set; }
public IPAddress IpAddress{ get; set; }
public int Port{ get; set; }
public override void ResetMethod()
{
}
}
internal class ConnectDomainNameMethod : BaseCommandMethod
{
public static readonly ConnectDomainNameMethod DefaultInstance = new ConnectDomainNameMethod();
public override CommandCategory Command => CommandCategory.ConnectDomainName;
public NetConnectConfiguration Configuration{ get; set; }
public string DomainName{ get; set; }
public int Port{ get; set; }
public override void ResetMethod()
{
}
}
internal class ShutdownMethod : BaseCommandMethod
{
public static readonly ShutdownMethod DefaultInstance = new ShutdownMethod();
public override CommandCategory Command => CommandCategory.Shutdown;
public override void ResetMethod()
{
}
}
}