mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
rename files
use config vars to disable the api and whitelist listen IP
This commit is contained in:
parent
5e16c13a58
commit
77143fc2cf
@ -1,5 +1,5 @@
|
||||
set(DCHATSERVER_SOURCES
|
||||
"ChatHttpApi.cpp"
|
||||
"ChatWebApi.cpp"
|
||||
"ChatIgnoreList.cpp"
|
||||
"ChatPacketHandler.cpp"
|
||||
"PlayerContainer.cpp"
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "eWorldMessageType.h"
|
||||
#include "ChatIgnoreList.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "ChatHttpApi.h"
|
||||
#include "ChatWebApi.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "Server.h"
|
||||
@ -123,7 +123,8 @@ int main(int argc, char** argv) {
|
||||
uint32_t framesSinceMasterDisconnect = 0;
|
||||
uint32_t framesSinceLastSQLPing = 0;
|
||||
|
||||
std::thread APIThread(ChatHttpApi::Listen, ourPort);
|
||||
// start the web api thread
|
||||
std::thread webAPIThread(ChatWebApi::Listen, ourPort);
|
||||
|
||||
Game::logger->Flush(); // once immediately before main loop
|
||||
while (!Game::ShouldShutdown()) {
|
||||
@ -177,8 +178,11 @@ int main(int argc, char** argv) {
|
||||
delete Game::server;
|
||||
delete Game::logger;
|
||||
delete Game::config;
|
||||
ChatHttpApi::Stop();
|
||||
APIThread.join();
|
||||
|
||||
// rejoin the web api thread
|
||||
ChatWebApi::Stop();
|
||||
webAPIThread.join();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "ChatHttpApi.h"
|
||||
#include "ChatWebApi.h"
|
||||
#include "dCommonVars.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eChatMessageType.h"
|
||||
#include "httplib.h"
|
||||
#include "dServer.h"
|
||||
#include "PlayerContainer.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@ -15,7 +16,13 @@ namespace {
|
||||
httplib::Server m_APIServer;
|
||||
}
|
||||
|
||||
void ChatHttpApi::Listen(const uint32_t port) {
|
||||
void ChatWebApi::Listen(const uint32_t port) {
|
||||
if (Game::config->GetValue("enable_chat_web_api") != "1") {
|
||||
LOG("Chat Web API is disabled");
|
||||
return;
|
||||
}
|
||||
LOG("Chat Web API is enabled, starting web server...");
|
||||
|
||||
m_APIServer.Post("/announce", [](const httplib::Request& req, httplib::Response& res) {
|
||||
const json data = json::parse(req.body);
|
||||
if (!data.contains("title")) {
|
||||
@ -75,9 +82,12 @@ void ChatHttpApi::Listen(const uint32_t port) {
|
||||
if (data.empty()) res.status = 204;
|
||||
});
|
||||
|
||||
m_APIServer.listen("0.0.0.0", port);
|
||||
m_APIServer.listen(Game::config->GetValue("enable_chat_web_api").c_str(), port);
|
||||
};
|
||||
|
||||
void ChatHttpApi::Stop(){
|
||||
void ChatWebApi::Stop(){
|
||||
if (Game::config->GetValue("enable_chat_web_api") == "1") {
|
||||
LOG("Stopping Chat Web API server...");
|
||||
m_APIServer.stop();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "httplib.h"
|
||||
|
||||
namespace ChatHttpApi {
|
||||
namespace ChatWebApi {
|
||||
void Listen(const uint32_t port);
|
||||
void Stop();
|
||||
};
|
@ -6,3 +6,10 @@ max_number_of_best_friends=5
|
||||
# Change the value below to what you would like this to be (50 is live accurate)
|
||||
# going over 50 will be allowed in some secnarios, but proper handling will require client modding
|
||||
max_number_of_friends=50
|
||||
|
||||
# Enable or disable the chat web API, disabled by default
|
||||
# It will run on the same port the chat server is running on, defined in shardconfig.ini
|
||||
enable_chat_web_api=0
|
||||
|
||||
# If that chat web api is enabled, it will only listen for connections on this ip address
|
||||
chat_web_api_listen_address=localhost
|
||||
|
Loading…
Reference in New Issue
Block a user