blob: 07dfce40ee5a80bcb3264f5ce81d9fa353fcef20 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include "chatManager.hpp"
#include "IOManager.hpp"
#include "inputManager.hpp"
#include "log.hpp"
#include "sessionManager.hpp"
CChatManager::CChatManager() {
log(LOG, "ChatManager: initialized");
}
CChatManager::~CChatManager() {
log(SYS, "ChatManager: bye");
}
void CChatManager::newMessage(const SMessage &msg) {
log(LOG, "{}: {}", msg.username, msg.msg);
const auto session = g_pSessionManager->getByName(msg.username);
if (session && session->isMuted()) {
session->write("You are muted");
return;
}
g_pSessionManager->broadcastChat(msg);
g_pIOManager->m_vIO.push_back({.msg = msg, .log = std::nullopt});
g_pInputManager->updateIO();
}
std::string CChatManager::fmtBroadcastMessage(const SMessage &msg) {
return NFormatter::fmt(NONE, "{}: {}", msg.username, msg.msg);
}
std::vector<CChatManager::SMessage> CChatManager::getChat() const {
std::vector<SMessage> chat;
for (const auto &[msg, log] : g_pIOManager->getIO())
if (msg)
chat.push_back(*msg);
return chat;
}
|