Update of /cvsroot/planeshift/planeshift/src/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11634/server Modified Files: gem.cpp gem.h psserverchar.cpp slotmanager.cpp spawnmanager.cpp workmanager.cpp workmanager.h Log Message: Complete revamp of how containers update clients with their contents. Now the gemContainer multicasts all updates whenever any item is added or removed. The ownership of the item is sent along with the update message, so each client can determine how to display the item. This change to the message requires a net version ding, which I wanted to be sure to get in there before the client was released. Index: gem.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/gem.cpp,v retrieving revision 1.459 retrieving revision 1.460 diff -C2 -d -r1.459 -r1.460 *** gem.cpp 7 Jul 2007 20:18:03 -0000 1.459 --- gem.cpp 7 Jul 2007 23:37:47 -0000 1.460 *************** *** 3826,3835 **** unsigned short savedCount = item->GetStackCount(); item->SetStackCount(amountToAdd); ! bool result = AddToContainer(item, slot, true); item->SetStackCount(savedCount); return result; } ! bool gemContainer::AddToContainer(psItem *item, int slot, bool test) { // Slot changing and item creation in craft is done at the very end of event. --- 3826,3835 ---- unsigned short savedCount = item->GetStackCount(); item->SetStackCount(amountToAdd); ! bool result = AddToContainer(item, NULL, slot, true); item->SetStackCount(savedCount); return result; } ! bool gemContainer::AddToContainer(psItem *item, Client *fromClient, int slot, bool test) { // Slot changing and item creation in craft is done at the very end of event. *************** *** 3857,3863 **** // If the destination slot is occupied, try and look for an empty slot. if (FindItemInSlot(slot)) ! return AddToContainer(item, PSCHARACTER_SLOT_NONE, test); ! if (test) return true; // If the gemContainer we are dropping the item into is not pickupable then we --- 3857,3864 ---- // If the destination slot is occupied, try and look for an empty slot. if (FindItemInSlot(slot)) ! return AddToContainer(item, fromClient, PSCHARACTER_SLOT_NONE, test); ! if (test) ! return true; // If the gemContainer we are dropping the item into is not pickupable then we *************** *** 3870,3879 **** item->Save(false); itemlist.PushSmart(item); return true; } ! bool gemContainer::RemoveFromContainer(psItem *item) { ! return itemlist.Delete(item); } --- 3871,3919 ---- item->Save(false); itemlist.PushSmart(item); + + if (fromClient) + { + // Update client(s) + psViewItemUpdate mesg(fromClient->GetClientNum(), + GetEntity()->GetID(), + slot, + false, + item->GetName(), + item->GetImageName(), + item->GetStackCount(), + item->GetGuardingCharacterID()); + + mesg.Multicast(fromClient->GetActor()->GetMulticastClients(),0,5); + } return true; } ! bool gemContainer::RemoveFromContainer(psItem *item,Client *fromClient) { ! printf("Removing %s from container now.\n", item->GetName() ); ! if (itemlist.Delete(item)) ! { ! uint32_t slot = item->GetLocInParent(); ! uint32_t count = item->GetStackCount(); ! ! if (fromClient) ! { ! printf("Multicasting removal update to nearby clients of %s.\n\n", fromClient->GetName() ); ! // Update client(s) ! psViewItemUpdate mesg(fromClient->GetClientNum(), ! GetEntity()->GetID(), ! slot, ! true, ! item->GetName(), ! item->GetImageName(), ! item->GetStackCount(), ! 0); ! ! mesg.Multicast(fromClient->GetActor()->GetMulticastClients(),0,5); ! } ! return true; ! } ! else ! return false; } *************** *** 3924,3933 **** } ! psItem *gemContainer::psContainerIterator::RemoveCurrent() { if (current < container->CountItems() ) { psItem *item = container->GetIndexItem(current); ! container->RemoveFromContainer(item); current--; // This adjusts so that the next "Next()" call actually returns the next item and doesn't skip one. return item; --- 3964,3973 ---- } ! psItem *gemContainer::psContainerIterator::RemoveCurrent(Client *fromClient) { if (current < container->CountItems() ) { psItem *item = container->GetIndexItem(current); ! container->RemoveFromContainer(item,fromClient); current--; // This adjusts so that the next "Next()" call actually returns the next item and doesn't skip one. return item; Index: gem.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/gem.h,v retrieving revision 1.200 retrieving revision 1.201 diff -C2 -d -r1.200 -r1.201 *** gem.h 20 Jun 2007 09:20:54 -0000 1.200 --- gem.h 7 Jul 2007 23:37:47 -0000 1.201 *************** *** 376,380 **** protected: csArray<psItem*> itemlist; ! bool AddToContainer(psItem *item, int slot, bool test); public: --- 376,380 ---- protected: csArray<psItem*> itemlist; ! bool AddToContainer(psItem *item, Client *fromClient,int slot, bool test); public: *************** *** 389,394 **** bool CanAdd(unsigned short amountToAdd, psItem *item, int slot=-1); ! bool AddToContainer(psItem *item, int slot=-1) { return AddToContainer(item, slot, false); } ! bool RemoveFromContainer(psItem *item); psItem *FindItemInSlot(int slot); int SlotCount() const { return PSITEM_MAX_CONTAINER_SLOTS; } --- 389,394 ---- bool CanAdd(unsigned short amountToAdd, psItem *item, int slot=-1); ! bool AddToContainer(psItem *item,Client *fromClient, int slot=-1) { return AddToContainer(item, fromClient, slot, false); } ! bool RemoveFromContainer(psItem *item,Client *fromClient); psItem *FindItemInSlot(int slot); int SlotCount() const { return PSITEM_MAX_CONTAINER_SLOTS; } *************** *** 408,412 **** bool HasNext(); psItem *Next(); ! psItem *RemoveCurrent(); void UseContainerItem(gemContainer *containerItem); }; --- 408,412 ---- bool HasNext(); psItem *Next(); ! psItem *RemoveCurrent(Client *fromClient); void UseContainerItem(gemContainer *containerItem); }; Index: psserverchar.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/psserverchar.cpp,v retrieving revision 1.531 retrieving revision 1.532 diff -C2 -d -r1.531 -r1.532 *** psserverchar.cpp 23 Jun 2007 18:08:49 -0000 1.531 --- psserverchar.cpp 7 Jul 2007 23:37:47 -0000 1.532 *************** *** 1537,1541 **** outgoing.ConstructMsg(); ! psserver->GetEventManager()->SendMessage(outgoing.msg); return true; --- 1537,1541 ---- outgoing.ConstructMsg(); ! outgoing.SendMessage(); return true; *************** *** 1566,1570 **** bool isContainer = item->GetIsContainer(); ! psViewItemDescription outgoing( client->GetClientNum(), name, --- 1566,1570 ---- bool isContainer = item->GetIsContainer(); ! psViewItemDescription outgoing( client->GetClientNum(), name, *************** *** 1598,1605 **** gemContainer *container = dynamic_cast<gemContainer*> (item->GetGemObject()); - // This is not a container in the world so it must be a container inside the pserson's - // inventory. So check to see which items the player has that are in the container. if (!container) { int slot = 0; for (size_t i=0; i < client->GetCharacterData()->Inventory().GetInventoryIndexCount(); i++) --- 1598,1605 ---- gemContainer *container = dynamic_cast<gemContainer*> (item->GetGemObject()); if (!container) { + // This is not a container in the world so it must be a container inside the pserson's + // inventory. So check to see which items the player has that are in the container. int slot = 0; for (size_t i=0; i < client->GetCharacterData()->Inventory().GetInventoryIndexCount(); i++) Index: slotmanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/slotmanager.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** slotmanager.cpp 7 Jul 2007 09:35:07 -0000 1.9 --- slotmanager.cpp 7 Jul 2007 23:37:47 -0000 1.10 *************** *** 197,202 **** if (worldContainer->CanAdd(itemProposed->GetStackCount(), itemProposed, msg.toSlot)) { ! worldContainer->RemoveFromContainer(itemProposed); ! worldContainer->AddToContainer(itemProposed, msg.toSlot); } --- 197,202 ---- if (worldContainer->CanAdd(itemProposed->GetStackCount(), itemProposed, msg.toSlot)) { ! worldContainer->RemoveFromContainer(itemProposed,fromClient); ! worldContainer->AddToContainer(itemProposed, fromClient, msg.toSlot); } *************** *** 204,209 **** psserver->GetWorkManager()->StartAutoWork(fromClient, worldContainer, itemProposed, msg.stackCount); ! // Update client ! psserver->GetCharManager()->SendContainerContents(fromClient, parentItem, containerEntityID); break; --- 204,209 ---- psserver->GetWorkManager()->StartAutoWork(fromClient, worldContainer, itemProposed, msg.stackCount); ! ! // psserver->GetCharManager()->SendContainerContents(fromClient, parentItem, containerEntityID); break; *************** *** 211,215 **** case CONTAINER_WORLD: { ! worldContainer->RemoveFromContainer(itemProposed); chr->DropItem(itemProposed, msg.posWorld); break; --- 211,215 ---- case CONTAINER_WORLD: { ! worldContainer->RemoveFromContainer(itemProposed,fromClient); chr->DropItem(itemProposed, msg.posWorld); break; *************** *** 227,233 **** { // Now that it was successful, take it out of the world container ! worldContainer->RemoveFromContainer(itemProposed); chr->Inventory().Add(itemProposed, false); - psserver->GetCharManager()->SendContainerContents(fromClient, parentItem, containerEntityID); return; } --- 227,232 ---- { // Now that it was successful, take it out of the world container ! worldContainer->RemoveFromContainer(itemProposed,fromClient); chr->Inventory().Add(itemProposed, false); return; } *************** *** 235,239 **** if (itemProposed) itemProposed->Save(false); ! psserver->GetCharManager()->SendContainerContents(fromClient, parentItem, containerEntityID); break; } --- 234,250 ---- if (itemProposed) itemProposed->Save(false); ! ! // Update client(s) ! psViewItemUpdate mesg(fromClient->GetClientNum(), ! worldContainer->GetEntity()->GetID(), ! msg.fromSlot, ! true, ! itemProposed->GetName(), ! itemProposed->GetImageName(), ! itemProposed->GetStackCount(), ! 0); ! ! mesg.Multicast(fromClient->GetActor()->GetMulticastClients(),0,5); ! // psserver->GetCharManager()->SendContainerContents(fromClient, parentItem, containerEntityID); break; } *************** *** 367,372 **** { psItem *newItem = chr->Inventory().RemoveItem(NULL, (INVENTORY_SLOT_NUMBER) srcSlot, msg.stackCount); ! worldContainer->AddToContainer(newItem, msg.toSlot); ! psserver->GetWorkManager()->StartAutoWork(fromClient, worldContainer, newItem, msg.stackCount); } --- 378,382 ---- { psItem *newItem = chr->Inventory().RemoveItem(NULL, (INVENTORY_SLOT_NUMBER) srcSlot, msg.stackCount); ! worldContainer->AddToContainer(newItem, fromClient, msg.toSlot); psserver->GetWorkManager()->StartAutoWork(fromClient, worldContainer, newItem, msg.stackCount); } Index: spawnmanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/spawnmanager.cpp,v retrieving revision 1.197 retrieving revision 1.198 diff -C2 -d -r1.197 -r1.198 *** spawnmanager.cpp 12 Jun 2007 23:54:49 -0000 1.197 --- spawnmanager.cpp 7 Jul 2007 23:37:47 -0000 1.198 *************** *** 565,569 **** if (container) { ! container->AddToContainer(item,item->GetLocInParent()); } else --- 565,569 ---- if (container) { ! container->AddToContainer(item,NULL,item->GetLocInParent()); } else Index: workmanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/workmanager.cpp,v retrieving revision 1.252 retrieving revision 1.253 diff -C2 -d -r1.252 -r1.253 *** workmanager.cpp 23 Jun 2007 18:11:39 -0000 1.252 --- workmanager.cpp 7 Jul 2007 23:37:47 -0000 1.253 *************** *** 2246,2251 **** // Remove items and delete ! it.RemoveCurrent(); ! SendClearUpdate( item->GetLocInParent(), containerID ); if (!item->Destroy()) { --- 2246,2251 ---- // Remove items and delete ! it.RemoveCurrent(owner->GetActor()->GetClient() ); ! // SendClearUpdate( item->GetLocInParent(), containerID ); if (!item->Destroy()) { *************** *** 2298,2303 **** unsigned int containerID = workItem->GetGemObject()->GetEntity()->GetID(); unsigned int transformSlot = oldItem->GetLocInParent(); ! SendClearUpdate( transformSlot, containerID ); ! container->RemoveFromContainer(oldItem); if (!oldItem->Destroy()) { --- 2298,2303 ---- unsigned int containerID = workItem->GetGemObject()->GetEntity()->GetID(); unsigned int transformSlot = oldItem->GetLocInParent(); ! // SendClearUpdate( transformSlot, containerID ); ! container->RemoveFromContainer(oldItem,owner->GetActor()->GetClient() ); if (!oldItem->Destroy()) { *************** *** 2321,2325 **** // Send update to client and save // container->AddToContainer(newItem, newItem->GetLocInParent()); ! SendItemUpdate( newItem->GetLocInParent(), newItem ); workItem->Save(true); --- 2321,2325 ---- // Send update to client and save // container->AddToContainer(newItem, newItem->GetLocInParent()); ! //SendItemUpdate( newItem->GetLocInParent(), newItem ); workItem->Save(true); *************** *** 2461,2465 **** return NULL; } ! container->AddToContainer(newItem,slot); parent->Save(true); } --- 2461,2465 ---- return NULL; } ! container->AddToContainer(newItem,owner->GetActor()->GetClient(), slot); parent->Save(true); } *************** *** 2514,2517 **** --- 2514,2519 ---- } + #if 0 //These two functions are built into Container add/remove functions now. KWF + bool psWorkManager::SendItemUpdate(INVENTORY_SLOT_NUMBER slotID, psItem *newItem ) { *************** *** 2561,2564 **** --- 2563,2567 ---- return true; } + #endif Index: workmanager.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/workmanager.h,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** workmanager.h 23 May 2007 01:42:24 -0000 1.79 --- workmanager.h 7 Jul 2007 23:37:47 -0000 1.80 *************** *** 249,253 **** * @return False if there is a problem sending message. */ ! bool SendClearUpdate( unsigned int slotID, unsigned int containerID ); protected: --- 249,253 ---- * @return False if there is a problem sending message. */ ! // bool SendClearUpdate( unsigned int slotID, unsigned int containerID ); protected: *************** *** 370,374 **** psItem* TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality); // bool TransformHandItem(uint32 newId, int newQty, float itemQuality); ! bool SendItemUpdate( INVENTORY_SLOT_NUMBER slotID, psItem *newItem ); void StartTransformationEvent(int transType, INVENTORY_SLOT_NUMBER transSlot, int resultQty, --- 370,374 ---- psItem* TransformSlotItem(INVENTORY_SLOT_NUMBER slot, uint32 newId, int newQty, float itemQuality); // bool TransformHandItem(uint32 newId, int newQty, float itemQuality); ! //bool SendItemUpdate( INVENTORY_SLOT_NUMBER slotID, psItem *newItem ); void StartTransformationEvent(int transType, INVENTORY_SLOT_NUMBER transSlot, int resultQty, |