Skip to content

Phira-mp + Project Overview

Project Structure

Phira-mp-plus/

├── Cargo.toml                   # Workspace root
├── Cargo.lock
├── LICENSE                      # AGPL-3.0
├── README.md

├── server_config.yml            # YAML config file (auto-generates default template on first run)
├── data/                        # Runtime data directory
│   ├── extensions.json          #   Plugin extension data persistence
│   ├── rounds/                  #   Round Touches/Judges records
│   └── plugins/                 #   Plugin private data
├── log/                         # Runtime logs (hourly rotation)

├── phira-mp-plus-server/        # Server core
│   ├── Cargo.toml               #   Dependencies: axum / tokio / wasmtime / clap etc.
│   ├── locales/                 #   Fluent i18n translation files
│   │   ├── en-US.ftl
│   │   ├── zh-CN.ftl
│   │   └── zh-TW.ftl
│   └── src/
│       ├── main.rs              #   Process entry and lifecycle
│       ├── logging.rs           #   Tracing output and log rotation
│       ├── terminal.rs          #   Terminal capability detection and Screen fallback strategy
│       ├── lib.rs               #   Module exports
│       ├── server.rs            #   Server core: PlusConfig / PlusServerState / PlusServer
│       │                        #     Accept loop, benchmark methods, state query dispatch
│       ├── session.rs           #   Session management: Session / User models, auth, command processing
│       │                        #     Touches/Judges data flow to plugin events + disk storage
│       ├── room.rs              #   Room state machine: InternalRoomState / Room
│       │                        #     Select→Ready→Play→Settlement, player real-time data cache
│       ├── plugin.rs            #   Plugin manager + WASM host: PluginManager / PluginHost trait
│       │                        #     Plugin loading, event dispatch, CLI/HTTP/API registration
│       ├── plugin_http.rs       #   HTTP service assembly and dynamic request dispatch
│       ├── plugin_http/
│       │   ├── router.rs        #   Dynamic route matching
│       │   ├── sse.rs           #   SSE event bus, snapshots and stream conversion
│       │   └── websocket.rs     #   Real-time WebSocket bridge
│       ├── wasm_host.rs         #   WASM runtime: wasmtime instance, JSON ABI, host/api bridge
│       ├── extensions.rs        #   Extension data system: user/room KV store + auth cache persistence
│       ├── ban.rs               #   Ban system: global bans + room blacklists
│       ├── round_store.rs       #   Round data storage: JSONL format, organized by round_uuid/player_id
│       ├── rate_limiter.rs      #   Rate limiting: sliding window (connections) + token bucket (commands)
│       ├── cli.rs               #   CLI command handler: 30+ management commands, plugin extension commands
│       ├── cli_tui.rs           #   TUI terminal interface: ratatui + crossterm
│       └── l10n.rs              #   Localization: Fluent Bundle / tl! macro

├── phira-mp-plus-server-api/    # WASM plugin shared types crate
│   └── src/lib.rs               #   PluginEvent / PluginInfo / HttpHandle
│                                #   ServerStateQuery / PluginApiHandler

├── phira-mp/                    # Upstream phira-mp submodule (protocol layer and original server)
│   ├── phira-mp-common/         #   Network protocol: binary encoding (BinaryData trait),
│   │   └── src/                 #     Command definitions (ClientCommand / ServerCommand),
│   │       ├── lib.rs           #     Stream frame protocol, RoomId / RoomState / message types
│   │       ├── command.rs
│   │       ├── bin.rs           #     BinaryReader / BinaryWriter (LEB128, little-endian)
│   │       └── framing.rs       #     Packet/Unpacket (VARINT length prefix)
│   ├── phira-mp-macros/         #   #[derive(BinaryData)] procedural macro
│   ├── phira-mp-server/         #   Original standalone server (reference)
│   └── phira-mp-client/         #   TCP client library (for game integration)

├── docs/                        # Local documentation
│   ├── cli.md                   #   CLI command reference
│   └── plugin-dev.md            #   WASM plugin development guide + WIT API reference

└── server_config.yml            # YAML config file (runtime copy)

Terminal Compatibility

On startup, the server detects stdin/stdout, TERM, STY, and TMUX. GNU Screen automatically switches to line-by-line compatible console, without colors, alternate screen, mouse capture, or Bracketed Paste; tmux can still use the full TUI. The project also follows NO_COLOR, and line-by-line output filters any remaining control sequences. Non-interactive environments also use the line-by-line console.

SSE Room Events

After connecting to GET /rooms/listen, the server first sends ready, then replays current room snapshots as update_room events, followed by continuous create_room, update_room, join_room, leave_room, and new_round events. Use the following command to inspect the data stream:

bash
curl -N http://127.0.0.1:12347/rooms/listen

Build Features

FeatureDescriptionDefault
plugin-systemWASM plugin support (wasmtime)Yes

Configuration Reference

See server_config.yml for the full configuration:

KeyTypeDefaultDescription
portu1612346TCP listen port
http_portu1612347HTTP/SSE service port
monitorsVec<i32>[2]Phira user IDs allowed to spectate
phira_api_endpointStringhttps://phira.5wyxi.comPhira API endpoint
plugins_dirStringpluginsPlugin directory
chat_enabledbooltrueChat feature toggle
cli_enabledbooltrueCLI console toggle
connection_rate_limitu3230Connection rate limit (allowed count per window)
connection_rate_windowu3210Connection rate stats window (seconds)
max_users_per_roomusize8Max players per room
round_data_retention_daysu327Round Touches/Judges retention days (0=no retention)
server_nameStringServer name

Last modified byFireflyF09on2026-06-26 16:11

Built with VitePress