Skip to content

cpp-phira-mp ​

A C++ version of phira-mp rebuilt from phira-mp, with new features including Web admin panel, REST API, SSE real-time events, ban system, spectator system adaptation, and connection welcome messages.

Features ​

1. Web Admin Panel (Password Protected) ​

  • Access via browser at http://server-ip:12347/admin (by default)
  • Login Authentication: Default password is admin on first run, please change it immediately
  • View all room lists, room status, player counts and lists
  • Real-time refresh (auto-updates every 5 seconds)
  • One-click disband any room
  • One-click kick any player from a room
  • Ban/unban player IDs (banned players see "You have been banned" on connection)
  • Ban list persists in banned_users.json

2. API ​

EndpointDescription
GET /api/rooms/infoGet all room lists and full data
GET /api/rooms/info/<n>Get info for a room by name
GET /api/rooms/user/<user_id>Get room info for a specific user
GET /api/rooms/listenSSE real-time event stream

SSE Event Types ​

EventDescription
keepaliveKeep connection alive
create_roomNew room created
update_roomRoom data updated (state, chart, lock, cycle, etc.)
join_roomUser joined a room
leave_roomUser left a room
player_scorePlayer finished a game (includes full score record)
start_roundRoom started a new round

SSE connections have a built-in 15-second keepalive mechanism to prevent disconnection by middleware or firewalls.

3. This program can be used with the Phira Spectator Implementation for spectating. ​

4. Connection Welcome Messages ​

  • Automatically sends a welcome message after user authentication succeeds
  • Displays the current list of joinable rooms (only shows rooms that are selecting charts and unlocked)

Pre-build Setup ​

bash
# Update package list
sudo apt update

# Install build tools and dependencies
sudo apt install -y build-essential g++ curl pkg-config uuid-dev libsqlite3-dev zlib1g-dev libssl-dev libboost-dev libspdlog-dev libargon2-dev libfmt-dev nlohmann-json3-dev libcurl4-openssl-dev make

Required Dependencies ​

DependencyUbuntu PackagePurpose
G++ (>=10)build-essential / g++C++20 compiler
uuid-devuuid-devUUID generation
curlcurlHTTP requests (fetch Phira API data)
makebuild-essentialBuild tool
pkg-configpkg-configBuild tool
Boostlibboost-devRequired dependency
spdloglibspdlog-devLogging level implementation
Argon2libargon2-devBinary protocol
Json3nlohmann-json3-devJSON handling
SQLite3libsqlite3-devUser ID database implementation
Curl-OpenSSLlibcurl4-openssl-devCurl and OpenSSL implementation
OpenSSLlibssl-devSSL support

Build ​

bash
cd cpp-phira-mp
make clean
make -j$(nproc)

A successful build generates the phira-mp-server executable.


Download ​

You can visit the project's GitHub Actions to download pre-compiled executables and startup scripts. (Run with ./start.sh).


Running ​

bash
# Run with default ports (game port: 12346, Web/api port: 12347, admin password: admin)
./phira-mp-server

# Custom ports
./phira-mp-server --port 12346 --http-port 12347 --admin-password PASSWORD

Command Line Arguments ​

ArgumentDescriptionDefault
--portGame server port12346
--http-portWeb admin/API port12347
--admin-passwordAdmin panel passwordadmin
--db-pathSet database .db file pathvisitors.db
-h, --helpShow help-

File Structure ​

cpp-phira-mp-main/
├── include/
│   ├── binary.hpp          # Binary protocol
│   ├── command.hpp         # Command definitions
│   ├── http_server.hpp     # HTTP server
│   ├── l10n.hpp            # Localization
│   ├── room.hpp            # Room + round history
│   ├── server.hpp          # Server + get_state()
│   ├── session.hpp         # Session
│   ├── stream.hpp          # Touch info stream
│   ├── visitor_db.hpp      # Visitor count recording
├── src/
│   ├── binary.cpp          # Binary protocol implementation
│   ├── command.cpp         # Command implementation
│   ├── http_server.cpp     # Web page/API implementation
│   ├── l10n.cpp            # Localization implementation
│   ├── main.cpp            # Main entry point
│   ├── room.cpp            # Core logic implementation
│   ├── server.cpp          # Server
│   ├── session.cpp         # Core logic implementation
│   ├── visitor_db.cpp      # Visitor count recording
│   └── stream.cpp          # Spectator protocol
│   
├── locales/
│   ├── en-US.ftl
│   ├── zh-CN.ftl
│   └── zh-TW.ftl
├── Makefile
├── CMakeLists.txt
└── README.md

Runtime Files ​

  • banned_user.json — Banned player ID list (auto-created/managed)

API Usage Examples ​

bash
# Get all rooms
curl http://localhost:12345/api/rooms/info

# Get a specific room
curl http://localhost:12345/api/rooms/info/my-room

# Get the room a user is in
curl http://localhost:12345/api/rooms/user/12345

# Listen to real-time events (SSE)
curl http://localhost:12345/api/rooms/listen

QQ Group ​

1049578201

License ​

Licensed under the MIT license.


Last modified byFireflyF09on2026-06-26 15:41

Built with VitePress