mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +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))
|
if (data->size != sizeof(sP_CL2FE_REQ_REQUEST_MAKE_BUDDY))
|
||||||
return; // malformed packet
|
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;
|
return;
|
||||||
|
|
||||||
sP_CL2FE_REQ_REQUEST_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_REQUEST_MAKE_BUDDY*)data->buf;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
CNSocket* otherSock = PlayerManager::getSockFromID(otherPlr->iID);
|
||||||
|
|
||||||
|
if (otherSock == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, resp);
|
||||||
|
INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, otherResp);
|
||||||
|
|
||||||
CNSocket* otherSock = sock;
|
resp.iRequestID = plr->iID;
|
||||||
|
resp.iBuddyID = req->iBuddyID;
|
||||||
|
resp.iBuddyPCUID = req->iBuddyPCUID;
|
||||||
|
|
||||||
for (auto pair : PlayerManager::players) {
|
otherResp.iRequestID = plr->iID;
|
||||||
if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
otherResp.iBuddyID = req->iBuddyID;
|
||||||
otherSock = pair.first;
|
memcpy(otherResp.szFirstName, plr->PCStyle.szFirstName, sizeof(plr->PCStyle.szFirstName));
|
||||||
break;
|
memcpy(otherResp.szLastName, plr->PCStyle.szLastName, sizeof(plr->PCStyle.szLastName));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerView& plr = PlayerManager::players[otherSock];
|
std::cout << "Buddy ID: " << req->iBuddyID << std::endl;
|
||||||
|
|
||||||
resp.iRequestID = plr.plr->iID;
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC));
|
||||||
resp.iBuddyID = plr.plr->iID;
|
otherSock->sendPacket((void*)&otherResp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER));
|
||||||
resp.iBuddyPCUID = plr.plr->PCStyle.iPC_UID;
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +88,7 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) {
|
|||||||
for (auto pair : PlayerManager::players) {
|
for (auto pair : PlayerManager::players) {
|
||||||
int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9;
|
int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9;
|
||||||
int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17;
|
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;
|
otherSock = pair.first;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -98,62 +108,65 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) {
|
|||||||
if (data->size != sizeof(sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY))
|
if (data->size != sizeof(sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
|
|
||||||
sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY*)data->buf;
|
sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY* req = (sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY*)data->buf;
|
||||||
Player* plrReq = PlayerManager::getPlayer(sock);
|
Player* plr = PlayerManager::getPlayer(sock);
|
||||||
|
Player* otherPlr = PlayerManager::getPlayerFromID(req->iBuddyID);
|
||||||
|
|
||||||
if (plrReq == nullptr)
|
if (plr == nullptr || otherPlr == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp);
|
||||||
|
|
||||||
CNSocket* otherSock = sock;
|
CNSocket* otherSock = PlayerManager::getSockFromID(otherPlr->iID);
|
||||||
|
|
||||||
for (auto pair : PlayerManager::players) {
|
resp.iBuddySlot = plr->buddyCnt;
|
||||||
if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
resp.BuddyInfo.iID = otherPlr->iID;
|
||||||
otherSock = pair.first;
|
resp.BuddyInfo.iPCUID = otherPlr->PCStyle.iPC_UID;
|
||||||
break;
|
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)
|
||||||
PlayerView& plr = PlayerManager::players[otherSock];
|
resp.BuddyInfo.iNameCheckFlag = otherPlr->PCStyle.iNameCheck;
|
||||||
|
memcpy(resp.BuddyInfo.szFirstName, otherPlr->PCStyle.szFirstName, sizeof(otherPlr->PCStyle.szFirstName));
|
||||||
if (pkt->iAcceptFlag == 1) {
|
memcpy(resp.BuddyInfo.szLastName, otherPlr->PCStyle.szLastName, sizeof(otherPlr->PCStyle.szLastName));
|
||||||
//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));
|
|
||||||
|
|
||||||
|
if (req->iAcceptFlag == 1)
|
||||||
|
{
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
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
|
plr->buddyIDs[plr->buddyCnt] = otherPlr->PCStyle.iPC_UID;
|
||||||
if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
std::cout << "Buddy's ID: " << plr->buddyIDs[plr->buddyCnt] << std::endl;
|
||||||
resp.BuddyInfo.iID = plrReq->iID;
|
plr->buddyCnt++;
|
||||||
resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID;
|
|
||||||
resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck;
|
|
||||||
resp.BuddyInfo.iPCState = plrReq->iPCState;
|
if (plr->iID != otherPlr->iID)
|
||||||
resp.BuddyInfo.iGender = plrReq->PCStyle.iGender;
|
{
|
||||||
resp.BuddyInfo.bBlocked = 0;
|
resp.iBuddySlot = otherPlr->buddyCnt;
|
||||||
resp.BuddyInfo.bFreeChat = 1;
|
resp.BuddyInfo.iID = plr->iID;
|
||||||
memcpy(resp.BuddyInfo.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName));
|
resp.BuddyInfo.iPCUID = plr->PCStyle.iPC_UID;
|
||||||
memcpy(resp.BuddyInfo.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName));
|
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));
|
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
|
otherPlr->buddyIDs[otherPlr->buddyCnt] = plr->PCStyle.iPC_UID;
|
||||||
|
std::cout << "Buddy's ID: " << plr->buddyIDs[plr->buddyCnt] << std::endl;
|
||||||
|
otherPlr->buddyCnt++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp);
|
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp);
|
||||||
|
|
||||||
declineResp.iErrorCode = 6; // Buddy declined notification
|
declineResp.iErrorCode = 6; // Buddy declined notification
|
||||||
declineResp.iBuddyID = pkt->iBuddyID;
|
declineResp.iBuddyID = req->iBuddyID;
|
||||||
declineResp.iBuddyPCUID = pkt->iBuddyPCUID;
|
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
|
// Accepting buddy request from the find name request
|
||||||
@ -178,7 +191,7 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
|
|||||||
for (auto pair : PlayerManager::players) {
|
for (auto pair : PlayerManager::players) {
|
||||||
int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9;
|
int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9;
|
||||||
int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17;
|
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;
|
otherSock = pair.first;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -186,12 +199,12 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
PlayerView& plr = PlayerManager::players[otherSock];
|
PlayerView& plr = PlayerManager::players[otherSock];
|
||||||
|
|
||||||
if (pkt->iAcceptFlag == 1) {
|
|
||||||
//resp.iBuddySlot = 0; // hard-coding this for now
|
resp.iBuddySlot = plrReq->buddyCnt;
|
||||||
//resp.BuddyInfo.iID = plrReq->iID;
|
resp.BuddyInfo.iID = plr.plr->iID;
|
||||||
resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID;
|
resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID;
|
||||||
resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck;
|
resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck;
|
||||||
resp.BuddyInfo.iPCState = plr.plr->iPCState;
|
resp.BuddyInfo.iPCState = 1;
|
||||||
resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender;
|
resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender;
|
||||||
resp.BuddyInfo.bBlocked = 0;
|
resp.BuddyInfo.bBlocked = 0;
|
||||||
resp.BuddyInfo.bFreeChat = 1;
|
resp.BuddyInfo.bFreeChat = 1;
|
||||||
@ -199,14 +212,20 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
|
|||||||
memcpy(resp.BuddyInfo.szFirstName, plr.plr->PCStyle.szFirstName, sizeof(plr.plr->PCStyle.szFirstName));
|
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));
|
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));
|
if (pkt->iAcceptFlag == 1)
|
||||||
buddyList(sock, resp.BuddyInfo);
|
{
|
||||||
|
|
||||||
if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) {
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC));
|
||||||
|
plrReq->buddyIDs[plrReq->buddyCnt] = plr.plr->PCStyle.iPC_UID;
|
||||||
|
plrReq->buddyCnt++;
|
||||||
|
|
||||||
|
if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID)
|
||||||
|
{
|
||||||
|
resp.iBuddySlot = plr.plr->buddyCnt;
|
||||||
resp.BuddyInfo.iID = plrReq->iID;
|
resp.BuddyInfo.iID = plrReq->iID;
|
||||||
resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID;
|
resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID;
|
||||||
resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck;
|
resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck;
|
||||||
resp.BuddyInfo.iPCState = plrReq->iPCState;
|
resp.BuddyInfo.iPCState = 1;
|
||||||
resp.BuddyInfo.iGender = plrReq->PCStyle.iGender;
|
resp.BuddyInfo.iGender = plrReq->PCStyle.iGender;
|
||||||
resp.BuddyInfo.bBlocked = 0;
|
resp.BuddyInfo.bBlocked = 0;
|
||||||
resp.BuddyInfo.bFreeChat = 1;
|
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));
|
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));
|
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);
|
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp);
|
||||||
|
|
||||||
declineResp.iErrorCode = 6; // Buddy declined notification
|
declineResp.iErrorCode = 6; // Buddy declined notification
|
||||||
declineResp.iBuddyID = plr.plr->iID;
|
|
||||||
declineResp.iBuddyPCUID = pkt->iBuddyPCUID;
|
declineResp.iBuddyPCUID = pkt->iBuddyPCUID;
|
||||||
|
|
||||||
otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL));
|
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
|
// Getting buddy state
|
||||||
void BuddyManager::reqPktGetBuddyState(CNSocket* sock, CNPacketData* data) {
|
void BuddyManager::reqPktGetBuddyState(CNSocket* sock, CNPacketData* data) {
|
||||||
|
Player* plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp);
|
||||||
INITSTRUCT(sBuddyBaseInfo, buddyInfo);
|
|
||||||
|
|
||||||
for (int BuddySlot = 0; BuddySlot < 50; BuddySlot++) {
|
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.aBuddyState[plr->buddyCnt] = 1; // this sets every buddy to online. Will get the pcstate right directly from the DB.
|
||||||
resp.aBuddyID[BuddySlot] = buddyInfo.iID;
|
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));
|
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;
|
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);
|
INITSTRUCT(sP_FE2CL_REP_REMOVE_BUDDY_SUCC, resp);
|
||||||
|
|
||||||
resp.iBuddyPCUID = pkt->iBuddyPCUID;
|
resp.iBuddyPCUID = pkt->iBuddyPCUID;
|
||||||
resp.iBuddySlot = pkt->iBuddySlot;
|
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));
|
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
|
#pragma region Helper methods
|
||||||
|
|
||||||
void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr) {
|
bool BuddyManager::NameCheck(char16_t reqName[], char16_t resName[], int sizeOfLNReq, int sizeOfLNRes) {
|
||||||
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) {
|
|
||||||
// If lengths of array are not equal means
|
// If lengths of array are not equal means
|
||||||
// array are not equal
|
// array are not equal
|
||||||
if (sizeOfLNReq != sizeOfLNRes)
|
if (sizeOfLNReq != sizeOfLNRes)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Sort both arrays
|
// Sort both arrays
|
||||||
std::sort(reqLastName, reqLastName + sizeOfLNReq);
|
std::sort(reqName, reqName + sizeOfLNReq);
|
||||||
std::sort(resLastName, resLastName + sizeOfLNRes);
|
std::sort(resName, resName + sizeOfLNRes);
|
||||||
|
|
||||||
// Linearly compare elements
|
// Linearly compare elements
|
||||||
for (int i = 0; i < sizeOfLNReq; i++)
|
for (int i = 0; i < sizeOfLNReq; i++)
|
||||||
if (reqLastName[i] != resLastName[i])
|
if (reqName[i] != resName[i])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If all elements were same.
|
// If all elements were same.
|
||||||
|
@ -34,11 +34,7 @@ namespace BuddyManager {
|
|||||||
void reqBuddyWarp(CNSocket* sock, CNPacketData* data);
|
void reqBuddyWarp(CNSocket* sock, CNPacketData* data);
|
||||||
|
|
||||||
// helper methods
|
// 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
|
// 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 NameCheck(char16_t reqName[], char16_t resName[], int sizeOfReq, int sizeOfRes); // checks if the request and requested player's 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
|
|
||||||
}
|
}
|
||||||
|
@ -70,4 +70,7 @@ struct Player {
|
|||||||
int32_t iGroupConditionBitFlag;
|
int32_t iGroupConditionBitFlag;
|
||||||
|
|
||||||
bool notify;
|
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
|
// TODO: check if serialkey exists, if it doesn't send sP_FE2CL_REP_PC_ENTER_FAIL
|
||||||
Player plr = CNSharedData::getPlayer(enter->iEnterSerialKey);
|
Player plr = CNSharedData::getPlayer(enter->iEnterSerialKey);
|
||||||
|
|
||||||
|
plr.buddyCnt = 0;
|
||||||
|
std::cout << "Buddy Count: " << plr.buddyCnt << std::endl;
|
||||||
|
|
||||||
plr.groupCnt = 1;
|
plr.groupCnt = 1;
|
||||||
plr.iIDGroup = plr.groupIDs[0] = plr.iID;
|
plr.iIDGroup = plr.groupIDs[0] = plr.iID;
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ int main() {
|
|||||||
NanoManager::init();
|
NanoManager::init();
|
||||||
NPCManager::init();
|
NPCManager::init();
|
||||||
TransportManager::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();
|
GroupManager::init();
|
||||||
Database::open();
|
Database::open();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user