Network & Online Features

Project DVN

Contents


Networking API

DVN includes a high-level networking API that makes it easy to send, receive, and process custom data packets.

You can build lightweight communication, or full client-server architectures if needed.

To use sockets you simply use the NetworkSocket class.

public final class NetworkSocket
{
    public:
    final:
    this(void delegate(Throwable) errorHandler, void delegate(NetworkPacket) packetHandler = null);

    @property Socket socket() { return _socket; }

    @property bool isDisconnected() { return _disconnected; }

    void close();
    void send(NetworkPacket packet);
}

There is a helper function called handle if you need to have a simple packet handler in another thread.

NetworkSocket handle(string ip, ushort port, void delegate(Throwable) errorHandler, void delegate(NetworkPacket) packetHandler = null);

This will automatically handle packets using the following data format:

INT32 PACKET_ID;
INT32 PACKET_SIZE;
UINT8[PACKET_SIZE] DATA;

If you need to handle another format then you have to implement a handler for the socket yourself.

Using network packets

Network packets are small data containers designed for transferring structured information.

They can represent player choices, messages, game state, or anything else your design requires.

Examples:

  • Player decisions
  • Scene sync
  • Inventory or variable sync
  • Puzzle solutions
  • Custom commands

In DVN the default network packet uses the following format:

INT32 PACKET_ID;
INT32 PACKET_SIZE;
UINT8[PACKET_SIZE] DATA;

However you can implement your own data packet structures if needed.

There is a wrapper around data packets called NetworkPacket which the NetworkSocket class uses.

public class NetworkPacket
{
    public:
    final:
    this(NetworkPacket packet);
    this(ubyte[] buffer, Endian endian = Endian.bigEndian);
    this(int id, int size, Endian endian = Endian.bigEndian);

    Endian packetEndian() const { return _packetEndian; }
    void packetEndian(Endian e) { _packetEndian = e; }

    @property int packetId();
    @property int packetVirtualSize();
    @property int packetPhysicalSize();
    @property size_t offset();
    @property void offset(size_t newOffset);

    void writeStringUTF32(dstring value);
    void write(T)(T value) if (isIntegral!T || isFloatingPoint!T);
    void writeStringListUTF32(dstring[] list);
    void writeBuffer(ubyte[] value);
    void writeStaticBuffer(ubyte[] value);

    T read(T)() if (isIntegral!T || isFloatingPoint!T);
    dstring readStringUTF32();
    dstring[] readStringListUTF32();
    ubyte[] readBuffer();
    ubyte[] readStaticBuffer(int length);

    ubyte[] finalizePacket();
}

Online VNs

Online visual novels are no longer theoretical - DVN supports them directly.

Use cases:

  • Shared decisions (Telltale-style voting)
  • Live group playthroughs
  • Streaming audience participation
  • Synchronized storytelling between devices

Multiplayer logic

A DVN project can handle multiple connected clients, branching logic per user, or even competitive or cooperative narrative paths.

Server communication

DVN's networking layer is based on plain TCP sockets and a flexible packet system. It does not include built-in HTTPS, TLS/SSL, HTTP/2, or WebSocket support.

In practice, this means:

  • You can implement your own protocol on top of TCP.
  • You can talk to a custom server that you control (e.g. written in D, C#, Go, etc.).
  • Simple HTTP/1-style requests are possible if you implement the request/response formatting yourself.
  • If you need HTTPS, WebSockets, or modern REST APIs, you can:
    • use an external proxy/service that terminates TLS and forwards plain TCP/HTTP,
    • or build a small middleware server that DVN talks to over raw TCP.

This keeps the core engine lightweight and cross-platform, while still allowing advanced online features for projects that need them.

Why DVN Doesn't Bundle SSL/TLS or High-Level Web Protocols

DVN focuses on providing a clean and flexible low-level networking layer based on raw TCP sockets. It does not include built-in support for HTTPS, TLS/SSL, WebSockets, or HTTP/2.

This is a deliberate design choice for two major reasons:

Compatibility

Secure networking protocols and modern web stacks evolve quickly. Bundling these directly into the engine would create maintenance overhead, platform inconsistencies, and version lock-in - especially across desktop, mobile, and future platforms.

Security

Protocols like HTTPS and TLS require proper handling of:

  • encryption suites
  • certificate validation and trust chains
  • revocation and renewal
  • best-practice cryptographic configuration
  • compliance with constantly changing security standards

These responsibilities are best handled by dedicated, security-focused networking libraries, proxies, or backend services, not by a game/engine runtime.

How DVN Handles Networking Instead

DVN provides:

  • Raw TCP sockets
  • A packet system
  • Event-driven networking hooks
  • Full control over serialization and communication logic

This approach gives developers maximum flexibility - whether they're building:

  • LAN multiplayer games
  • custom protocols
  • lightweight online features
  • or integrating with external servers and services

If your project requires secure or web-style communication, DVN can be used alongside:

  • reverse proxies (NGINX / Caddy / HAProxy)
  • middleware servers
  • existing SSL/TLS-capable libraries
  • cloud services that terminate encryption and forward plain traffic

In short: DVN gives you the networking foundation - and leaves cryptography and web standards to tools that are purpose-built and security-audited for them.