mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-19 12:21:34 +00:00
[Library] Update httplib (#1401)
* Update httplib * Update syntax for new httplib and run on own thread * Only log if path is set in request
This commit is contained in:
parent
3886636ec7
commit
7139530787
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
LoginServer server;
|
LoginServer server;
|
||||||
EQEmuLogSys LogSys;
|
EQEmuLogSys LogSys;
|
||||||
@ -130,6 +131,23 @@ void LoadServerConfig()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start_web_server()
|
||||||
|
{
|
||||||
|
int web_api_port = server.config.GetVariableInt("web_api", "port", 6000);
|
||||||
|
LogInfo("Webserver API now listening on port [{0}]", web_api_port);
|
||||||
|
|
||||||
|
httplib::Server api;
|
||||||
|
|
||||||
|
api.set_logger([](const auto& req, const auto& res) {
|
||||||
|
if (!req.path.empty()) {
|
||||||
|
LogInfo("[API] Request [{}] via [{}:{}]", req.path, req.remote_addr, req.remote_port);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
LoginserverWebserver::RegisterRoutes(api);
|
||||||
|
api.listen("0.0.0.0", web_api_port);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
RegisterExecutablePlatform(ExePlatformLogin);
|
RegisterExecutablePlatform(ExePlatformLogin);
|
||||||
@ -195,7 +213,7 @@ int main(int argc, char **argv)
|
|||||||
* create client manager
|
* create client manager
|
||||||
*/
|
*/
|
||||||
LogInfo("Client Manager Init");
|
LogInfo("Client Manager Init");
|
||||||
server.client_manager = new ClientManager();
|
server.client_manager = new ClientManager();
|
||||||
if (!server.client_manager) {
|
if (!server.client_manager) {
|
||||||
LogError("Client Manager Failed to Start");
|
LogError("Client Manager Failed to Start");
|
||||||
LogInfo("Server Manager Shutdown");
|
LogInfo("Server Manager Shutdown");
|
||||||
@ -222,13 +240,10 @@ int main(int argc, char **argv)
|
|||||||
/**
|
/**
|
||||||
* Web API
|
* Web API
|
||||||
*/
|
*/
|
||||||
httplib::Server api;
|
bool web_api_enabled = server.config.GetVariableBool("web_api", "enabled", true);
|
||||||
int web_api_port = server.config.GetVariableInt("web_api", "port", 6000);
|
|
||||||
bool web_api_enabled = server.config.GetVariableBool("web_api", "enabled", true);
|
|
||||||
if (web_api_enabled) {
|
if (web_api_enabled) {
|
||||||
api.bind("0.0.0.0", web_api_port);
|
std::thread web_api_thread(start_web_server);
|
||||||
LogInfo("Webserver API now listening on port [{0}]", web_api_port);
|
web_api_thread.detach();
|
||||||
LoginserverWebserver::RegisterRoutes(api);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInfo("[Config] [Logging] IsTraceOn [{0}]", server.options.IsTraceOn());
|
LogInfo("[Config] [Logging] IsTraceOn [{0}]", server.options.IsTraceOn());
|
||||||
@ -251,10 +266,6 @@ int main(int argc, char **argv)
|
|||||||
server.client_manager->Process();
|
server.client_manager->Process();
|
||||||
EQ::EventLoop::Get().Process();
|
EQ::EventLoop::Get().Process();
|
||||||
|
|
||||||
if (web_api_enabled) {
|
|
||||||
api.poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sleep(5);
|
Sleep(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user