mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-04-26 16:46:31 +00:00
WIP
This commit is contained in:
parent
72d1b434ed
commit
5ad0b3e74a
@ -134,9 +134,6 @@ namespace ChatWeb {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// WebSocket subscriptions
|
// WebSocket subscriptions
|
||||||
Game::web.RegisterWSSubscription("chat_local");
|
|
||||||
Game::web.RegisterWSSubscription("chat_team");
|
|
||||||
Game::web.RegisterWSSubscription("chat_private");
|
|
||||||
Game::web.RegisterWSSubscription("chat");
|
Game::web.RegisterWSSubscription("chat");
|
||||||
Game::web.RegisterWSSubscription("player");
|
Game::web.RegisterWSSubscription("player");
|
||||||
Game::web.RegisterWSSubscription("team");
|
Game::web.RegisterWSSubscription("team");
|
||||||
@ -156,24 +153,20 @@ namespace ChatWeb {
|
|||||||
|
|
||||||
data["channel"] = magic_enum::enum_name(chatMessage.channel);
|
data["channel"] = magic_enum::enum_name(chatMessage.channel);
|
||||||
|
|
||||||
std::string event = "chat"; // generic catch all
|
|
||||||
switch (chatMessage.channel) {
|
switch (chatMessage.channel) {
|
||||||
case eChatChannel::LOCAL:
|
case eChatChannel::LOCAL:
|
||||||
event = "chat_local";
|
break;
|
||||||
break;
|
case eChatChannel::TEAM:
|
||||||
case eChatChannel::TEAM:
|
data["teamID"] = chatMessage.teamID;
|
||||||
event = "chat_team";
|
break;
|
||||||
data["teamID"] = chatMessage.teamID;
|
case eChatChannel::PRIVATE_CHAT:
|
||||||
break;
|
data["receiver"] = chatMessage.receiver;
|
||||||
case eChatChannel::PRIVATE_CHAT:
|
break;
|
||||||
data["receiver"] = chatMessage.receiver;
|
default:
|
||||||
event = "chat_private";
|
// do nothing
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
LOG_DEBUG("Unhandled Chat channel [%s] in websocket send", StringifiedEnum::ToString(chatMessage.channel).data());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
Game::web.SendWSMessage(event, data);
|
Game::web.SendWSMessage("chat", data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,98 +11,82 @@
|
|||||||
#include "dServer.h"
|
#include "dServer.h"
|
||||||
#include "eConnectionType.h"
|
#include "eConnectionType.h"
|
||||||
#include "MessageType/Chat.h"
|
#include "MessageType/Chat.h"
|
||||||
|
namespace ChatPackets {
|
||||||
void ShowAllRequest::Serialize(RakNet::BitStream& bitStream) {
|
void ShowAllRequest::Serialize(RakNet::BitStream& bitStream) const {
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::SHOW_ALL);
|
bitStream.Write(this->requestor);
|
||||||
bitStream.Write(this->requestor);
|
bitStream.Write(this->displayZoneData);
|
||||||
bitStream.Write(this->displayZoneData);
|
bitStream.Write(this->displayIndividualPlayers);
|
||||||
bitStream.Write(this->displayIndividualPlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShowAllRequest::Deserialize(RakNet::BitStream& inStream) {
|
|
||||||
inStream.Read(this->requestor);
|
|
||||||
inStream.Read(this->displayZoneData);
|
|
||||||
inStream.Read(this->displayIndividualPlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FindPlayerRequest::Serialize(RakNet::BitStream& bitStream) {
|
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WHO);
|
|
||||||
bitStream.Write(this->requestor);
|
|
||||||
bitStream.Write(this->playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FindPlayerRequest::Deserialize(RakNet::BitStream& inStream) {
|
|
||||||
inStream.Read(this->requestor);
|
|
||||||
inStream.Read(this->playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message) {
|
|
||||||
CBITSTREAM;
|
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
|
||||||
|
|
||||||
bitStream.Write<uint64_t>(0);
|
|
||||||
bitStream.Write(chatChannel);
|
|
||||||
|
|
||||||
bitStream.Write<uint32_t>(message.size());
|
|
||||||
bitStream.Write(LUWString(senderName));
|
|
||||||
|
|
||||||
bitStream.Write(playerObjectID);
|
|
||||||
bitStream.Write<uint16_t>(0);
|
|
||||||
bitStream.Write<char>(0);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < message.size(); ++i) {
|
|
||||||
bitStream.Write<uint16_t>(message[i]);
|
|
||||||
}
|
|
||||||
bitStream.Write<uint16_t>(0);
|
|
||||||
SEND_PACKET_BROADCAST;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
|
|
||||||
CBITSTREAM;
|
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
|
||||||
|
|
||||||
bitStream.Write<uint64_t>(0);
|
|
||||||
bitStream.Write<char>(4);
|
|
||||||
|
|
||||||
bitStream.Write<uint32_t>(message.size());
|
|
||||||
bitStream.Write(LUWString("", 33));
|
|
||||||
|
|
||||||
bitStream.Write<uint64_t>(0);
|
|
||||||
bitStream.Write<uint16_t>(0);
|
|
||||||
bitStream.Write<char>(0);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < message.size(); ++i) {
|
|
||||||
bitStream.Write<uint16_t>(message[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bitStream.Write<uint16_t>(0);
|
bool ShowAllRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||||
|
VALIDATE_READ(inStream.Read(this->requestor));
|
||||||
//This is so Wincent's announcement works:
|
VALIDATE_READ(inStream.Read(this->displayZoneData));
|
||||||
if (sysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
|
VALIDATE_READ(inStream.Read(this->displayIndividualPlayers));
|
||||||
SEND_PACKET;
|
return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SEND_PACKET_BROADCAST;
|
void FindPlayerRequest::Serialize(RakNet::BitStream& bitStream) const {
|
||||||
}
|
bitStream.Write(this->requestor);
|
||||||
|
bitStream.Write(this->playerName);
|
||||||
|
}
|
||||||
|
|
||||||
void ChatPackets::SendMessageFail(const SystemAddress& sysAddr) {
|
bool FindPlayerRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||||
//0x00 - "Chat is currently disabled."
|
VALIDATE_READ(inStream.Read(this->requestor));
|
||||||
//0x01 - "Upgrade to a full LEGO Universe Membership to chat with other players."
|
VALIDATE_READ(inStream.Read(this->playerName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
CBITSTREAM;
|
void ChatMessage::Serialize(RakNet::BitStream& bitStream) const {
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SEND_CANNED_TEXT);
|
bitStream.Write<uint64_t>(0);// senderID
|
||||||
bitStream.Write<uint8_t>(0); //response type, options above ^
|
bitStream.Write(chatChannel);
|
||||||
//docs say there's a wstring here-- no idea what it's for, or if it's even needed so leaving it as is for now.
|
|
||||||
SEND_PACKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatPackets::Announcement::Send() {
|
bitStream.Write<uint32_t>(message.GetAsString().size());
|
||||||
CBITSTREAM;
|
bitStream.Write(LUWString(senderName));
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GM_ANNOUNCE);
|
|
||||||
bitStream.Write<uint32_t>(title.size());
|
bitStream.Write(playerObjectID); // senderID
|
||||||
bitStream.Write(title);
|
bitStream.Write<uint16_t>(0); // sourceID
|
||||||
bitStream.Write<uint32_t>(message.size());
|
bitStream.Write(responseCode);
|
||||||
bitStream.Write(message);
|
bitStream.Write(message)
|
||||||
SEND_PACKET_BROADCAST;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
|
||||||
|
CBITSTREAM;
|
||||||
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||||
|
|
||||||
|
bitStream.Write<uint64_t>(0);
|
||||||
|
bitStream.Write<char>(4);
|
||||||
|
|
||||||
|
bitStream.Write<uint32_t>(message.size());
|
||||||
|
bitStream.Write(LUWString("", 33));
|
||||||
|
|
||||||
|
bitStream.Write<uint64_t>(0);
|
||||||
|
bitStream.Write<uint16_t>(0);
|
||||||
|
bitStream.Write<char>(0);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < message.size(); ++i) {
|
||||||
|
bitStream.Write<uint16_t>(message[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bitStream.Write<uint16_t>(0);
|
||||||
|
|
||||||
|
//This is so Wincent's announcement works:
|
||||||
|
if (sysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
|
||||||
|
SEND_PACKET;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SEND_PACKET_BROADCAST;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageFailure::Serialize(RakNet::BitStream& bitStream) const {
|
||||||
|
bitStream.Write(this->cannedText);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Announcement::Serialize(RakNet::BitStream& bitStream) const {
|
||||||
|
bitStream.Write<uint32_t>(title.size());
|
||||||
|
bitStream.Write(title);
|
||||||
|
bitStream.Write<uint32_t>(message.size());
|
||||||
|
bitStream.Write(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,33 +10,60 @@ struct SystemAddress;
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "dCommonVars.h"
|
#include "dCommonVars.h"
|
||||||
|
#include "BitStreamUtils.h"
|
||||||
|
|
||||||
struct ShowAllRequest{
|
enum class eCannedText : uint8_t {
|
||||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
CHAT_DISABLED = 0,
|
||||||
bool displayZoneData = true;
|
F2P_CHAT_DISABLED = 1
|
||||||
bool displayIndividualPlayers = true;
|
|
||||||
void Serialize(RakNet::BitStream& bitStream);
|
|
||||||
void Deserialize(RakNet::BitStream& inStream);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FindPlayerRequest{
|
|
||||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
|
||||||
LUWString playerName;
|
|
||||||
void Serialize(RakNet::BitStream& bitStream);
|
|
||||||
void Deserialize(RakNet::BitStream& inStream);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ChatPackets {
|
namespace ChatPackets {
|
||||||
|
struct ShowAllRequest : public LUBitStream {
|
||||||
|
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||||
|
bool displayZoneData = true;
|
||||||
|
bool displayIndividualPlayers = true;
|
||||||
|
|
||||||
struct Announcement {
|
ShowAllRequest() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::WHO) {};
|
||||||
std::string title;
|
|
||||||
std::string message;
|
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||||
void Send();
|
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message);
|
struct FindPlayerRequest : public LUBitStream {
|
||||||
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false);
|
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||||
void SendMessageFail(const SystemAddress& sysAddr);
|
LUWString playerName;
|
||||||
|
FindPlayerRequest() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::WHO) {};
|
||||||
|
|
||||||
|
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||||
|
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Announcement : public LUBitStream {
|
||||||
|
std::string title;
|
||||||
|
std::string message;
|
||||||
|
|
||||||
|
Announcement() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::GM_ANNOUNCE) {};
|
||||||
|
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ChatMessage : public LUBitStream {
|
||||||
|
char chatChannel;
|
||||||
|
std::string senderName;
|
||||||
|
LWOOBJID playerObjectID;
|
||||||
|
bool senderMythran;
|
||||||
|
eChatMessageResponseCode responseCode = eChatMessageResponseCode::SENT;
|
||||||
|
LUWString message;
|
||||||
|
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||||
|
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Should be in client packets since it is a client connection type, but whatever
|
||||||
|
struct MessageFailure : public LUBitStream {
|
||||||
|
eCannedText cannedText = eCannedText::CHAT_DISABLED;
|
||||||
|
|
||||||
|
MessageFailure() : LUBitStream(eConnectionType::CLIENT, MessageType::Chat::SEND_CANNED_TEXT) {};
|
||||||
|
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHATPACKETS_H
|
#endif // CHATPACKETS_H
|
||||||
|
16
dWeb/Web.cpp
16
dWeb/Web.cpp
@ -169,6 +169,17 @@ void HandleMessages(mg_connection* connection, int message, void* message_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redirect logs to our logger
|
||||||
|
static void DLOG(char ch, void *param) {
|
||||||
|
static char buf[256];
|
||||||
|
static size_t len;
|
||||||
|
if (ch != '\n') buf[len++] = ch; // we provide the newline in our logger
|
||||||
|
if (ch == '\n' || len >= sizeof(buf)) {
|
||||||
|
LOG_DEBUG("%.*s", static_cast<int>(len), buf);
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Web::RegisterHTTPRoute(HTTPRoute route) {
|
void Web::RegisterHTTPRoute(HTTPRoute route) {
|
||||||
if (!Game::web.enabled) {
|
if (!Game::web.enabled) {
|
||||||
LOG_DEBUG("Failed to register HTTP route %s: web server not enabled", route.path.c_str());
|
LOG_DEBUG("Failed to register HTTP route %s: web server not enabled", route.path.c_str());
|
||||||
@ -214,8 +225,9 @@ void Web::RegisterWSSubscription(const std::string& subscription) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Web::Web() {
|
Web::Web() {
|
||||||
mg_log_set(MG_LL_NONE);
|
mg_log_set_fn(DLOG, NULL); // Redirect logs to our logger
|
||||||
mg_mgr_init(&mgr); // Initialize event manager
|
mg_log_set(MG_LL_DEBUG);
|
||||||
|
mg_mgr_init(&mgr); // Initialize event manager
|
||||||
}
|
}
|
||||||
|
|
||||||
Web::~Web() {
|
Web::~Web() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user