mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-01-22 08:30:06 +00:00
Move event buffers to Monitor
This commit is contained in:
parent
b4ed31d4fb
commit
6ff51685a8
20
src/Chat.cpp
20
src/Chat.cpp
@ -1,6 +1,7 @@
|
||||
#include "Chat.hpp"
|
||||
|
||||
#include "servers/CNShardServer.hpp"
|
||||
#include "servers/Monitor.hpp"
|
||||
|
||||
#include "Player.hpp"
|
||||
#include "PlayerManager.hpp"
|
||||
@ -8,9 +9,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
std::vector<std::string> Chat::dump;
|
||||
std::vector<std::string> Chat::bcasts;
|
||||
|
||||
using namespace Chat;
|
||||
|
||||
static void chatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
@ -29,7 +27,7 @@ static void chatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
std::string logLine = "[FreeChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
// send to client
|
||||
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
||||
@ -52,7 +50,7 @@ static void menuChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
std::string logLine = "[MenuChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
// send to client
|
||||
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
||||
@ -126,7 +124,7 @@ static void announcementHandler(CNSocket* sock, CNPacketData* data) {
|
||||
+ std::to_string(announcement->iDuringTime) + " "
|
||||
+ PlayerManager::getPlayerName(plr, false) + ": " + AUTOU16TOU8(msg.szAnnounceMsg);
|
||||
std::cout << "Broadcast " << logLine << std::endl;
|
||||
bcasts.push_back(logLine);
|
||||
Monitor::bcasts.push_back(logLine);
|
||||
}
|
||||
|
||||
// Buddy freechatting
|
||||
@ -159,7 +157,7 @@ static void buddyChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
std::string logLine = "[BuddyChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
||||
|
||||
@ -189,7 +187,7 @@ static void buddyMenuChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
std::string logLine = "[BuddyMenuChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
||||
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
||||
|
||||
@ -222,7 +220,7 @@ static void tradeChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
std::string logLine = "[TradeChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
||||
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
resp.iEmoteCode = pacdat->iEmoteCode;
|
||||
sock->sendPacket(resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT);
|
||||
@ -245,7 +243,7 @@ static void groupChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
std::string logLine = "[GroupChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
// send to client
|
||||
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, resp);
|
||||
@ -268,7 +266,7 @@ static void groupMenuChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
std::string logLine = "[GroupMenuChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||
|
||||
std::cout << logLine << std::endl;
|
||||
dump.push_back(logLine);
|
||||
Monitor::chats.push_back(logLine);
|
||||
|
||||
// send to client
|
||||
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp);
|
||||
|
@ -8,8 +8,6 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Chat {
|
||||
extern std::vector<std::string> dump;
|
||||
extern std::vector<std::string> bcasts;
|
||||
void init();
|
||||
|
||||
void sendServerMessage(CNSocket* sock, std::string msg); // uses MOTD
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "core/Core.hpp"
|
||||
#include "db/Database.hpp"
|
||||
#include "servers/CNShardServer.hpp"
|
||||
#include "servers/Monitor.hpp"
|
||||
|
||||
#include "PlayerManager.hpp"
|
||||
#include "Items.hpp"
|
||||
@ -10,8 +11,6 @@
|
||||
|
||||
using namespace Email;
|
||||
|
||||
std::vector<std::string> Email::dump;
|
||||
|
||||
// New email notification
|
||||
static void emailUpdateCheck(CNSocket* sock, CNPacketData* data) {
|
||||
INITSTRUCT(sP_FE2CL_REP_PC_NEW_EMAIL, resp);
|
||||
@ -324,7 +323,7 @@ static void emailSend(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
std::string logEmail = "[Email] " + PlayerManager::getPlayerName(plr, true) + " (to " + PlayerManager::getPlayerName(&otherPlr, true) + "): <" + email.SubjectLine + ">\n" + email.MsgBody;
|
||||
std::cout << logEmail << std::endl;
|
||||
dump.push_back(logEmail);
|
||||
Monitor::emails.push_back(logEmail);
|
||||
|
||||
// notification to recipient if online
|
||||
CNSocket* recipient = PlayerManager::getSockFromID(pkt->iTo_PCUID);
|
||||
|
@ -4,7 +4,5 @@
|
||||
#include <string>
|
||||
|
||||
namespace Email {
|
||||
extern std::vector<std::string> dump;
|
||||
|
||||
void init();
|
||||
}
|
||||
|
@ -14,6 +14,12 @@ static std::mutex sockLock; // guards socket list
|
||||
static std::list<SOCKET> sockets;
|
||||
static sockaddr_in address;
|
||||
|
||||
std::vector<std::string> Monitor::chats;
|
||||
std::vector<std::string> Monitor::bcasts;
|
||||
std::vector<std::string> Monitor::emails;
|
||||
|
||||
using namespace Monitor;
|
||||
|
||||
static bool transmit(std::list<SOCKET>::iterator& it, char *buff, int len) {
|
||||
int n = 0;
|
||||
int sock = *it;
|
||||
@ -99,7 +105,7 @@ outer:
|
||||
}
|
||||
|
||||
// chat
|
||||
for (auto& str : Chat::dump) {
|
||||
for (auto& str : chats) {
|
||||
n = std::snprintf(buff, sizeof(buff), "chat %s\n", str.c_str());
|
||||
|
||||
if (!transmit(it, buff, n))
|
||||
@ -107,7 +113,7 @@ outer:
|
||||
}
|
||||
|
||||
// announcements
|
||||
for (auto& str : Chat::bcasts) {
|
||||
for (auto& str : bcasts) {
|
||||
n = std::snprintf(buff, sizeof(buff), "bcast %s\n", str.c_str());
|
||||
|
||||
if (!transmit(it, buff, n))
|
||||
@ -115,7 +121,7 @@ outer:
|
||||
}
|
||||
|
||||
// emails
|
||||
for (auto& str : Email::dump) {
|
||||
for (auto& str : emails) {
|
||||
n = process_email(buff, str);
|
||||
|
||||
if (!transmit(it, buff, n))
|
||||
@ -131,9 +137,9 @@ outer:
|
||||
it++;
|
||||
}
|
||||
|
||||
Chat::dump.clear();
|
||||
Chat::bcasts.clear();
|
||||
Email::dump.clear();
|
||||
chats.clear();
|
||||
bcasts.clear();
|
||||
emails.clear();
|
||||
}
|
||||
|
||||
bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) {
|
||||
|
@ -3,6 +3,10 @@
|
||||
#include "core/Core.hpp"
|
||||
|
||||
namespace Monitor {
|
||||
extern std::vector<std::string> chats;
|
||||
extern std::vector<std::string> bcasts;
|
||||
extern std::vector<std::string> emails;
|
||||
|
||||
SOCKET init();
|
||||
bool acceptConnection(SOCKET, uint16_t);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user