mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-09 08:58:04 +00:00
Final framework, now just cleanup
This commit is contained in:
@@ -450,7 +450,6 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
|
||||
// build chat json data
|
||||
nlohmann::json data;
|
||||
data["action"] = "chat";
|
||||
data["playerName"] = sender.playerName;
|
||||
data["message"] = message.GetAsString();
|
||||
auto& zoneID = data["zone_id"];
|
||||
@@ -460,7 +459,7 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
|
||||
switch (channel) {
|
||||
case eChatChannel::LOCAL: {
|
||||
Game::web.SendWSMessage("WorldChat", data.dump());
|
||||
Game::web.SendWSMessage("chat_local", data);
|
||||
break;
|
||||
}
|
||||
case eChatChannel::TEAM: {
|
||||
@@ -472,7 +471,7 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
if (!otherMember) return;
|
||||
SendPrivateChatMessage(sender, otherMember, otherMember, message, eChatChannel::TEAM, eChatMessageResponseCode::SENT);
|
||||
data["teamID"] = team->teamID;
|
||||
Game::web.SendWSMessage("teamchat", data.dump());
|
||||
Game::web.SendWSMessage("chat_team", data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -528,6 +527,14 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
// only freinds can whispr each other
|
||||
for (const auto& fr : receiver.friends) {
|
||||
if (fr.friendID == sender.playerID) {
|
||||
nlohmann::json data;
|
||||
data["sender"] = sender.playerName;
|
||||
data["receiver"] = receiverName;
|
||||
data["message"] = message.GetAsString();
|
||||
data["zone_id"]["map_id"] = sender.zoneID.GetMapID();
|
||||
data["zone_id"]["instance_id"] = sender.zoneID.GetInstanceID();
|
||||
data["zone_id"]["clone_id"] = sender.zoneID.GetCloneID();
|
||||
Game::web.SendWSMessage("chat_private", data);
|
||||
//To the sender:
|
||||
SendPrivateChatMessage(sender, receiver, sender, message, eChatChannel::PRIVATE_CHAT, eChatMessageResponseCode::SENT);
|
||||
//To the receiver:
|
||||
|
@@ -69,36 +69,6 @@ void HandleWSChat(mg_connection* connection, json data) {
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWSSubscribe(mg_connection* connection, json data) {
|
||||
auto check = JSONUtils::CheckRequiredData(data, { "type" });
|
||||
if (!check.empty()) {
|
||||
LOG_DEBUG("Received invalid websocket message: %s", check.c_str());
|
||||
} else {
|
||||
const auto type = data["type"].get<std::string>();
|
||||
LOG_DEBUG("type %s subscribed", type.c_str());
|
||||
const auto sub = magic_enum::enum_cast<eWSSubscription>(type).value_or(eWSSubscription::INVALID);
|
||||
if (sub != eWSSubscription::INVALID) {
|
||||
connection->data[GeneralUtils::ToUnderlying(sub)] = 1;
|
||||
mg_ws_send(connection, "{\"status\":\"subscribed\"}", 18, WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWSUnsubscribe(mg_connection* connection, json data) {
|
||||
auto check = JSONUtils::CheckRequiredData(data, { "type" });
|
||||
if (!check.empty()) {
|
||||
LOG_DEBUG("Received invalid websocket message: %s", check.c_str());
|
||||
} else {
|
||||
const auto type = data["type"].get<std::string>();
|
||||
LOG_DEBUG("type %s unsubscribed", type.c_str());
|
||||
const auto sub = magic_enum::enum_cast<eWSSubscription>(type).value_or(eWSSubscription::INVALID);
|
||||
if (sub != eWSSubscription::INVALID) {
|
||||
connection->data[GeneralUtils::ToUnderlying(sub)] = 0;
|
||||
mg_ws_send(connection, "{\"status\":\"unsubscribed\"}", 18, WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWeb::RegisterRoutes() {
|
||||
// REST API v1 routes
|
||||
std::string v1_route = "/api/v1/";
|
||||
@@ -120,19 +90,16 @@ void ChatWeb::RegisterRoutes() {
|
||||
.handle = HandleHTTPAnnounceRequest
|
||||
});
|
||||
|
||||
// WebSocket Actions
|
||||
Game::web.RegisterWSAction({
|
||||
.action = "subscribe",
|
||||
.handle = HandleWSSubscribe
|
||||
});
|
||||
|
||||
Game::web.RegisterWSAction({
|
||||
.action = "unsubscribe",
|
||||
.handle = HandleWSUnsubscribe
|
||||
});
|
||||
|
||||
Game::web.RegisterWSAction({
|
||||
.action = "chat",
|
||||
// WebSocket Events
|
||||
Game::web.RegisterWSEvent({
|
||||
.name = "chat",
|
||||
.handle = HandleWSChat
|
||||
});
|
||||
|
||||
// WebSocket subscriptions
|
||||
Game::web.RegisterWSSubscription("chat_local");
|
||||
Game::web.RegisterWSSubscription("chat_team");
|
||||
Game::web.RegisterWSSubscription("chat_private");
|
||||
Game::web.RegisterWSSubscription("player");
|
||||
Game::web.RegisterWSSubscription("team");
|
||||
}
|
||||
|
@@ -6,15 +6,6 @@
|
||||
|
||||
#include "Web.h"
|
||||
|
||||
enum class eWSSubscription {
|
||||
WORLD_CHAT,
|
||||
PRIVATE_CHAT,
|
||||
TEAM_CHAT,
|
||||
TEAM,
|
||||
PLAYER,
|
||||
INVALID
|
||||
};
|
||||
|
||||
namespace ChatWeb {
|
||||
void RegisterRoutes();
|
||||
};
|
||||
|
@@ -70,7 +70,7 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
zoneID["map_id"] = data.zoneID.GetMapID();
|
||||
zoneID["instance_id"] = data.zoneID.GetInstanceID();
|
||||
zoneID["clone_id"] = data.zoneID.GetCloneID();
|
||||
Game::web.SendWSMessage("player", wsdata.dump());
|
||||
Game::web.SendWSMessage("player", wsdata);
|
||||
Database::Get()->UpdateActivityLog(data.playerID, eActivityType::PlayerLoggedIn, data.zoneID.GetMapID());
|
||||
m_PlayersToRemove.erase(playerId);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ void PlayerContainer::RemovePlayer(const LWOOBJID playerID) {
|
||||
wsdata["type"] = "remove";
|
||||
wsdata["playerName"] = player.playerName;
|
||||
wsdata["playerID"] = player.playerID;
|
||||
Game::web.SendWSMessage("player", wsdata.dump());
|
||||
Game::web.SendWSMessage("player", wsdata);
|
||||
|
||||
m_PlayerCount--;
|
||||
LOG("Removed user: %llu", playerID);
|
||||
|
Reference in New Issue
Block a user