-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a89e907
commit 1034eae
Showing
12 changed files
with
301 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <Messages/NotifyChatMessageBroadcast.h> | ||
|
||
void NotifyChatMessageBroadcast::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept | ||
{ | ||
Serialization::WriteString(aWriter, PlayerName); | ||
Serialization::WriteString(aWriter, ChatMessage); | ||
} | ||
|
||
void NotifyChatMessageBroadcast::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept | ||
{ | ||
ServerMessage::DeserializeRaw(aReader); | ||
|
||
PlayerName = Serialization::ReadString(aReader); | ||
ChatMessage = Serialization::ReadString(aReader); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "Message.h" | ||
|
||
using TiltedPhoques::String; | ||
|
||
struct NotifyChatMessageBroadcast final : ServerMessage | ||
{ | ||
static constexpr ServerOpcode Opcode = kNotifyChatMessageBroadcast; | ||
|
||
NotifyChatMessageBroadcast() : ServerMessage(Opcode) | ||
{ | ||
} | ||
|
||
virtual ~NotifyChatMessageBroadcast() = default; | ||
|
||
void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override; | ||
void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override; | ||
|
||
bool operator==(const NotifyChatMessageBroadcast& acRhs) const noexcept | ||
{ | ||
return GetOpcode() == acRhs.GetOpcode() && | ||
PlayerName == acRhs.PlayerName && | ||
ChatMessage == acRhs.ChatMessage; | ||
} | ||
|
||
TiltedPhoques::String PlayerName; | ||
TiltedPhoques::String ChatMessage; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <Messages/SendChatMessageRequest.h> | ||
|
||
void SendChatMessageRequest::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept | ||
{ | ||
Serialization::WriteString(aWriter, ChatMessage); | ||
} | ||
|
||
void SendChatMessageRequest::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept | ||
{ | ||
ClientMessage::DeserializeRaw(aReader); | ||
|
||
ChatMessage = Serialization::ReadString(aReader); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "Message.h" | ||
|
||
using TiltedPhoques::Map; | ||
using TiltedPhoques::String; | ||
|
||
struct SendChatMessageRequest final : ClientMessage | ||
{ | ||
static constexpr ClientOpcode Opcode = kSendChatMessageRequest; | ||
|
||
SendChatMessageRequest() : ClientMessage(Opcode) | ||
{ | ||
} | ||
|
||
virtual ~SendChatMessageRequest() = default; | ||
|
||
void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override; | ||
void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override; | ||
|
||
bool operator==(const SendChatMessageRequest& acRhs) const noexcept | ||
{ | ||
return GetOpcode() == acRhs.GetOpcode() && | ||
ChatMessage == acRhs.ChatMessage; | ||
} | ||
|
||
TiltedPhoques::String ChatMessage; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <Components.h> | ||
#include <GameServer.h> | ||
|
||
#include <Scripts/Player.h> | ||
#include <Services/OverlayService.h> | ||
|
||
#include <Messages/NotifyChatMessageBroadcast.h> | ||
#include <Messages/SendChatMessageRequest.h> | ||
|
||
#include <Events/PlayerEnterWorldEvent.h> | ||
|
||
#include <regex> | ||
|
||
OverlayService::OverlayService(World& aWorld, entt::dispatcher& aDispatcher) | ||
: m_world(aWorld), | ||
m_chatMessageConnection( | ||
aDispatcher.sink<PacketEvent<SendChatMessageRequest>>().connect<&OverlayService::HandleChatMessage>(this)) | ||
{ | ||
} | ||
|
||
#if 0 | ||
void OverlayService::SendChatMessage(Script::Player aPlayer, const std::string aMessage) | ||
{ | ||
spdlog::debug(aMessage); | ||
NotifyChatMessageBroadcast notifyMessage; | ||
notifyMessage.PlayerName = ""; | ||
notifyMessage.ChatMessage = aMessage; | ||
|
||
// TODO: ehh? | ||
Player* pPlayer = m_world.GetPlayerManager().GetById(aPlayer.GetId()); | ||
pPlayer->Send(notifyMessage); | ||
} | ||
#endif | ||
|
||
void OverlayService::BroadcastMessage(const std::string aMessage) | ||
{ | ||
NotifyChatMessageBroadcast notifyMessage; | ||
notifyMessage.PlayerName = ""; | ||
notifyMessage.ChatMessage = aMessage; | ||
|
||
GameServer::Get()->SendToPlayers(notifyMessage); | ||
} | ||
|
||
void OverlayService::HandleChatMessage(const PacketEvent<SendChatMessageRequest>& acMessage) const noexcept | ||
{ | ||
NotifyChatMessageBroadcast notifyMessage; | ||
notifyMessage.PlayerName = acMessage.pPlayer->GetUsername(); | ||
|
||
// TODO: std regex is slow | ||
std::regex escapeHtml{"<[^>]+>\s+(?=<)|<[^>]+>"}; | ||
notifyMessage.ChatMessage = std::regex_replace(acMessage.Packet.ChatMessage, escapeHtml, ""); | ||
|
||
GameServer::Get()->SendToPlayers(notifyMessage); | ||
} | ||
|
||
#if 0 | ||
void OverlayService::HandlePlayerJoin(const PlayerEnterWorldEvent& acEvent) const noexcept | ||
{ | ||
const Script::Player cPlayer(acEvent.Entity, m_world); | ||
|
||
auto& playerComponent = m_world.get<PlayerComponent>(cPlayer.GetEntityHandle()); | ||
|
||
spdlog::info("[SERVER] PlayerId: {} - ConnectionId: {}", cPlayer.GetId(), playerComponent.ConnectionId); | ||
if (playerComponent.Character) | ||
{ | ||
spdlog::info("[SERVER] CharacterId: {}", playerComponent.Character.value()); | ||
} | ||
|
||
//TODO | ||
//Send netid, username and default level to all client except to the one that just joined | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
#include <Scripts/Player.h> | ||
|
||
#include <Messages/SendChatMessageRequest.h> | ||
|
||
#include <Events/PacketEvent.h> | ||
#include <Events/PlayerEnterWorldEvent.h> | ||
|
||
struct World; | ||
|
||
class OverlayService | ||
{ | ||
public: | ||
OverlayService(World& aWorld, entt::dispatcher& aDispatcher); | ||
|
||
void SendChatMessage(Script::Player aPlayer, const std::string aMessage); | ||
void BroadcastMessage(const std::string aMessage); | ||
|
||
protected: | ||
void HandleChatMessage(const PacketEvent<SendChatMessageRequest>& acMessage) const noexcept; | ||
void HandlePlayerJoin(const PlayerEnterWorldEvent& acEvent) const noexcept; | ||
|
||
private: | ||
World& m_world; | ||
|
||
entt::scoped_connection m_chatMessageConnection; | ||
entt::scoped_connection m_playerEnterWorldConnection; | ||
}; |
Oops, something went wrong.