init
This commit is contained in:
commit
f25ba8adcd
64 changed files with 5959 additions and 0 deletions
48
src/GsDChat.Core/Protocol/HttpModels.cs
Normal file
48
src/GsDChat.Core/Protocol/HttpModels.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using GsDChat.Core.Models;
|
||||
|
||||
namespace GsDChat.Core.Protocol;
|
||||
|
||||
public class RegisterRequest
|
||||
{
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string? ServerPassword { get; set; }
|
||||
public string? InviteToken { get; set; }
|
||||
}
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string? ServerPassword { get; set; }
|
||||
}
|
||||
|
||||
public class AuthResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string? Token { get; set; }
|
||||
public string? UserId { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Role { get; set; }
|
||||
public string? ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
public class ServerInfoResponse
|
||||
{
|
||||
public string ServerName { get; set; } = "GsDChat Server";
|
||||
public string Version { get; set; } = "1.0.0";
|
||||
public string RegistrationMode { get; set; } = "Open"; // Open or InviteOnly
|
||||
public bool RequiresServerPassword { get; set; }
|
||||
public string Motd { get; set; } = "Welcome to GsDChat!";
|
||||
public long MaxFileSizeMb { get; set; } = 50;
|
||||
}
|
||||
|
||||
public class UploadFileResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string? FileId { get; set; }
|
||||
public string? FileName { get; set; }
|
||||
public long FileSizeBytes { get; set; }
|
||||
public string? ChannelId { get; set; }
|
||||
public string? ErrorMessage { get; set; }
|
||||
}
|
||||
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;
|
||||
}
|
||||
108
src/GsDChat.Core/Protocol/UiProtocol.cs
Normal file
108
src/GsDChat.Core/Protocol/UiProtocol.cs
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace GsDChat.Core.Protocol;
|
||||
|
||||
public class PanelDefinition
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Position { get; set; } = "Center"; // Top, Center, Bottom, Left, Right
|
||||
public int? Height { get; set; }
|
||||
public int? Width { get; set; }
|
||||
public bool ShowBorder { get; set; } = true;
|
||||
public string? BorderTitle { get; set; }
|
||||
public string? ContentTemplate { get; set; }
|
||||
}
|
||||
|
||||
public class ScreenDefinition
|
||||
{
|
||||
public string ScreenId { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string ShortcutKey { get; set; } = string.Empty; // e.g. F1, F2, F3, F4, F5
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public List<PanelDefinition> Panels { get; set; } = new();
|
||||
}
|
||||
|
||||
public class ThemeDefinition
|
||||
{
|
||||
public string PrimaryColor { get; set; } = "Cyan";
|
||||
public string SecondaryColor { get; set; } = "DarkCyan";
|
||||
public string BorderColor { get; set; } = "DarkGray";
|
||||
public string HighlightColor { get; set; } = "Yellow";
|
||||
public string ErrorColor { get; set; } = "Red";
|
||||
public string SuccessColor { get; set; } = "Green";
|
||||
public string TextMutedColor { get; set; } = "Gray";
|
||||
public string SystemNoticeColor { get; set; } = "Magenta";
|
||||
}
|
||||
|
||||
public class ServerUiSync
|
||||
{
|
||||
public string ServerName { get; set; } = "GsDChat Server";
|
||||
public string Motd { get; set; } = "Welcome to GsDChat!";
|
||||
public ThemeDefinition Theme { get; set; } = new();
|
||||
public List<ScreenDefinition> Screens { get; set; } = new();
|
||||
|
||||
public static ServerUiSync CreateDefault(string serverName = "GsDChat Server", string motd = "Welcome to GsDChat!")
|
||||
{
|
||||
return new ServerUiSync
|
||||
{
|
||||
ServerName = serverName,
|
||||
Motd = motd,
|
||||
Theme = new ThemeDefinition(),
|
||||
Screens = new List<ScreenDefinition>
|
||||
{
|
||||
new()
|
||||
{
|
||||
ScreenId = "F1_Chat",
|
||||
Title = "Chat",
|
||||
ShortcutKey = "F1",
|
||||
Description = "Active Channel Chat View",
|
||||
Panels = new List<PanelDefinition>
|
||||
{
|
||||
new() { Name = "Header", Position = "Top", Height = 3, ShowBorder = true, BorderTitle = "Channel Info" },
|
||||
new() { Name = "Messages", Position = "Center", ShowBorder = true, BorderTitle = "Messages" },
|
||||
new() { Name = "Input", Position = "Bottom", Height = 3, ShowBorder = true, BorderTitle = "Message Input" }
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
ScreenId = "F2_Channels",
|
||||
Title = "Channels",
|
||||
ShortcutKey = "F2",
|
||||
Description = "Browse and switch chat channels",
|
||||
Panels = new List<PanelDefinition>
|
||||
{
|
||||
new() { Name = "Header", Position = "Top", Height = 3, ShowBorder = true, BorderTitle = "Channels Browser" },
|
||||
new() { Name = "ChannelList", Position = "Center", ShowBorder = true, BorderTitle = "Available Channels" },
|
||||
new() { Name = "Help", Position = "Bottom", Height = 3, ShowBorder = true, BorderTitle = "Navigation" }
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
ScreenId = "F3_Users",
|
||||
Title = "Users",
|
||||
ShortcutKey = "F3",
|
||||
Description = "User directory and online presence",
|
||||
Panels = new List<PanelDefinition>
|
||||
{
|
||||
new() { Name = "Header", Position = "Top", Height = 3, ShowBorder = true, BorderTitle = "Community Members" },
|
||||
new() { Name = "UserList", Position = "Center", ShowBorder = true, BorderTitle = "Members Directory" },
|
||||
new() { Name = "Help", Position = "Bottom", Height = 3, ShowBorder = true, BorderTitle = "Commands" }
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
ScreenId = "F4_Files",
|
||||
Title = "Files",
|
||||
ShortcutKey = "F4",
|
||||
Description = "Shared files and download browser",
|
||||
Panels = new List<PanelDefinition>
|
||||
{
|
||||
new() { Name = "Header", Position = "Top", Height = 3, ShowBorder = true, BorderTitle = "Shared Files" },
|
||||
new() { Name = "FileList", Position = "Center", ShowBorder = true, BorderTitle = "Available Files" },
|
||||
new() { Name = "Actions", Position = "Bottom", Height = 3, ShowBorder = true, BorderTitle = "Transfer Commands" }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue