Name request monitor events

This commit is contained in:
Gent Semaj 2025-01-02 18:06:06 -05:00
parent b483bf7190
commit e84f6505b8
Signed by untrusted user: ycc
GPG Key ID: 2D76C57BF6BEADC4
3 changed files with 25 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include "servers/CNLoginServer.hpp"
#include "servers/Monitor.hpp"
#include "core/CNShared.hpp"
#include "db/Database.hpp"
@ -312,6 +313,16 @@ void CNLoginServer::nameSave(CNSocket* sock, CNPacketData* data) {
std::cout << "[WARN] Login Server: Database failed to create new character!" << std::endl;
return invalidCharacter(sock);
}
Player plr;
Database::getPlayer(&plr, (int)resp.iPC_UID);
// fire name check event if needed
if (plr.PCStyle.iNameCheck == 0) {
std::string namereq = std::to_string(resp.iPC_UID) + " " + AUTOU16TOU8(save->szFirstName) + " " + AUTOU16TOU8(save->szLastName);
Monitor::namereqs.push_back(namereq);
}
resp.iSlotNum = save->iSlotNum;
resp.iGender = save->iGender;
@ -327,7 +338,9 @@ void CNLoginServer::nameSave(CNSocket* sock, CNPacketData* data) {
DEBUGLOG(
std::cout << "Login Server: new character created" << std::endl;
std::cout << "\tSlot: " << (int)save->iSlotNum << std::endl;
std::cout << "\tName: " << AUTOU16TOU8(save->szFirstName) << " " << AUTOU16TOU8(save->szLastName) << std::endl;
std::cout << "\tName: " << AUTOU16TOU8(save->szFirstName) << " " << AUTOU16TOU8(save->szLastName);
if (plr.PCStyle.iNameCheck == 0) std::cout << " (pending approval)";
std::cout << std::endl;
)
}

View File

@ -17,6 +17,7 @@ static sockaddr_in address;
std::vector<std::string> Monitor::chats;
std::vector<std::string> Monitor::bcasts;
std::vector<std::string> Monitor::emails;
std::vector<std::string> Monitor::namereqs;
using namespace Monitor;
@ -131,6 +132,14 @@ outer:
goto outer;
}
// name requests
for (auto& str : namereqs) {
n = std::snprintf(buff, sizeof(buff), "namereq %s\n", str.c_str());
if (!transmit(it, buff, n))
goto outer;
}
if (!transmit(it, (char*)"end\n", 4))
continue;
@ -140,6 +149,7 @@ outer:
chats.clear();
bcasts.clear();
emails.clear();
namereqs.clear();
}
bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) {

View File

@ -6,6 +6,7 @@ namespace Monitor {
extern std::vector<std::string> chats;
extern std::vector<std::string> bcasts;
extern std::vector<std::string> emails;
extern std::vector<std::string> namereqs;
SOCKET init();
bool acceptConnection(SOCKET, uint16_t);