-
Notifications
You must be signed in to change notification settings - Fork 1.1k
HTTP server info handler #4964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
HTTP server info handler #4964
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new HTTP serverinfo endpoint that returns server status in JSON, updates build scripts to support optional MySQL/MariaDB selection, and removes hardcoded default vcpkg features.
- Introduces
handle_serverinfohandler with JSON response - Integrates handler into the HTTP router and exposes server start time via
serverStart() - Updates CMake and
vcpkg.jsonto drive features via CMake options instead of manifest defaults
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| vcpkg.json | Removed default-features block; features now driven by CMake |
| src/http/serverinfo.h/.cpp | Added new handler and JSON construction for /serverinfo |
| src/http/router.cpp | Registered serverinfo route |
| src/http/http.h/.cpp | Exposed serverStart() and captured start time |
| src/http/CMakeLists.txt | Included serverinfo sources |
| CMakeLists.txt | Introduced USE_LIBMYSQL option and feature-based logic |
Comments suppressed due to low confidence (5)
vcpkg.json:58
- Removing the
default-featuressection can disable core features (lua, http, libmariadb) by default. Consider restoring it or mirroring those features via the manifest fields controlled by CMake options to avoid build breakage.
"builtin-baseline": "0cf34c184ce990471435b5b9c92edcf7424930b1"
src/http/serverinfo.cpp:1
- The new
handle_serverinfologic isn't covered by any unit tests. Adding tests for response structure and edge cases (e.g., zero players) would ensure long-term correctness.
#include "../otpch.h"
src/http/serverinfo.h:1
- [nitpick] Public API
handle_serverinfoisn't documented. Adding a brief doc comment describing expected input, response format, and status codes would improve discoverability.
#pragma once
src/http/serverinfo.cpp:22
- This use of
std::formatrequires including<format>(or ensuring it's brought in viaotpch.h). Verify you have the correct header to avoid compilation errors.
{{"started", std::format("{:%FT%TZ}", round<std::chrono::seconds>(serverStart()))},
src/http/serverinfo.cpp:22
- [nitpick] Consider qualifying the
roundcall for clarity (e.g.,std::chrono::round<std::chrono::seconds>(…)) to make its origin explicit.
{{"started", std::format("{:%FT%TZ}", round<std::chrono::seconds>(serverStart()))},
| {"monsters", {{"total", g_game.getMonstersOnline()}}}, | ||
| {"npcs", {{"total", g_game.getNpcsOnline()}}}, | ||
| {"rates", | ||
| {{"experience", getNumber(ConfigManager::RATE_EXPERIENCE)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todo: add a table when experience stages are used
a0e8763 to
57195f2
Compare
|
|
||
| } // namespace | ||
|
|
||
| std::chrono::system_clock::time_point tfs::http::serverStart() { return startTimepoint; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could directly return uptime, avoiding the calculation with now
tfs::http::uptime()
Pull Request Prelude
Changes Proposed
Adds a new handler for a
serverinfomessage type that returns the same information as the old status protocol, in a JSON format.How to test: after compiling, send
{"type": "serverinfo"}to the HTTP server{ "serverinfo": { "started": "2025-07-05T14:50:06Z", "uptime": 7, "servername": "Forgotten", "port": 7171, "location": "Sweden", "url": "https://otland.net/", "server": "The Forgotten Server", "version": "1.7", "client": "13.10" }, "owner": { "name": "Ranieri", "email": "[email protected]" }, "players": { "online": 0, "max": 0, "peak": 0 }, "monsters": { "total": 648 }, "npcs": { "total": 14 }, "rates": { "experience": 5, "skill": 3, "loot": 2, "magic": 3, "spawn": 1 }, "map": { "name": "forgotten", "author": "Komic", "width": 2048, "height": 2048 } }