Skip to content

Conversation

@ranisalt
Copy link
Member

@ranisalt ranisalt commented Jul 5, 2025

Pull Request Prelude

Changes Proposed

Adds a new handler for a serverinfo message 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
  }
}

@ranisalt ranisalt requested a review from Copilot July 5, 2025 14:50
Copy link

Copilot AI left a 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_serverinfo handler with JSON response
  • Integrates handler into the HTTP router and exposes server start time via serverStart()
  • Updates CMake and vcpkg.json to 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-features section 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_serverinfo logic 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_serverinfo isn'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::format requires including <format> (or ensuring it's brought in via otpch.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 round call 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)},
Copy link
Member Author

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


} // namespace

std::chrono::system_clock::time_point tfs::http::serverStart() { return startTimepoint; }
Copy link
Contributor

@ramon-bernardo ramon-bernardo Dec 4, 2025

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants