From: <jo...@us...> - 2014-04-06 01:41:46
|
Revision: 9365 http://sourceforge.net/p/planeshift/code/9365 Author: joelyon Date: 2014-04-06 01:41:43 +0000 (Sun, 06 Apr 2014) Log Message: ----------- Prevent WorkManager::LockpickComplete operating on a workEvent Object that is no longer valid. Modified Paths: -------------- trunk/src/server/workmanager.cpp Modified: trunk/src/server/workmanager.cpp =================================================================== --- trunk/src/server/workmanager.cpp 2014-04-06 01:17:08 UTC (rev 9364) +++ trunk/src/server/workmanager.cpp 2014-04-06 01:41:43 UTC (rev 9365) @@ -4102,59 +4102,72 @@ void WorkManager::LockpickComplete(psWorkGameEvent* workEvent) { - psCharacter* character = workEvent->client->GetCharacterData(); - PSSKILL skill = workEvent->object->GetLockpickSkill(); - // Check if not moved too far away from lock - // First check if lock (object such as box) is in not inventory - // For now, that is never the case, but I can imagine that changing - if((PSCHARACTER_SLOT_NONE == workEvent->object->GetLocInParent()) && - (workEvent->client->GetActor()->RangeTo(workEvent->object->GetGemObject()) > RANGE_TO_USE)) + if( workEvent->object==NULL ) { - // Send denied message - psserver->SendSystemInfo(workEvent->client->GetClientNum(),"You failed your lockpicking attempt, because you moved away."); + psserver->SendSystemInfo(workEvent->client->GetClientNum(),"Lockpick target is no longer valid." ); } else { - // Check if the user has the right skills - int rank = 0; - if(skill >= 0 && skill < (PSSKILL)cacheManager->GetSkillAmount()) + psCharacter* character = workEvent->client->GetCharacterData(); + PSSKILL skill = workEvent->object->GetLockpickSkill(); + + if( workEvent->object->GetGemObject()==NULL ) { - rank = character->Skills().GetSkillRank(skill).Current(); + psserver->SendSystemInfo(workEvent->client->GetClientNum(),"Lockpick target is no longer valid." ); } - - if(rank >= (int) workEvent->object->GetLockStrength()) + else + // Check if not moved too far away from lock + // First check if lock (object such as box) is in not inventory + // For now, that is never the case, but I can imagine that changing + if((PSCHARACTER_SLOT_NONE == workEvent->object->GetLocInParent()) && + (workEvent->client->GetActor()->RangeTo(workEvent->object->GetGemObject()) > RANGE_TO_USE)) { - bool locked = workEvent->object->GetIsLocked(); - psserver->SendSystemOK(workEvent->client->GetClientNum(), locked ? "You unlocked %s." : "You locked %s.", workEvent->object->GetName()); - workEvent->object->SetIsLocked(!locked); - workEvent->object->Save(false); + // Send denied message + psserver->SendSystemInfo(workEvent->client->GetClientNum(),"You failed your lockpicking attempt, because you moved away."); + } + else + { + // Check if the user has the right skills + int rank = 0; + if(skill >= 0 && skill < (PSSKILL)cacheManager->GetSkillAmount()) + { + rank = character->Skills().GetSkillRank(skill).Current(); + } - // Calculate practice points. - - int practicePoints; - float modifier; + if(rank >= (int) workEvent->object->GetLockStrength()) { - MathEnvironment env; - env.Define("Object", workEvent->object); - env.Define("Worker", workEvent->client->GetCharacterData()); - env.Define("RequiredSkill", skill); - env.Define("PlayerSkill", rank); - env.Define("LockStrength", workEvent->object->GetLockStrength()); + bool locked = workEvent->object->GetIsLocked(); + psserver->SendSystemOK(workEvent->client->GetClientNum(), locked ? "You unlocked %s." : "You locked %s.", workEvent->object->GetName()); + workEvent->object->SetIsLocked(!locked); + workEvent->object->Save(false); - calc_lockpicking_exp->Evaluate(&env); - practicePoints = env.Lookup("ResultPractice")->GetRoundValue(); - modifier = env.Lookup("ResultModifier")->GetValue(); + // Calculate practice points. + + int practicePoints; + float modifier; + { + MathEnvironment env; + env.Define("Object", workEvent->object); + env.Define("Worker", workEvent->client->GetCharacterData()); + env.Define("RequiredSkill", skill); + env.Define("PlayerSkill", rank); + env.Define("LockStrength", workEvent->object->GetLockStrength()); + + calc_lockpicking_exp->Evaluate(&env); + practicePoints = env.Lookup("ResultPractice")->GetRoundValue(); + modifier = env.Lookup("ResultModifier")->GetValue(); + } + + // Assign points and exp. + workEvent->client->GetCharacterData()->CalculateAddExperience(skill, practicePoints, modifier); } - - // Assign points and exp. - workEvent->client->GetCharacterData()->CalculateAddExperience(skill, practicePoints, modifier); + else + { + // Send denied message + psserver->SendSystemInfo(workEvent->client->GetClientNum(),"You failed your lockpicking attempt."); + } } - else - { - // Send denied message - psserver->SendSystemInfo(workEvent->client->GetClientNum(),"You failed your lockpicking attempt."); - } } workEvent->client->GetActor()->SetMode(PSCHARACTER_MODE_PEACE); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |