Fix players being able to become buddies twice

This commit is contained in:
Gent 2020-11-09 04:41:20 -05:00
parent f0ded0886c
commit 8a68958ed4
2 changed files with 11 additions and 2 deletions

View File

@ -170,7 +170,7 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) {
if (slotA == -1 || slotB == -1)
return; // sanity check
if (req->iAcceptFlag == 1 && plr->iID != otherPlr->iID)
if (req->iAcceptFlag == 1 && plr->iID != otherPlr->iID && !playerHasBuddyWithID(plr, otherPlr->iID))
{
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp);
@ -250,7 +250,7 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) {
if (slotA == -1 || slotB == -1)
return; // sanity check
if (pkt->iAcceptFlag == 1 && plr->iID != otherPlr->iID) {
if (pkt->iAcceptFlag == 1 && plr->iID != otherPlr->iID && !playerHasBuddyWithID(plr, otherPlr->iID)) {
INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp);
// A to B
@ -716,4 +716,12 @@ bool BuddyManager::NameCheck(char16_t reqName[], char16_t resName[], int sizeOfL
return true;
}
bool BuddyManager::playerHasBuddyWithID(Player* plr, int buddyID) {
for (int i = 0; i < 50; i++) {
if (plr->buddyIDs[i] == buddyID)
return true;
}
return false;
}
#pragma endregion

View File

@ -51,4 +51,5 @@ namespace BuddyManager {
// Name checks
int getAvailableBuddySlot(Player* plr);
bool NameCheck(char16_t reqName[], char16_t resName[], int sizeOfReq, int sizeOfRes); // checks if the request and requested player's names match
bool playerHasBuddyWithID(Player* plr, int buddyID);
}