init
This commit is contained in:
commit
f25ba8adcd
64 changed files with 5959 additions and 0 deletions
157
src/GsDChat.Core/Protocol/NetworkMessages.cs
Normal file
157
src/GsDChat.Core/Protocol/NetworkMessages.cs
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using GsDChat.Core.Models;
|
||||
|
||||
namespace GsDChat.Core.Protocol;
|
||||
|
||||
public static class MessageTypes
|
||||
{
|
||||
public const string Auth = "AUTH";
|
||||
public const string AuthResult = "AUTH_RESULT";
|
||||
public const string UiSync = "UI_SYNC";
|
||||
public const string SendMessage = "SEND_MESSAGE";
|
||||
public const string MessageBroadcast = "MESSAGE_BROADCAST";
|
||||
public const string HistorySync = "HISTORY_SYNC";
|
||||
public const string JoinChannel = "JOIN_CHANNEL";
|
||||
public const string ChannelListSync = "CHANNEL_LIST_SYNC";
|
||||
public const string CreateChannel = "CREATE_CHANNEL";
|
||||
public const string DeleteChannel = "DELETE_CHANNEL";
|
||||
public const string UserListSync = "USER_LIST_SYNC";
|
||||
public const string FileListSync = "FILE_LIST_SYNC";
|
||||
public const string SystemNotice = "SYSTEM_NOTICE";
|
||||
public const string Error = "ERROR";
|
||||
public const string ExecuteCommand = "EXECUTE_COMMAND";
|
||||
public const string CommandResult = "COMMAND_RESULT";
|
||||
public const string Ping = "PING";
|
||||
public const string Pong = "PONG";
|
||||
}
|
||||
|
||||
public class NetworkEnvelope
|
||||
{
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string Payload { get; set; } = "{}";
|
||||
|
||||
public static NetworkEnvelope Create<T>(string type, T payload)
|
||||
{
|
||||
return new NetworkEnvelope
|
||||
{
|
||||
Type = type,
|
||||
Payload = JsonSerializer.Serialize(payload)
|
||||
};
|
||||
}
|
||||
|
||||
public T? Unpack<T>()
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(Payload);
|
||||
}
|
||||
}
|
||||
|
||||
public class AuthPacket
|
||||
{
|
||||
public string Token { get; set; } = string.Empty;
|
||||
public string? ServerPassword { get; set; }
|
||||
}
|
||||
|
||||
public class AuthResultPacket
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Role { get; set; } = UserRoles.Member;
|
||||
public string? ErrorMessage { get; set; }
|
||||
public ServerUiSync? UiSync { get; set; }
|
||||
public string? ActiveChannelId { get; set; }
|
||||
}
|
||||
|
||||
public class SendMessagePacket
|
||||
{
|
||||
public string ChannelId { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class MessageBroadcastPacket
|
||||
{
|
||||
public ChatMessage Message { get; set; } = new();
|
||||
}
|
||||
|
||||
public class HistorySyncPacket
|
||||
{
|
||||
public string ChannelId { get; set; } = string.Empty;
|
||||
public List<ChatMessage> Messages { get; set; } = new();
|
||||
}
|
||||
|
||||
public class JoinChannelPacket
|
||||
{
|
||||
public string ChannelId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ChannelListSyncPacket
|
||||
{
|
||||
public List<Channel> Channels { get; set; } = new();
|
||||
public string ActiveChannelId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class CreateChannelPacket
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Topic { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class DeleteChannelPacket
|
||||
{
|
||||
public string ChannelId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class UserSummary
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Role { get; set; } = UserRoles.Member;
|
||||
public bool IsOnline { get; set; }
|
||||
}
|
||||
|
||||
public class UserListSyncPacket
|
||||
{
|
||||
public List<UserSummary> Users { get; set; } = new();
|
||||
}
|
||||
|
||||
public class FileSummary
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string ChannelId { get; set; } = string.Empty;
|
||||
public string OriginalFileName { get; set; } = string.Empty;
|
||||
public string ContentType { get; set; } = string.Empty;
|
||||
public long FileSizeBytes { get; set; }
|
||||
public string UploaderUsername { get; set; } = string.Empty;
|
||||
public System.DateTime CreatedAt { get; set; }
|
||||
}
|
||||
|
||||
public class FileListSyncPacket
|
||||
{
|
||||
public List<FileSummary> Files { get; set; } = new();
|
||||
}
|
||||
|
||||
public class SystemNoticePacket
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Level { get; set; } = "Info"; // Info, Warning, Success
|
||||
}
|
||||
|
||||
public class ErrorPacket
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public string? Code { get; set; }
|
||||
}
|
||||
|
||||
public class ExecuteCommandPacket
|
||||
{
|
||||
public string Command { get; set; } = string.Empty;
|
||||
public string Args { get; set; } = string.Empty;
|
||||
public string ChannelId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class CommandResultPacket
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Output { get; set; } = string.Empty;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue