GPResult gpiAuthBuddyRequest ( GPConnection * connection, GPProfile profile ) { GPIProfile * pProfile; GPIConnection * iconnection = (GPIConnection*)*connection; // Get the profile object. ////////////////////////// if(!gpiGetProfile(connection, profile, &pProfile)) Error(connection, GP_PARAMETER_ERROR, "Invalid profile."); // Check for a valid sig. ///////////////////////// if(!pProfile->authSig) Error(connection, GP_PARAMETER_ERROR, "Invalid profile."); // Send the request. //////////////////// CHECK_RESULT(gpiSendAuthBuddyRequest(connection, pProfile)); // freeclear the sig if no more requests. //////////////////////////////////// pProfile->requestCount--; if(!iconnection->infoCaching && (pProfile->requestCount <= 0)) { freeclear(pProfile->authSig); if(gpiCanFreeProfile(pProfile)) gpiRemoveProfile(connection, pProfile); } return GP_NO_ERROR; }
static GPIBool gpiDisconnectCleanupProfile( GPConnection * connection, GPIProfile * profile, void * data ) { GPIConnection * iconnection = (GPIConnection*)*connection; GSI_UNUSED(data); // Even if we cache buddy/block info, free it up to get rid of mem // leaks, just don't remove the profile until we save the cache. ////////////////////////////////////////////////////////////////// if(profile->buddyStatus) { profile->buddyOrBlockCache = gsi_true; freeclear(profile->buddyStatus->statusString); freeclear(profile->buddyStatus->locationString); freeclear(profile->buddyStatus); } if (profile->buddyStatusInfo) { profile->buddyOrBlockCache = gsi_true; freeclear(profile->buddyStatusInfo->richStatus); freeclear(profile->buddyStatusInfo->gameType); freeclear(profile->buddyStatusInfo->gameVariant); freeclear(profile->buddyStatusInfo->gameMapName); if (profile->buddyStatusInfo->extendedInfoKeys) { ArrayFree(profile->buddyStatusInfo->extendedInfoKeys); profile->buddyStatusInfo->extendedInfoKeys = NULL; } freeclear(profile->buddyStatusInfo); } if (profile->blocked) profile->buddyOrBlockCache = gsi_true; freeclear(profile->authSig); freeclear(profile->peerSig); profile->requestCount = 0; // Remove Profile if: // (there is no info to cache) or // (we only cache buddies/blocked and the user is not a buddy or a block) if ((!profile->cache) || (iconnection->infoCachingBuddyAndBlockOnly==GPITrue && !profile->buddyOrBlockCache)) { gpiRemoveProfile(connection, profile); return GPIFalse; } return GPITrue; }
GPResult gpiDeleteBuddy( GPConnection * connection, GPProfile profile, GPIBool sendServerRequest ) { GPIProfile * pProfile; GPIConnection * iconnection = (GPIConnection*)*connection; int index; // Get the profile object. ////////////////////////// if(!gpiGetProfile(connection, profile, &pProfile)) Error(connection, GP_PARAMETER_ERROR, "Invalid profile."); // Check that this is a buddy. ////////////////////////////// // Removed - 092404 BED - User could be a buddy even though we don't have the status //if(!pProfile->buddyStatus) // Error(connection, GP_PARAMETER_ERROR, "Profile not a buddy."); // Send the request. //////////////////// if (GPITrue == sendServerRequest) { gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\delbuddy\\"); gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\sesskey\\"); gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->sessKey); gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\delprofileid\\"); gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, pProfile->profileId); gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\final\\"); } // Need to fix up the buddy indexes. //////////////////////////////////// if (pProfile->buddyStatus) { index = pProfile->buddyStatus->buddyIndex; assert(index >= 0); freeclear(pProfile->buddyStatus->statusString); freeclear(pProfile->buddyStatus->locationString); freeclear(pProfile->buddyStatus); if(gpiCanFreeProfile(pProfile)) gpiRemoveProfile(connection, pProfile); iconnection->profileList.numBuddies--; assert(iconnection->profileList.numBuddies >= 0); #ifndef _PS2 gpiProfileMap(connection, gpiFixBuddyIndices, (void *)(unsigned long)index); #else gpiProfileMap(connection, gpiFixBuddyIndices, (void *)index); #endif } if (pProfile->buddyStatusInfo) { index = pProfile->buddyStatusInfo->buddyIndex; assert(index >= 0); freeclear(pProfile->buddyStatusInfo->richStatus); freeclear(pProfile->buddyStatusInfo->gameType); freeclear(pProfile->buddyStatusInfo->gameVariant); freeclear(pProfile->buddyStatusInfo->gameMapName); freeclear(pProfile->buddyStatusInfo); if (pProfile->buddyStatusInfo->extendedInfoKeys) { ArrayFree(pProfile->buddyStatusInfo->extendedInfoKeys); pProfile->buddyStatusInfo->extendedInfoKeys = NULL; } if(gpiCanFreeProfile(pProfile)) gpiRemoveProfile(connection, pProfile); iconnection->profileList.numBuddies--; assert(iconnection->profileList.numBuddies >= 0); #ifndef _PS2 gpiProfileMap(connection, gpiFixBuddyIndices, (void *)(unsigned long)index); #else gpiProfileMap(connection, gpiFixBuddyIndices, (void *)index); #endif } return GP_NO_ERROR; }
//FUNCTIONS /////////// static GPResult gpiProcessPeerInitiatingConnection( GPConnection * connection, GPIPeer * peer ) { GPIConnection * iconnection = (GPIConnection*)*connection; //int state; char * str = NULL; //int len; GPIBool connClosed; GPIProfile * pProfile; GPResult result; GSUdpPeerState aPeerState; GS_ASSERT(peer); if (!peer) return GP_NETWORK_ERROR; GS_ASSERT(peer->state != GPI_PEER_DISCONNECTED && peer->state != GPI_PEER_NOT_CONNECTED); if (peer->state == GPI_PEER_DISCONNECTED || peer->state == GPI_PEER_NOT_CONNECTED) return GP_NETWORK_ERROR; // Check the state. /////////////////// switch(peer->state) { case GPI_PEER_GETTING_SIG: // Do nothing - we're waiting for getinfo to get the sig. ///////////////////////////////////////////////////////// break; case GPI_PEER_GOT_SIG: { // Start the connect. ///////////////////// gsDebugFormat(GSIDebugCat_GP, GSIDebugType_State, GSIDebugLevel_Verbose, "Got the peer signature for profileid: %d\n", peer->profile); CHECK_RESULT(gpiPeerStartConnect(connection, peer)); break; } case GPI_PEER_CONNECTING: { // Check if the connect finished. ///////////////////////////////// /* CHECK_RESULT(gpiCheckSocketConnect(connection, peer->sock, &state)); if(state == GPI_DISCONNECTED) { Error(connection, GP_NETWORK_ERROR, "Error connecting to a peer."); } */ gsUdpEngineGetPeerState(peer->ip, peer->port, &aPeerState); if(aPeerState == GS_UDP_PEER_CONNECTED) { GPIPeer * pcurr; GPIBool freePeerSig = GPITrue; // Get the profile object. ////////////////////////// if(!gpiGetProfile(connection, peer->profile, &pProfile)) Error(connection, GP_NETWORK_ERROR, "Error connecting to a peer."); // Send the auth. ///////////////// gpiAppendStringToBuffer(connection, &peer->outputBuffer, "\\auth\\"); gpiAppendStringToBuffer(connection, &peer->outputBuffer, "\\pid\\"); gpiAppendIntToBuffer(connection, &peer->outputBuffer, iconnection->profileid); gpiAppendStringToBuffer(connection, &peer->outputBuffer, "\\nick\\"); gpiAppendStringToBuffer(connection, &peer->outputBuffer, iconnection->nick); gpiAppendStringToBuffer(connection, &peer->outputBuffer, "\\sig\\"); gpiAppendStringToBuffer(connection, &peer->outputBuffer, pProfile->peerSig); gpiAppendStringToBuffer(connection, &peer->outputBuffer, "\\final\\"); // Are there any other peers still connecting? ////////////////////////////////////////////// for(pcurr = iconnection->peerList ; pcurr != NULL ; pcurr = pcurr->pnext) if((pcurr->profile == peer->profile) && (pcurr != peer)) if(pcurr->state <= GPI_PEER_CONNECTING) freePeerSig = GPIFalse; // freeclear it? /////////// if(freePeerSig) { freeclear(pProfile->peerSig); if(gpiCanFreeProfile(pProfile)) gpiRemoveProfile(connection, pProfile); } // Update the state. //////////////////// peer->state = GPI_PEER_WAITING; } break; } case GPI_PEER_WAITING: { // Check for a response. //////////////////////// //CHECK_RESULT(gpiRecvToBuffer(connection, peer->sock, &peer->inputBuffer, &len, &connClosed, "PR")); // Check for a final. ///////////////////// if (peer->inputBuffer.buffer) str = strstr(peer->inputBuffer.buffer, "\\final\\"); if(str != NULL) { str[0] = '\0'; str += 7; // Was it rejected? /////////////////// if(strncmp(peer->inputBuffer.buffer, "\\anack\\", 7) == 0) { // Rejected. //////////// peer->nackCount++; // Is this more than once? ////////////////////////// if(peer->nackCount > 1) { // we shouldn't reach this case unless there is a problem with // the server when getting a buddy's signature // Give up already. /////////////////// Error(connection, GP_NETWORK_ERROR, "Error getting buddy authorization."); } // Try getting the latest sig. ////////////////////////////// CHECK_RESULT(gpiPeerGetSig(connection, peer)); } else if(strncmp(peer->inputBuffer.buffer, "\\aack\\", 6) != 0) { // Unknown message. /////////////////// Error(connection, GP_NETWORK_ERROR, "Error parsing buddy message."); } // The connection has been established. /////////////////////////////////////// peer->state = GPI_PEER_CONNECTED; peer->inputBuffer.len = 0; } break; } // code should not reach here. default: break; } // Send stuff that needs to be sent. //////////////////////////////////// if(peer->outputBuffer.len > 0) { //result = gpiSendFromBuffer(connection, peer->sock, &peer->outputBuffer, &connClosed, GPITrue, "PR"); result = gpiSendBufferToPeer(connection, peer->ip, peer->port, &peer->outputBuffer, &connClosed, GPITrue); if(connClosed || (result != GP_NO_ERROR)) peer->state = GPI_PEER_DISCONNECTED; } return GP_NO_ERROR; }