From: Borrillis <bor...@us...> - 2005-12-02 13:44:38
|
Update of /cvsroot/planeshift/planeshift/src/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21043/src/server Modified Files: advicemanager.cpp Log Message: - Added some sanity checks Index: advicemanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/advicemanager.cpp,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** advicemanager.cpp 1 Dec 2005 22:09:33 -0000 1.49 --- advicemanager.cpp 2 Dec 2005 13:44:30 -0000 1.50 *************** *** 49,67 **** protected: ! csRef<SafeClientRef> advisor, advisee; ! AdviceManager *manager; public: ! uint32_t AdvisorClientNum; ! uint32_t AdviseeClientNum; ! csString adviseeName; ! psAdviceRequestTimeoutGameEvent *requestEvent; ! psAdviceSessionTimeoutGameEvent *timeoutEvent; ! csString lastRequest; ! int status; ! bool answered; ! size_t advisorPoints; ! int requestRetries; AdviceSession() --- 49,68 ---- protected: ! csRef<SafeClientRef> advisor, // Safe reference to the client who has indicated they can assist other users. ! advisee; // Safe refereneces to the client who is requesting help. ! AdviceManager *manager; // The parent controller public: ! uint32_t AdvisorClientNum; // cache the client number for the Advisor ! uint32_t AdviseeClientNum; // cache the client number for the Advisee ! csString adviseeName; // cache the name of the advisee ! psAdviceRequestTimeoutGameEvent *requestEvent; // event to cancel the current request ! psAdviceSessionTimeoutGameEvent *timeoutEvent; // event to cancel the current session ! csString lastRequest; // cache the text of the last request ! int status; // current status of the session -- this should be changed to an enum ! bool answered; // has the initial question been answered? ! size_t advisorPoints; // current value in advisor points for this session. ! int requestRetries; // how many times the current request has been resent. AdviceSession() *************** *** 120,123 **** --- 121,125 ---- void SetAdvisor( Client *newAdvisor) { + // A NULL advisor is valid here, just clear the current advisor and return if ( newAdvisor == NULL ) { *************** *** 125,130 **** --- 127,136 ---- return; } + + // if there is a current advisor, unattach ourselves if ( advisor && advisor->clientptr ) advisor->clientptr->GetActor()->Unregister( this ); + + // assign new advisor advisor = newAdvisor->GetSafeReference(); AdvisorClientNum = advisor->clientptr->GetClientNum(); *************** *** 192,202 **** //Handle dependencies ourselves since we have two. ! adviseeActor = adviceSession->GetAdvisee()->clientptr->GetActor(); ! adviseeActor->Register( this ); if ( adviceSession->GetAdvisor() ) { advisorActor = adviceSession->GetAdvisor()->clientptr->GetActor(); ! advisorActor->Register( this ); } else advisorActor = NULL; --- 198,212 ---- //Handle dependencies ourselves since we have two. ! if ( adviceSession->GetAdvisee() ) ! { ! adviseeActor = adviceSession->GetAdvisee()->clientptr->GetActor(); ! if ( adviseeActor ) adviseeActor->Register( this ); ! } ! else adviseeActor = NULL; if ( adviceSession->GetAdvisor() ) { advisorActor = adviceSession->GetAdvisor()->clientptr->GetActor(); ! if ( advisorActor ) advisorActor->Register( this ); } else advisorActor = NULL; *************** *** 210,215 **** if ( advisorActor != NULL ) advisorActor->Unregister( this ); advisorActor = NULL; ! if(adviceSession->requestEvent == this) ! adviceSession->requestEvent = NULL; } --- 220,225 ---- if ( advisorActor != NULL ) advisorActor->Unregister( this ); advisorActor = NULL; ! ! if ( adviceSession->requestEvent == this ) adviceSession->requestEvent = NULL; } *************** *** 218,228 **** gemActor *sender = (gemActor *)object; ! if ( sender == adviseeActor ) { ! psGEMEvent::Disconnecting( object ); ! adviseeActor->Unregister( this ); ! if ( advisorActor ) advisorActor->Unregister( this ); ! adviseeActor = advisorActor = NULL; ! return; } --- 228,241 ---- gemActor *sender = (gemActor *)object; ! if ( adviseeActor ) { ! if ( sender == adviseeActor ) ! { ! psGEMEvent::Disconnecting( object ); ! adviseeActor->Unregister( this ); ! if ( advisorActor ) advisorActor->Unregister( this ); ! adviseeActor = advisorActor = NULL; ! return; ! } } *************** *** 259,267 **** //Handle dependencies ourselves since we have two. ! adviseeActor = adviceSession->GetAdvisee()->clientptr->GetActor(); ! adviseeActor->Register( this ); ! advisorActor = adviceSession->GetAdvisor()->clientptr->GetActor(); ! advisorActor->Register( this ); }; --- 272,289 ---- //Handle dependencies ourselves since we have two. ! if ( adviceSession->GetAdvisee() != NULL ) ! { ! adviseeActor = adviceSession->GetAdvisee()->clientptr->GetActor(); ! if ( adviseeActor ) adviseeActor->Register( this ); ! } ! // This should only happen when this is an unanswered question. ! // This event is canceled and recreated each time there is any activity on the session, ! // so this should be filled in when an advisor either claims or answers the question. ! if ( adviceSession->GetAdvisor() != NULL ) ! { ! advisorActor = adviceSession->GetAdvisor()->clientptr->GetActor(); ! if ( advisorActor ) advisorActor->Register( this ); ! } }; *************** *** 269,281 **** psAdviceSessionTimeoutGameEvent::~psAdviceSessionTimeoutGameEvent() { ! if ( adviseeActor != NULL ) ! adviseeActor->Unregister( this ); adviseeActor = NULL; ! if ( advisorActor != NULL ) ! advisorActor->Unregister( this ); advisorActor = NULL; ! if(adviceSession->timeoutEvent == this) ! adviceSession->timeoutEvent = NULL; } --- 291,301 ---- psAdviceSessionTimeoutGameEvent::~psAdviceSessionTimeoutGameEvent() { ! if ( adviseeActor != NULL ) adviseeActor->Unregister( this ); adviseeActor = NULL; ! if ( advisorActor != NULL ) advisorActor->Unregister( this ); advisorActor = NULL; ! ! if ( adviceSession->timeoutEvent == this )adviceSession->timeoutEvent = NULL; } *************** *** 285,294 **** //Handle dependencies ourselves since we have two. ! if ( adviseeActor != NULL) ! adviseeActor->Unregister( this ); adviseeActor = NULL; ! if ( advisorActor != NULL ) ! advisorActor->Unregister( this ); advisorActor = NULL; }; --- 305,312 ---- //Handle dependencies ourselves since we have two. ! if ( adviseeActor != NULL) adviseeActor->Unregister( this ); adviseeActor = NULL; ! if ( advisorActor != NULL ) advisorActor->Unregister( this ); advisorActor = NULL; }; |