From: DaveG <da...@us...> - 2006-03-02 00:28:38
|
Update of /cvsroot/planeshift/planeshift/src/server/bulkobjects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16742/src/server/bulkobjects Modified Files: psitem.cpp psitem.h Log Message: fixing crash from save on removing an item from an exchange; putting the optional save flag on the stacking functions, so stacking doesn't have to be done manually (they are the only functions that may save that should be optional, anyway) Index: psitem.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/psitem.cpp,v retrieving revision 1.169 retrieving revision 1.170 diff -C2 -d -r1.169 -r1.170 *** psitem.cpp 26 Feb 2006 08:38:19 -0000 1.169 --- psitem.cpp 2 Mar 2006 00:28:30 -0000 1.170 *************** *** 1524,1549 **** } ! psItem *psItem::SplitStack(unsigned short newstackcount) { - psItem *newitem; - // Cannot split into a stack of 0 or a stack of the same amount or more than there already are if (newstackcount<1 || newstackcount>=GetStackCount()) return NULL; ! newitem = Copy(newstackcount); if (newitem == NULL) return NULL; // Adjust stack count of source ! SetStackCount(stack_count-newstackcount); return newitem; } ! psItem *psItem::CombineStack(psItem *stackme) { - unsigned short maxmove; - // Ensure stacking compatability. if (!CheckStackableWith(stackme)) --- 1524,1545 ---- } ! psItem *psItem::SplitStack(unsigned short newstackcount, bool save) { // Cannot split into a stack of 0 or a stack of the same amount or more than there already are if (newstackcount<1 || newstackcount>=GetStackCount()) return NULL; ! psItem *newitem = Copy(newstackcount); if (newitem == NULL) return NULL; // Adjust stack count of source ! SetStackCount(stack_count-newstackcount, save); return newitem; } ! psItem *psItem::CombineStack(psItem *stackme, bool save) { // Ensure stacking compatability. if (!CheckStackableWith(stackme)) *************** *** 1554,1563 **** // We're working with an unsigned short so this is a bit funky. // We can't just add and check <65536 because it could roll over during the add ! maxmove=65535-stack_count; if (maxmove < stackme->GetStackCount()) { // Move a partial stack ! stackme->SetStackCount(stackme->GetStackCount()-maxmove); ! SetStackCount(stack_count+maxmove); // Didn't completely move the old stack --- 1550,1559 ---- // We're working with an unsigned short so this is a bit funky. // We can't just add and check <65536 because it could roll over during the add ! unsigned short maxmove = 65535 - stack_count; if (maxmove < stackme->GetStackCount()) { // Move a partial stack ! stackme->SetStackCount(stackme->GetStackCount()-maxmove, save); ! SetStackCount(stack_count+maxmove, save); // Didn't completely move the old stack *************** *** 1575,1580 **** } ! SetStackCount(stack_count+stackme->GetStackCount()); ! CacheManager::GetSingleton().RemoveInstance(stackme); // Stacks completely merged --- 1571,1580 ---- } ! SetStackCount(stack_count+stackme->GetStackCount(), save); ! ! if (save) ! CacheManager::GetSingleton().RemoveInstance(stackme); ! else ! delete stackme; // Don't remove from DB if not saving // Stacks completely merged Index: psitem.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/psitem.h,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** psitem.h 26 Feb 2006 08:38:19 -0000 1.96 --- psitem.h 2 Mar 2006 00:28:30 -0000 1.97 *************** *** 485,489 **** * on an owning player must be set first, and then Save() called to generate a UID and save to the database. */ ! psItem *SplitStack(unsigned short newstackcount); --- 485,489 ---- * on an owning player must be set first, and then Save() called to generate a UID and save to the database. */ ! psItem* SplitStack(unsigned short newstackcount, bool save=true); *************** *** 495,499 **** * WARNING: caller must regard the 'stackme' pointer as invalid and must not access it any more */ ! psItem * CombineStack(psItem * stackme); --- 495,499 ---- * WARNING: caller must regard the 'stackme' pointer as invalid and must not access it any more */ ! psItem* CombineStack(psItem* stackme, bool save=true); |