mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-23 11:50:04 +00:00
Buddy rework, adjustments, and fixes
I cleaned up the code a bit (I'll clean it up more as I make more progress) and fixed a bug with buddy slots. Now buddies aren't overwritten! A few reworks and adjustments I reworked the buddyIDs array to store only player UIDs instead of IDs. I also reworked buddy deleting so that it deletes buddies from the array. Code cleanup Cleaned up some of the code. I mainly just removed useless helper methods.
This commit is contained in:
parent
26460c0167
commit
262dca7dd6
@ -27,32 +27,42 @@ void BuddyManager::requestBuddy(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2FE_REQ_REQUEST_MAKE_BUDDY))
|
||||
return; // malformed packet
|
||||
|
||||
Player* plrReq = PlayerManager::getPlayer(sock);
|
||||
sP_CL2FE_REQ_REQUEST_MAKE_BUDDY* req = (sP_CL2FE_REQ_REQUEST_MAKE_BUDDY*)data->buf;
|
||||
|
||||
if (plrReq == nullptr)
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
Player* otherPlr = PlayerManager::getPlayerFromID(req->iBuddyID);
|
||||
|
||||
if (plr == nullptr || otherPlr == nullptr)
|
||||
return;
|
||||
|
||||
sP_CL2FE_REQ_REQUEST_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_REQUEST_MAKE_BUDDY*)data->buf;
|
||||
|
||||
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, resp);
|
||||
|
||||
CNSocket* otherSock = sock;
|
||||
|
||||
for (auto pair : PlayerManager::players) {
|
||||
if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
||||
otherSock = pair.first;
|
||||
break;
|
||||
}
|
||||
if (plr->buddyCnt >= 50 || otherPlr->buddyCnt >= 50)
|
||||
{
|
||||
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_FAIL, failResp);
|
||||
sock->sendPacket((void*)&failResp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_FAIL));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerView& plr = PlayerManager::players[otherSock];
|
||||
CNSocket* otherSock = PlayerManager::getSockFromID(otherPlr->iID);
|
||||
|
||||
resp.iRequestID = plr.plr->iID;
|
||||
resp.iBuddyID = plr.plr->iID;
|
||||
resp.iBuddyPCUID = plr.plr->PCStyle.iPC_UID;
|
||||
if (otherSock == nullptr)
|
||||
return;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC)); // informs the player that the request was sent
|
||||
requestedBuddy(otherSock, plrReq, plr); // The other player will see the request
|
||||
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, resp);
|
||||
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, otherResp);
|
||||
|
||||
resp.iRequestID = plr->iID;
|
||||
resp.iBuddyID = req->iBuddyID;
|
||||
resp.iBuddyPCUID = req->iBuddyPCUID;
|
||||
|
||||
otherResp.iRequestID = plr->iID;
|
||||
otherResp.iBuddyID = req->iBuddyID;
|
||||
memcpy(otherResp.szFirstName, plr->PCStyle.szFirstName, sizeof(plr->PCStyle.szFirstName));
|
||||
memcpy(otherResp.szLastName, plr->PCStyle.szLastName, sizeof(plr->PCStyle.szLastName));
|
||||
|
||||
std::cout << "Buddy ID: " << req->iBuddyID << std::endl;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC));
|
||||
otherSock->sendPacket((void*)&otherResp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER));
|
||||
|
||||
}
|
||||
|
||||
@ -78,7 +88,7 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) {
|
||||
for (auto pair : PlayerManager::players) {
|
||||
int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9;
|
||||
int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17;
|
||||
if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { // This long line of gorgeous parameters is to check if the player's name matches :eyes:
|
||||
if (BuddyManager::NameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::NameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { // This long line of gorgeous parameters is to check if the player's name matches :eyes:
|
||||
otherSock = pair.first;
|
||||
break;
|
||||
}
|
||||
@ -98,62 +108,65 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY))
|
||||
return; // malformed packet
|
||||
|
||||
sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY*)data->buf;
|
||||
Player* plrReq = PlayerManager::getPlayer(sock);
|
||||
sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY* req = (sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY*)data->buf;
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
Player* otherPlr = PlayerManager::getPlayerFromID(req->iBuddyID);
|
||||
|
||||
if (plrReq == nullptr)
|
||||
if (plr == nullptr || otherPlr == nullptr)
|
||||
return;
|
||||
|
||||
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp);
|
||||
|
||||
CNSocket* otherSock = sock;
|
||||
CNSocket* otherSock = PlayerManager::getSockFromID(otherPlr->iID);
|
||||
|
||||
for (auto pair : PlayerManager::players) {
|
||||
if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
||||
otherSock = pair.first;
|
||||
break;
|
||||
resp.iBuddySlot = plr->buddyCnt;
|
||||
resp.BuddyInfo.iID = otherPlr->iID;
|
||||
resp.BuddyInfo.iPCUID = otherPlr->PCStyle.iPC_UID;
|
||||
resp.BuddyInfo.iPCState = 1; //to show whether the other player is online or offline (hardcoded for now)
|
||||
resp.BuddyInfo.bBlocked = 0; //to show whether the other player is blocked (hardcoded for now)
|
||||
resp.BuddyInfo.iGender = otherPlr->PCStyle.iGender; //shows the other player's gender
|
||||
resp.BuddyInfo.bFreeChat = 1; //shows whether or not the other player has freechat on (hardcoded for now)
|
||||
resp.BuddyInfo.iNameCheckFlag = otherPlr->PCStyle.iNameCheck;
|
||||
memcpy(resp.BuddyInfo.szFirstName, otherPlr->PCStyle.szFirstName, sizeof(otherPlr->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, otherPlr->PCStyle.szLastName, sizeof(otherPlr->PCStyle.szLastName));
|
||||
|
||||
if (req->iAcceptFlag == 1)
|
||||
{
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
plr->buddyIDs[plr->buddyCnt] = otherPlr->PCStyle.iPC_UID;
|
||||
std::cout << "Buddy's ID: " << plr->buddyIDs[plr->buddyCnt] << std::endl;
|
||||
plr->buddyCnt++;
|
||||
|
||||
|
||||
if (plr->iID != otherPlr->iID)
|
||||
{
|
||||
resp.iBuddySlot = otherPlr->buddyCnt;
|
||||
resp.BuddyInfo.iID = plr->iID;
|
||||
resp.BuddyInfo.iPCUID = plr->PCStyle.iPC_UID;
|
||||
resp.BuddyInfo.iPCState = 1; //to show whether the other player is online or offline (hardcoded for now)
|
||||
resp.BuddyInfo.bBlocked = 0; //to show whether the other player is blocked (hardcoded for now)
|
||||
resp.BuddyInfo.iGender = plr->PCStyle.iGender; //shows the other player's gender
|
||||
resp.BuddyInfo.bFreeChat = 1; //shows whether or not the other player has freechat on (hardcoded for now)
|
||||
resp.BuddyInfo.iNameCheckFlag = plr->PCStyle.iNameCheck;
|
||||
memcpy(resp.BuddyInfo.szFirstName, plr->PCStyle.szFirstName, sizeof(plr->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, plr->PCStyle.szLastName, sizeof(plr->PCStyle.szLastName));
|
||||
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
otherPlr->buddyIDs[otherPlr->buddyCnt] = plr->PCStyle.iPC_UID;
|
||||
std::cout << "Buddy's ID: " << plr->buddyIDs[plr->buddyCnt] << std::endl;
|
||||
otherPlr->buddyCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerView& plr = PlayerManager::players[otherSock];
|
||||
|
||||
if (pkt->iAcceptFlag == 1) {
|
||||
//resp.iBuddySlot = 0; // hard-coding this for now
|
||||
resp.BuddyInfo.iID = pkt->iBuddyID;
|
||||
resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID;
|
||||
resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck;
|
||||
resp.BuddyInfo.iPCState = plr.plr->iPCState;
|
||||
resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender;
|
||||
resp.BuddyInfo.bBlocked = 0;
|
||||
resp.BuddyInfo.bFreeChat = 1;
|
||||
|
||||
memcpy(resp.BuddyInfo.szFirstName, plr.plr->PCStyle.szFirstName, sizeof(plr.plr->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, plr.plr->PCStyle.szLastName, sizeof(plr.plr->PCStyle.szLastName));
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
buddyList(sock, resp.BuddyInfo); // saves buddy data to player's buddylist
|
||||
if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
||||
resp.BuddyInfo.iID = plrReq->iID;
|
||||
resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID;
|
||||
resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck;
|
||||
resp.BuddyInfo.iPCState = plrReq->iPCState;
|
||||
resp.BuddyInfo.iGender = plrReq->PCStyle.iGender;
|
||||
resp.BuddyInfo.bBlocked = 0;
|
||||
resp.BuddyInfo.bFreeChat = 1;
|
||||
memcpy(resp.BuddyInfo.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName));
|
||||
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
buddyList(otherSock, resp.BuddyInfo); // saves requester's data to this player's buddylist
|
||||
}
|
||||
} else {
|
||||
else
|
||||
{
|
||||
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp);
|
||||
|
||||
declineResp.iErrorCode = 6; // Buddy declined notification
|
||||
declineResp.iBuddyID = pkt->iBuddyID;
|
||||
declineResp.iBuddyPCUID = pkt->iBuddyPCUID;
|
||||
declineResp.iBuddyID = req->iBuddyID;
|
||||
declineResp.iBuddyPCUID = req->iBuddyPCUID;
|
||||
|
||||
otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); // tells the requester that the player declined
|
||||
otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Accepting buddy request from the find name request
|
||||
@ -178,7 +191,7 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
|
||||
for (auto pair : PlayerManager::players) {
|
||||
int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9;
|
||||
int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17;
|
||||
if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) {
|
||||
if (BuddyManager::NameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::NameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) {
|
||||
otherSock = pair.first;
|
||||
break;
|
||||
}
|
||||
@ -186,27 +199,33 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
PlayerView& plr = PlayerManager::players[otherSock];
|
||||
|
||||
if (pkt->iAcceptFlag == 1) {
|
||||
//resp.iBuddySlot = 0; // hard-coding this for now
|
||||
//resp.BuddyInfo.iID = plrReq->iID;
|
||||
resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID;
|
||||
resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck;
|
||||
resp.BuddyInfo.iPCState = plr.plr->iPCState;
|
||||
resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender;
|
||||
resp.BuddyInfo.bBlocked = 0;
|
||||
resp.BuddyInfo.bFreeChat = 1;
|
||||
|
||||
memcpy(resp.BuddyInfo.szFirstName, plr.plr->PCStyle.szFirstName, sizeof(plr.plr->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, plr.plr->PCStyle.szLastName, sizeof(plr.plr->PCStyle.szLastName));
|
||||
resp.iBuddySlot = plrReq->buddyCnt;
|
||||
resp.BuddyInfo.iID = plr.plr->iID;
|
||||
resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID;
|
||||
resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck;
|
||||
resp.BuddyInfo.iPCState = 1;
|
||||
resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender;
|
||||
resp.BuddyInfo.bBlocked = 0;
|
||||
resp.BuddyInfo.bFreeChat = 1;
|
||||
|
||||
memcpy(resp.BuddyInfo.szFirstName, plr.plr->PCStyle.szFirstName, sizeof(plr.plr->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, plr.plr->PCStyle.szLastName, sizeof(plr.plr->PCStyle.szLastName));
|
||||
|
||||
if (pkt->iAcceptFlag == 1)
|
||||
{
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
buddyList(sock, resp.BuddyInfo);
|
||||
plrReq->buddyIDs[plrReq->buddyCnt] = plr.plr->PCStyle.iPC_UID;
|
||||
plrReq->buddyCnt++;
|
||||
|
||||
if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
||||
if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID)
|
||||
{
|
||||
resp.iBuddySlot = plr.plr->buddyCnt;
|
||||
resp.BuddyInfo.iID = plrReq->iID;
|
||||
resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID;
|
||||
resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck;
|
||||
resp.BuddyInfo.iPCState = plrReq->iPCState;
|
||||
resp.BuddyInfo.iPCState = 1;
|
||||
resp.BuddyInfo.iGender = plrReq->PCStyle.iGender;
|
||||
resp.BuddyInfo.bBlocked = 0;
|
||||
resp.BuddyInfo.bFreeChat = 1;
|
||||
@ -215,15 +234,17 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
|
||||
memcpy(resp.BuddyInfo.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName));
|
||||
|
||||
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
buddyList(otherSock, resp.BuddyInfo);
|
||||
plr.plr->buddyIDs[plr.plr->buddyCnt] = plrReq->PCStyle.iPC_UID;
|
||||
plr.plr->buddyCnt++;
|
||||
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp);
|
||||
|
||||
declineResp.iErrorCode = 6; // Buddy declined notification
|
||||
declineResp.iBuddyID = plr.plr->iID;
|
||||
declineResp.iBuddyPCUID = pkt->iBuddyPCUID;
|
||||
|
||||
otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL));
|
||||
}
|
||||
|
||||
@ -291,12 +312,13 @@ void BuddyManager::reqBuddyMenuchat(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
// Getting buddy state
|
||||
void BuddyManager::reqPktGetBuddyState(CNSocket* sock, CNPacketData* data) {
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp);
|
||||
INITSTRUCT(sBuddyBaseInfo, buddyInfo);
|
||||
|
||||
|
||||
for (int BuddySlot = 0; BuddySlot < 50; BuddySlot++) {
|
||||
resp.aBuddyState[BuddySlot] = 1; // this sets every buddy to online. Will get the pcstate right directly from the DB.
|
||||
resp.aBuddyID[BuddySlot] = buddyInfo.iID;
|
||||
//resp.aBuddyState[plr->buddyCnt] = 1; // this sets every buddy to online. Will get the pcstate right directly from the DB.
|
||||
resp.aBuddyID[BuddySlot] = plr->buddyIDs[BuddySlot];
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_GET_BUDDY_STATE_SUCC, sizeof(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC));
|
||||
}
|
||||
}
|
||||
@ -324,11 +346,19 @@ void BuddyManager::reqBuddyDelete(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
sP_CL2FE_REQ_REMOVE_BUDDY* pkt = (sP_CL2FE_REQ_REMOVE_BUDDY*)data->buf;
|
||||
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
if (plr == nullptr)
|
||||
return;
|
||||
|
||||
INITSTRUCT(sP_FE2CL_REP_REMOVE_BUDDY_SUCC, resp);
|
||||
|
||||
resp.iBuddyPCUID = pkt->iBuddyPCUID;
|
||||
resp.iBuddySlot = pkt->iBuddySlot;
|
||||
|
||||
plr->buddyIDs[resp.iBuddySlot] -= resp.iBuddyPCUID;
|
||||
plr->buddyCnt--;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_REMOVE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REMOVE_BUDDY_SUCC));
|
||||
}
|
||||
|
||||
@ -337,101 +367,19 @@ void BuddyManager::reqBuddyWarp(CNSocket* sock, CNPacketData* data) {} // stub
|
||||
|
||||
#pragma region Helper methods
|
||||
|
||||
void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr) {
|
||||
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, resp);
|
||||
|
||||
resp.iRequestID = plrReq->iID;
|
||||
resp.iBuddyID = plr.plr->iID;
|
||||
|
||||
memcpy(resp.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName));
|
||||
memcpy(resp.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName));
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER)); // player get the buddy request.
|
||||
|
||||
}
|
||||
|
||||
// Buddy list load
|
||||
void BuddyManager::buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo) {
|
||||
|
||||
size_t resplen = sizeof(sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC) + sizeof(sBuddyBaseInfo);
|
||||
uint8_t respbuf[4096];
|
||||
|
||||
memset(respbuf, 0, resplen);
|
||||
|
||||
sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC* resp = (sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC*)respbuf;
|
||||
sBuddyBaseInfo* respdata = (sBuddyBaseInfo*)(respbuf + sizeof(sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC));
|
||||
|
||||
resp->iID = BuddyInfo.iID;
|
||||
resp->iPCUID = BuddyInfo.iPCUID;
|
||||
|
||||
for (int i = 0; i < resp->iBuddyCnt && i < resp->iListNum; i++) {
|
||||
respdata->iID = BuddyInfo.iID;
|
||||
respdata->iPCUID = BuddyInfo.iPCUID;
|
||||
respdata->iGender = BuddyInfo.iGender;
|
||||
respdata->iPCState = BuddyInfo.iPCState;
|
||||
respdata->iNameCheckFlag = BuddyInfo.iNameCheckFlag;
|
||||
respdata->bBlocked = 0;
|
||||
respdata->bFreeChat = 1;
|
||||
memcpy(respdata->szFirstName, BuddyInfo.szFirstName, sizeof(BuddyInfo.szFirstName));
|
||||
memcpy(respdata->szLastName, BuddyInfo.szLastName, sizeof(BuddyInfo.szLastName));
|
||||
}
|
||||
|
||||
sock->sendPacket((void*)respbuf, P_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC, resplen); // updates/loads player's buddy list
|
||||
|
||||
}
|
||||
|
||||
// If the requested player accepts the buddy request, the requester's buddylist will get loaded up.
|
||||
void BuddyManager::otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr) {
|
||||
|
||||
// resp.iBuddySlot = 0; //hard-coding this for now
|
||||
resp.BuddyInfo.iID = BuddyID;
|
||||
resp.BuddyInfo.iPCUID = BuddyPCUID;
|
||||
resp.BuddyInfo.iNameCheckFlag = plr->PCStyle.iNameCheck;
|
||||
resp.BuddyInfo.iPCState = plr->iPCState;
|
||||
resp.BuddyInfo.iGender = plr->PCStyle.iGender;
|
||||
resp.BuddyInfo.bBlocked = 0;
|
||||
resp.BuddyInfo.bFreeChat = 1;
|
||||
|
||||
memcpy(resp.BuddyInfo.szFirstName, plr->PCStyle.szFirstName, sizeof(plr->PCStyle.szFirstName));
|
||||
memcpy(resp.BuddyInfo.szLastName, plr->PCStyle.szLastName, sizeof(plr->PCStyle.szLastName));
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||
buddyList(sock, resp.BuddyInfo);
|
||||
}
|
||||
|
||||
// Check if the requested name matches the requested player's name
|
||||
bool BuddyManager::firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes) {
|
||||
// If lengths of array are not equal means
|
||||
// array are not equal
|
||||
if (sizeOfReq != sizeOfRes)
|
||||
return false;
|
||||
|
||||
// Sort both arrays
|
||||
std::sort(reqFirstName, reqFirstName + sizeOfReq);
|
||||
std::sort(resFirstName, resFirstName + sizeOfRes);
|
||||
|
||||
// Linearly compare elements
|
||||
for (int i = 0; i < sizeOfReq; i++)
|
||||
if (reqFirstName[i] != resFirstName[i])
|
||||
return false;
|
||||
|
||||
// If all elements were same.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BuddyManager::lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes) {
|
||||
bool BuddyManager::NameCheck(char16_t reqName[], char16_t resName[], int sizeOfLNReq, int sizeOfLNRes) {
|
||||
// If lengths of array are not equal means
|
||||
// array are not equal
|
||||
if (sizeOfLNReq != sizeOfLNRes)
|
||||
return false;
|
||||
|
||||
// Sort both arrays
|
||||
std::sort(reqLastName, reqLastName + sizeOfLNReq);
|
||||
std::sort(resLastName, resLastName + sizeOfLNRes);
|
||||
std::sort(reqName, reqName + sizeOfLNReq);
|
||||
std::sort(resName, resName + sizeOfLNRes);
|
||||
|
||||
// Linearly compare elements
|
||||
for (int i = 0; i < sizeOfLNReq; i++)
|
||||
if (reqLastName[i] != resLastName[i])
|
||||
if (reqName[i] != resName[i])
|
||||
return false;
|
||||
|
||||
// If all elements were same.
|
||||
|
@ -34,11 +34,7 @@ namespace BuddyManager {
|
||||
void reqBuddyWarp(CNSocket* sock, CNPacketData* data);
|
||||
|
||||
// helper methods
|
||||
void requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr);
|
||||
void buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo); // updates the buddylist
|
||||
void otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr); // tells the other player that they are now buddies with the requester.
|
||||
|
||||
|
||||
// Name checks
|
||||
bool firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes); // checks if the request and requested player's first names match
|
||||
bool lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes); // checks if the request and requested player's last names match
|
||||
bool NameCheck(char16_t reqName[], char16_t resName[], int sizeOfReq, int sizeOfRes); // checks if the request and requested player's names match
|
||||
}
|
||||
|
@ -70,4 +70,7 @@ struct Player {
|
||||
int32_t iGroupConditionBitFlag;
|
||||
|
||||
bool notify;
|
||||
|
||||
int buddyCnt;
|
||||
int64_t buddyIDs[50];
|
||||
};
|
||||
|
@ -293,6 +293,9 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
// TODO: check if serialkey exists, if it doesn't send sP_FE2CL_REP_PC_ENTER_FAIL
|
||||
Player plr = CNSharedData::getPlayer(enter->iEnterSerialKey);
|
||||
|
||||
plr.buddyCnt = 0;
|
||||
std::cout << "Buddy Count: " << plr.buddyCnt << std::endl;
|
||||
|
||||
plr.groupCnt = 1;
|
||||
plr.iIDGroup = plr.groupIDs[0] = plr.iID;
|
||||
|
||||
|
@ -99,7 +99,7 @@ int main() {
|
||||
NanoManager::init();
|
||||
NPCManager::init();
|
||||
TransportManager::init();
|
||||
// BuddyManager::init(); // stubbed until we have database integration + lots of bug fixes
|
||||
BuddyManager::init(); // stubbed until we have database integration + lots of bug fixes
|
||||
GroupManager::init();
|
||||
Database::open();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user