mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch: accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes they need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <algorithm>
|
|
#include "eHTTPStatusCode.h"
|
|
#include "json.hpp"
|
|
|
|
/**
|
|
* HTTP Request Context
|
|
*
|
|
* Carries all request metadata through the middleware chain.
|
|
* Populated by the Web framework before middleware/handlers are called.
|
|
*/
|
|
struct HTTPContext {
|
|
// Request metadata
|
|
std::string method{};
|
|
std::string path{}; // lowercased: routes match without regard to case
|
|
std::string originalPath{}; // as sent, for parameters whose case matters (file names)
|
|
std::string queryString{};
|
|
std::string body{};
|
|
|
|
// Request headers (header name -> value)
|
|
// Header names are lowercase for case-insensitive lookup
|
|
std::map<std::string, std::string> headers{};
|
|
|
|
// Client information
|
|
std::string clientIP{};
|
|
|
|
// Authentication information (populated by auth middleware)
|
|
bool isAuthenticated = false;
|
|
std::string authenticatedUser{};
|
|
uint32_t accountId = 0;
|
|
uint8_t gmLevel = 0;
|
|
|
|
// Custom data for middleware to communicate
|
|
std::map<std::string, std::string> userData{};
|
|
|
|
/**
|
|
* Get header value (case-insensitive)
|
|
*/
|
|
const std::string& GetHeader(const std::string& headerName) const {
|
|
static const std::string empty{};
|
|
|
|
// Convert to lowercase for comparison
|
|
std::string lowerName = headerName;
|
|
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
|
|
|
const auto it = headers.find(lowerName);
|
|
return it != headers.end() ? it->second : empty;
|
|
}
|
|
|
|
/**
|
|
* Set header value (automatically lowercased)
|
|
*/
|
|
void SetHeader(const std::string& headerName, const std::string& value) {
|
|
std::string lowerName = headerName;
|
|
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
|
headers[lowerName] = value;
|
|
}
|
|
|
|
/**
|
|
* Get user data as JSON for template rendering
|
|
*/
|
|
nlohmann::json GetUserDataJson() const {
|
|
nlohmann::json userData;
|
|
userData["username"] = authenticatedUser;
|
|
userData["gmLevel"] = gmLevel;
|
|
userData["accountId"] = accountId;
|
|
return userData;
|
|
}
|
|
};
|