# ZNet

Event-driven UDP networking library for multiplayer games, built on top of
libsst-net and enet.

## Architecture

- `ZNetServer` -- listens for connections, manages multiple peers
- `ZNetClient` -- connects to a single server
- `ZNetHost` -- shared base class for both
- `ZNetPeer` -- represents a remote connection

## Packet delivery

Packets are created with `ZNetHost::CreatePacket()` and sent with either
reliable or transient (fire-and-forget) delivery:

- `ZNET_RELIABLE` -- guaranteed delivery with sequencing and ACK
- `ZNET_TRANSIENT` -- unreliable, lowest latency

Packets larger than MTU are automatically fragmented and reassembled.

## Events

Poll with `HasEvent()` / `GetNextEvent()`:

| Event | Meaning |
|---|---|
| `ZNETEVENT_CONNECT` | Peer connected |
| `ZNETEVENT_DISCONNECT` | Peer disconnected gracefully |
| `ZNETEVENT_TIMEOUT` | Peer timed out |
| `ZNETEVENT_DATA` | Data packet received |

## Features

- Bandwidth throttling (token bucket) via `ZNetBandwidthMeter`
- Configurable MTU (512 -- 1500 bytes, with IPv4/IPv6 safe defaults)
- Packet loss simulation for testing (`SetDropChance`)
- Connection validation callback on server (`ZNetConnectCallback`)
- Up to 4 listen sockets per server
- Reference-counted packets
- `ZNetUtil::ReaderForPacket()` / `WriterForPacket()` for easy serialization
