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 "Chat.hpp"
|
||||||
|
|
||||||
#include "servers/CNShardServer.hpp"
|
#include "servers/CNShardServer.hpp"
|
||||||
|
#include "servers/Monitor.hpp"
|
||||||
|
|
||||||
#include "Player.hpp"
|
#include "Player.hpp"
|
||||||
#include "PlayerManager.hpp"
|
#include "PlayerManager.hpp"
|
||||||
@ -8,9 +9,6 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
std::vector<std::string> Chat::dump;
|
|
||||||
std::vector<std::string> Chat::bcasts;
|
|
||||||
|
|
||||||
using namespace Chat;
|
using namespace Chat;
|
||||||
|
|
||||||
static void chatHandler(CNSocket* sock, CNPacketData* data) {
|
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::string logLine = "[FreeChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||||
|
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
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::string logLine = "[MenuChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||||
|
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
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) + " "
|
+ std::to_string(announcement->iDuringTime) + " "
|
||||||
+ PlayerManager::getPlayerName(plr, false) + ": " + AUTOU16TOU8(msg.szAnnounceMsg);
|
+ PlayerManager::getPlayerName(plr, false) + ": " + AUTOU16TOU8(msg.szAnnounceMsg);
|
||||||
std::cout << "Broadcast " << logLine << std::endl;
|
std::cout << "Broadcast " << logLine << std::endl;
|
||||||
bcasts.push_back(logLine);
|
Monitor::bcasts.push_back(logLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buddy freechatting
|
// 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::string logLine = "[BuddyChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
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::string logLine = "[BuddyMenuChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
||||||
|
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
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::string logLine = "[TradeChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
||||||
|
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
resp.iEmoteCode = pacdat->iEmoteCode;
|
resp.iEmoteCode = pacdat->iEmoteCode;
|
||||||
sock->sendPacket(resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT);
|
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::string logLine = "[GroupChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, resp);
|
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::string logLine = "[GroupMenuChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
||||||
|
|
||||||
std::cout << logLine << std::endl;
|
std::cout << logLine << std::endl;
|
||||||
dump.push_back(logLine);
|
Monitor::chats.push_back(logLine);
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp);
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Chat {
|
namespace Chat {
|
||||||
extern std::vector<std::string> dump;
|
|
||||||
extern std::vector<std::string> bcasts;
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void sendServerMessage(CNSocket* sock, std::string msg); // uses MOTD
|
void sendServerMessage(CNSocket* sock, std::string msg); // uses MOTD
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "core/Core.hpp"
|
#include "core/Core.hpp"
|
||||||
#include "db/Database.hpp"
|
#include "db/Database.hpp"
|
||||||
#include "servers/CNShardServer.hpp"
|
#include "servers/CNShardServer.hpp"
|
||||||
|
#include "servers/Monitor.hpp"
|
||||||
|
|
||||||
#include "PlayerManager.hpp"
|
#include "PlayerManager.hpp"
|
||||||
#include "Items.hpp"
|
#include "Items.hpp"
|
||||||
@ -10,8 +11,6 @@
|
|||||||
|
|
||||||
using namespace Email;
|
using namespace Email;
|
||||||
|
|
||||||
std::vector<std::string> Email::dump;
|
|
||||||
|
|
||||||
// New email notification
|
// New email notification
|
||||||
static void emailUpdateCheck(CNSocket* sock, CNPacketData* data) {
|
static void emailUpdateCheck(CNSocket* sock, CNPacketData* data) {
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_NEW_EMAIL, resp);
|
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::string logEmail = "[Email] " + PlayerManager::getPlayerName(plr, true) + " (to " + PlayerManager::getPlayerName(&otherPlr, true) + "): <" + email.SubjectLine + ">\n" + email.MsgBody;
|
||||||
std::cout << logEmail << std::endl;
|
std::cout << logEmail << std::endl;
|
||||||
dump.push_back(logEmail);
|
Monitor::emails.push_back(logEmail);
|
||||||
|
|
||||||
// notification to recipient if online
|
// notification to recipient if online
|
||||||
CNSocket* recipient = PlayerManager::getSockFromID(pkt->iTo_PCUID);
|
CNSocket* recipient = PlayerManager::getSockFromID(pkt->iTo_PCUID);
|
||||||
|
@ -4,7 +4,5 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Email {
|
namespace Email {
|
||||||
extern std::vector<std::string> dump;
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,12 @@ static std::mutex sockLock; // guards socket list
|
|||||||
static std::list<SOCKET> sockets;
|
static std::list<SOCKET> sockets;
|
||||||
static sockaddr_in address;
|
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) {
|
static bool transmit(std::list<SOCKET>::iterator& it, char *buff, int len) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int sock = *it;
|
int sock = *it;
|
||||||
@ -99,7 +105,7 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// chat
|
// chat
|
||||||
for (auto& str : Chat::dump) {
|
for (auto& str : chats) {
|
||||||
n = std::snprintf(buff, sizeof(buff), "chat %s\n", str.c_str());
|
n = std::snprintf(buff, sizeof(buff), "chat %s\n", str.c_str());
|
||||||
|
|
||||||
if (!transmit(it, buff, n))
|
if (!transmit(it, buff, n))
|
||||||
@ -107,7 +113,7 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// announcements
|
// announcements
|
||||||
for (auto& str : Chat::bcasts) {
|
for (auto& str : bcasts) {
|
||||||
n = std::snprintf(buff, sizeof(buff), "bcast %s\n", str.c_str());
|
n = std::snprintf(buff, sizeof(buff), "bcast %s\n", str.c_str());
|
||||||
|
|
||||||
if (!transmit(it, buff, n))
|
if (!transmit(it, buff, n))
|
||||||
@ -115,7 +121,7 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// emails
|
// emails
|
||||||
for (auto& str : Email::dump) {
|
for (auto& str : emails) {
|
||||||
n = process_email(buff, str);
|
n = process_email(buff, str);
|
||||||
|
|
||||||
if (!transmit(it, buff, n))
|
if (!transmit(it, buff, n))
|
||||||
@ -131,9 +137,9 @@ outer:
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chat::dump.clear();
|
chats.clear();
|
||||||
Chat::bcasts.clear();
|
bcasts.clear();
|
||||||
Email::dump.clear();
|
emails.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) {
|
bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) {
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
#include "core/Core.hpp"
|
#include "core/Core.hpp"
|
||||||
|
|
||||||
namespace Monitor {
|
namespace Monitor {
|
||||||
|
extern std::vector<std::string> chats;
|
||||||
|
extern std::vector<std::string> bcasts;
|
||||||
|
extern std::vector<std::string> emails;
|
||||||
|
|
||||||
SOCKET init();
|
SOCKET init();
|
||||||
bool acceptConnection(SOCKET, uint16_t);
|
bool acceptConnection(SOCKET, uint16_t);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user