GsDChat/README.md

8.6 KiB

GsDChat

A lightweight, secure, and private community chat platform built in pure C# (.NET 10) without external non-.NET libraries.

GsDChat provides a single-server architecture with SQLite persistence, dynamic DLL modding via AssemblyLoadContext, HTTPS/WSS and tunnel-ready HTTP/WS support, authenticated file transfers, and a server-driven screen-swapping Terminal User Interface (TUI).


Key Features

  • Pure .NET Architecture: Strict adherence to the standard .NET runtime and first-party Microsoft.Data.Sqlite. Zero native/unmanaged C/C++ third-party dependencies.
  • Flexible Network & Tunnel Support: Configurable direct HTTPS/WSS (with custom PFX/PEM certificates or self-signed certs) or plain HTTP/WS for running inside Docker containers behind Cloudflare Tunnels (cloudflared), Tailscale, or reverse proxies.
  • Screen-Swapping TUI Client: Built with ANSI escape codes and System.Console (zero third-party UI dependencies). Fast screen-swapping using function keys:
    • F1: Active Channel Chat (scrollable history, timestamps, role badges, file card indicators, bottom input box).
    • F2: Channel Browser (channel list, topics, active indicator, join and create channels).
    • F3: User Directory (member list, role tags, real-time online ● / offline ○ presence).
    • F4: Shared Files Browser (table of uploaded files, download to ./downloads/, upload from local path).
    • F5+: Mod-defined custom screens rendered dynamically from server layout schemas.
  • Dynamic Modding System: Place mod .dll files in ./mods/ to dynamically extend the server using AssemblyLoadContext:
    • Intercept and transform chat messages (e.g. shorthand emoji formatting :shrug:, word filters).
    • Register custom slash commands (e.g. /roll 2d6, /announce).
    • Subscribe to server lifecycle and entity events (UserConnected, ChannelCreated, FileUploaded).
    • Inject custom TUI screens or customize server MOTD.
  • Security & Authentication:
    • PBKDF2 with SHA-512 (100,000 iterations) and 256-bit cryptographically secure salt.
    • Constant-time verification preventing timing attacks.
    • 256-bit secure session tokens.
    • Optional server-wide password gate.
    • Role-based permissions (Owner, Admin, Member). First registered user automatically becomes the Server Owner.
  • Direct File Transfers: Authenticated multipart HTTPS uploads (POST /api/files/upload) and streaming downloads (GET /api/files/{id}) with SHA-256 integrity verification.

Project Structure

GsDChat/
├── GsDChat.slnx
├── src/
│   ├── GsDChat.Core/              # Shared models, crypto, and network/UI protocols
│   ├── GsDChat.Modding/           # Mod SDK: IMod, pipelines, command registry, event bus
│   ├── GsDChat.Server/            # ASP.NET Core Kestrel, SQLite DB, WebSockets, File REST
│   ├── GsDChat.Client/            # Pure C# screen-swapping TUI client
│   └── GsDChat.Mods.SampleBot/    # Reference mod: /roll, /announce, emoji transformer, F5 screen
└── tests/
    └── GsDChat.Tests/             # Comprehensive xUnit test suite (Unit, Integration, E2E)

Quick Start

1. Build Solution

dotnet build GsDChat.slnx

2. Run All Tests

dotnet test GsDChat.slnx

3. Run the Server

dotnet run --project src/GsDChat.Server

By default, the server runs on http://0.0.0.0:5000 with SQLite database in ./data/chat.db and loads any mod DLLs in ./mods/.

Server Configuration (serversettings.json / CLI flags)

You can edit src/GsDChat.Server/serversettings.json or pass command-line arguments:

{
  "Host": "0.0.0.0",
  "Port": 5000,
  "UseTls": false,
  "CertificatePath": "",
  "CertificatePassword": "",
  "ServerWidePassword": "",
  "RegistrationMode": "Open",
  "DataDirectory": "data",
  "MaxFileSizeMb": 50,
  "ServerName": "GsDChat Community Server",
  "Motd": "Welcome to GsDChat! Enjoy private and modular messaging."
}

CLI Overrides:

dotnet run --project src/GsDChat.Server -- --port 8080 --server-password "MySecretCommunityPassword"

Docker & Cloudflare Tunnel Deployment

Option A: Standard Docker Compose

  1. Copy .env.example to .env (already done by default) and customize variables:
    cp .env.example .env
    
  2. Start the container:
    docker compose up -d --build
    
    Data (database + files) is persisted in ./data/ and mods in ./mods/.

Option B: Built-in Cloudflare Tunnel (cloudflared)

This deploys GsDChat in an isolated container with zero open host ports, securely accessible globally via Cloudflare Tunnel.

  1. Create a tunnel in Cloudflare Zero Trust (Networks -> Tunnels -> Add a Tunnel).
  2. Copy the tunnel token into .env:
    CLOUDFLARE_TUNNEL_TOKEN=eyJh...
    
  3. In Cloudflare Zero Trust, configure the Public Hostname:
    • Service: HTTP
    • URL: gsdchat:5000
  4. Start both GsDChat and the cloudflared tunnel:
    docker compose -f docker-compose.tunnel.yml up -d --build
    

4. Run the Client TUI

Launch the client interactively:

dotnet run --project src/GsDChat.Client

When launched, GsDChat opens a user-friendly Server Selection Menu:

  • Displays a quick-access list of your recently visited servers and remembered usernames (like Discord server list).
  • Option [N] to connect to a new server URL or IP.
  • Option [D] to delete an entry from history.
  • Prompts for credentials (or uses saved username) and masked password.

Or connect directly via command-line arguments:

dotnet run --project src/GsDChat.Client -- --server https://chat.example.com --username Alice --password MyPassword123!

Zero-Install WebClient (Mobile & Desktop)

GsDChat includes a responsive, zero-install WebClient built with pure HTML5, CSS3, and JavaScript (served directly from the server's wwwroot/):

  • Access: Open http://<server-ip>:5000/ or your Cloudflare Tunnel URL in any browser.
  • Mobile Optimized: Designed specifically for phones and touchscreens with responsive navigation tabs, bottom chat bar, and native file pickers.
  • Offline / Private LAN Ready: 100% self-contained with zero external CDN dependencies.
  • Features: Real-time WebSocket messaging, channel switching, online user presence, authenticated file uploads, and downloads. Session tokens are remembered in browser storage.

Client TUI Navigation

Key Action
F1 Switch to Chat view
F2 Switch to Channels view
F3 Switch to Users directory view
F4 Switch to Files transfer view
F5 Switch to Server Status (SampleBot mod view)
Enter (on F1) Send message or run slash command
PageUp / PageDown Scroll message viewport up and down
Ctrl + C Exit client

Built-in & Mod Slash Commands

Type these directly in the chat input on F1:

  • /help — List available commands.
  • /join <channel> — Switch to a channel (e.g. /join general).
  • /create <name> [topic] — Create a new channel (Admin/Owner).
  • /upload <local_path> — Upload a file to the active channel.
  • /download <file_id> — Download a shared file to ./downloads/.
  • /roll [NdM] (SampleBot) — Roll dice (e.g. /roll 2d6, /roll 1d20).
  • /announce <text> (SampleBot) — Post an official broadcast announcement (Admin/Owner).
  • Text emoji shortcuts: :shrug: converts to ¯\_(ツ)_/¯, :tableflip: converts to (╯°□°)╯︵ ┻━┻, :heart: to ❤️.

Modding Guide

To create a custom mod:

  1. Create a class library targeting net10.0.
  2. Reference GsDChat.Modding.csproj.
  3. Implement IMod:
using GsDChat.Modding;

public class MyCustomMod : IMod
{
    public string Id => "com.example.mycustommod";
    public string Name => "My Custom Mod";
    public string Version => "1.0.0";
    public string Description => "Example custom mod for GsDChat";

    public Task InitializeAsync(IModContext context)
    {
        // Register a custom slash command
        context.Commands.RegisterCommand("ping", "Responds with pong", async cmdCtx =>
        {
            return CommandResult.Ok("🏓 Pong from custom mod!");
        });

        // Intercept messages
        context.Pipeline.Use(async (msgCtx, next) =>
        {
            // Inspect or modify msgCtx.Message.Content
            await next();
        });

        return Task.CompletedTask;
    }

    public Task ShutdownAsync() => Task.CompletedTask;
}
  1. Drop the built .dll into the server's ./mods/ directory and restart the server.

License

MIT License.