mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-02-02 01:47:06 +00:00
fix content type
This commit is contained in:
parent
394fcc050c
commit
5941db25bd
@ -114,7 +114,7 @@ std::set<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::str
|
||||
std::string segment;
|
||||
std::regex reg("(!*|\\?*|\\;*|\\.*|\\,*)");
|
||||
|
||||
std::set<std::pair<uint8_t, uint8_t>> listOfBadSegments = std::set<std::pair<uint8_t, uint8_t>>();
|
||||
std::set<std::pair<uint8_t, uint8_t>> listOfBadSegments;
|
||||
|
||||
uint32_t position = 0;
|
||||
|
||||
|
@ -73,8 +73,8 @@ void HandleWSChat(mg_connection* connection, json data) {
|
||||
LOG_DEBUG("Chat message \"%s\" from %s was not allowed", message.c_str(), user.c_str());
|
||||
data["error"] = "Chat message blocked by filter";
|
||||
data["filtered"] = json::array();
|
||||
for (const auto& filtered : filter_check) {
|
||||
data["filtered"].push_back(message.substr(filtered.first, filtered.second));
|
||||
for (const auto& [start, len] : filter_check) {
|
||||
data["filtered"].push_back(message.substr(start, len));
|
||||
}
|
||||
mg_ws_send(connection, data.dump().c_str(), data.dump().size(), WEBSOCKET_OP_TEXT);
|
||||
return;
|
||||
@ -102,10 +102,6 @@ void HandleWSChat(mg_connection* connection, json data) {
|
||||
}
|
||||
bitStream.Write<uint16_t>(0);
|
||||
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
|
||||
// send to world servers with macthing zone
|
||||
// Cry: this is the hard part since there is no instance manager
|
||||
// Do we send it to master and let master sort it out via instance manager?
|
||||
}
|
||||
}
|
||||
|
||||
|
22
dWeb/Web.cpp
22
dWeb/Web.cpp
@ -12,7 +12,7 @@ namespace Game {
|
||||
}
|
||||
|
||||
namespace {
|
||||
const char * json_content_type = "application/json";
|
||||
const char* json_content_type = "Content-Type: application/json\r\n";
|
||||
std::map<std::pair<eHTTPMethod, std::string>, HTTPRoute> g_HTTPRoutes;
|
||||
std::map<std::string, WSEvent> g_WSEvents;
|
||||
std::vector<std::string> g_WSSubscriptions;
|
||||
@ -170,6 +170,11 @@ void HandleMessages(mg_connection* connection, int message, void* message_data)
|
||||
}
|
||||
|
||||
void Web::RegisterHTTPRoute(HTTPRoute route) {
|
||||
if (!Game::web.enabled) {
|
||||
LOG_DEBUG("Failed to register HTTP route %s: web server not enabled", route.path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto [_, success] = g_HTTPRoutes.try_emplace({ route.method, route.path }, route);
|
||||
if (!success) {
|
||||
LOG_DEBUG("Failed to register HTTP route %s", route.path.c_str());
|
||||
@ -179,6 +184,11 @@ void Web::RegisterHTTPRoute(HTTPRoute route) {
|
||||
}
|
||||
|
||||
void Web::RegisterWSEvent(WSEvent event) {
|
||||
if (!Game::web.enabled) {
|
||||
LOG_DEBUG("Failed to register WS event %s: web server not enabled", event.name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto [_, success] = g_WSEvents.try_emplace(event.name, event);
|
||||
if (!success) {
|
||||
LOG_DEBUG("Failed to register WS event %s", event.name.c_str());
|
||||
@ -188,6 +198,11 @@ void Web::RegisterWSEvent(WSEvent event) {
|
||||
}
|
||||
|
||||
void Web::RegisterWSSubscription(const std::string& subscription) {
|
||||
if (!Game::web.enabled) {
|
||||
LOG_DEBUG("Failed to register WS subscription %s: web server not enabled", subscription.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// check that subsction is not already in the vector
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), subscription);
|
||||
if (subItr != g_WSSubscriptions.end()) {
|
||||
@ -208,6 +223,7 @@ Web::~Web() {
|
||||
}
|
||||
|
||||
bool Web::Startup(const std::string& listen_ip, const uint32_t listen_port) {
|
||||
|
||||
// Make listen address
|
||||
const std::string& listen_address = "http://" + listen_ip + ":" + std::to_string(listen_port);
|
||||
LOG("Starting web server on %s", listen_address.c_str());
|
||||
@ -217,7 +233,7 @@ bool Web::Startup(const std::string& listen_ip, const uint32_t listen_port) {
|
||||
LOG("Failed to create web server listener on %s", listen_address.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// WebSocket Events
|
||||
Game::web.RegisterWSEvent({
|
||||
.name = "subscribe",
|
||||
@ -242,7 +258,7 @@ void Web::ReceiveRequests() {
|
||||
}
|
||||
|
||||
void Web::SendWSMessage(const std::string subscription, json& data) {
|
||||
if (!Game::web.enabled) return;
|
||||
if (!Game::web.enabled) return; // don't attempt to send if web is not enabled
|
||||
|
||||
// find subscription
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), subscription);
|
||||
|
@ -33,12 +33,6 @@ struct WSEvent {
|
||||
std::function<void(mg_connection*, nlohmann::json)> handle;
|
||||
};
|
||||
|
||||
struct WSMessage {
|
||||
uint32_t id;
|
||||
std::string sub;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class Web {
|
||||
public:
|
||||
Web();
|
||||
|
Loading…
Reference in New Issue
Block a user