[Server] Make it possible to resend a received ObjectList of any kind

Additionally, make existing related functions less confusing.
0.6.3
David Cernat 7 years ago
parent 494edbe5cb
commit bacecc93e3

@ -24,16 +24,25 @@ void ObjectFunctions::ReadLastObjectList() noexcept
readObjectList = mwmp::Networking::getPtr()->getLastObjectList(); readObjectList = mwmp::Networking::getPtr()->getLastObjectList();
} }
void ObjectFunctions::InitializeObjectList(unsigned short pid) noexcept void ObjectFunctions::ClearObjectList() noexcept
{
writeObjectList.cell.blank();
writeObjectList.baseObjects.clear();
}
void ObjectFunctions::SetObjectListPid(unsigned short pid) noexcept
{ {
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
writeObjectList.cell.blank();
writeObjectList.baseObjects.clear();
writeObjectList.guid = player->guid; writeObjectList.guid = player->guid;
} }
void ObjectFunctions::CopyLastObjectListToStore() noexcept
{
writeObjectList = *readObjectList;
}
unsigned int ObjectFunctions::GetObjectChangesSize() noexcept unsigned int ObjectFunctions::GetObjectChangesSize() noexcept
{ {
return readObjectList->baseObjectCount; return readObjectList->baseObjectCount;
@ -315,9 +324,9 @@ void ObjectFunctions::SetContainerItemEnchantmentCharge(double enchantmentCharge
tempContainerItem.enchantmentCharge = enchantmentCharge; tempContainerItem.enchantmentCharge = enchantmentCharge;
} }
void ObjectFunctions::SetReceivedContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex, int actionCount) noexcept void ObjectFunctions::SetContainerItemActionCountByIndex(unsigned int objectIndex, unsigned int itemIndex, int actionCount) noexcept
{ {
readObjectList->baseObjects.at(objectIndex).containerItems.at(itemIndex).actionCount = actionCount; writeObjectList.baseObjects.at(objectIndex).containerItems.at(itemIndex).actionCount = actionCount;
} }
void ObjectFunctions::AddObject() noexcept void ObjectFunctions::AddObject() noexcept
@ -425,15 +434,10 @@ void ObjectFunctions::SendDoorDestination(bool broadcast) noexcept
packet->Send(true); packet->Send(true);
} }
void ObjectFunctions::SendContainer(bool broadcast, bool useLastReadObjectList) noexcept void ObjectFunctions::SendContainer(bool broadcast) noexcept
{ {
mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_CONTAINER); mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_CONTAINER);
packet->setObjectList(&writeObjectList);
if (useLastReadObjectList)
packet->setObjectList(readObjectList);
else
packet->setObjectList(&writeObjectList);
packet->Send(false); packet->Send(false);
if (broadcast) if (broadcast)
@ -457,6 +461,12 @@ void ObjectFunctions::ReadLastEvent() noexcept
ReadLastObjectList(); ReadLastObjectList();
} }
void ObjectFunctions::InitializeObjectList(unsigned short pid) noexcept
{
ClearObjectList();
SetObjectListPid(pid);
}
void ObjectFunctions::InitializeEvent(unsigned short pid) noexcept void ObjectFunctions::InitializeEvent(unsigned short pid) noexcept
{ {
InitializeObjectList(pid); InitializeObjectList(pid);

@ -3,7 +3,11 @@
#define OBJECTAPI \ #define OBJECTAPI \
{"ReadLastObjectList", ObjectFunctions::ReadLastObjectList},\ {"ReadLastObjectList", ObjectFunctions::ReadLastObjectList},\
{"InitializeObjectList", ObjectFunctions::InitializeObjectList},\ \
{"ClearObjectList", ObjectFunctions::ClearObjectList},\
{"SetObjectListPid", ObjectFunctions::SetObjectListPid},\
\
{"CopyLastObjectListToStore", ObjectFunctions::CopyLastObjectListToStore},\
\ \
{"GetObjectChangesSize", ObjectFunctions::GetObjectChangesSize},\ {"GetObjectChangesSize", ObjectFunctions::GetObjectChangesSize},\
{"GetObjectListAction", ObjectFunctions::GetObjectListAction},\ {"GetObjectListAction", ObjectFunctions::GetObjectListAction},\
@ -66,7 +70,7 @@
{"SetContainerItemCharge", ObjectFunctions::SetContainerItemCharge},\ {"SetContainerItemCharge", ObjectFunctions::SetContainerItemCharge},\
{"SetContainerItemEnchantmentCharge", ObjectFunctions::SetContainerItemEnchantmentCharge},\ {"SetContainerItemEnchantmentCharge", ObjectFunctions::SetContainerItemEnchantmentCharge},\
\ \
{"SetReceivedContainerItemActionCount", ObjectFunctions::SetReceivedContainerItemActionCount},\ {"SetContainerItemActionCountByIndex", ObjectFunctions::SetContainerItemActionCountByIndex},\
\ \
{"AddObject", ObjectFunctions::AddObject},\ {"AddObject", ObjectFunctions::AddObject},\
{"AddContainerItem", ObjectFunctions::AddContainerItem},\ {"AddContainerItem", ObjectFunctions::AddContainerItem},\
@ -84,6 +88,7 @@
{"SendConsoleCommand", ObjectFunctions::SendConsoleCommand},\ {"SendConsoleCommand", ObjectFunctions::SendConsoleCommand},\
\ \
{"ReadLastEvent", ObjectFunctions::ReadLastEvent},\ {"ReadLastEvent", ObjectFunctions::ReadLastEvent},\
{"InitializeObjectList", ObjectFunctions::InitializeObjectList},\
{"InitializeEvent", ObjectFunctions::InitializeEvent},\ {"InitializeEvent", ObjectFunctions::InitializeEvent},\
{"GetEventAction", ObjectFunctions::GetEventAction},\ {"GetEventAction", ObjectFunctions::GetEventAction},\
{"GetEventContainerSubAction", ObjectFunctions::GetEventContainerSubAction},\ {"GetEventContainerSubAction", ObjectFunctions::GetEventContainerSubAction},\
@ -106,12 +111,26 @@ public:
/** /**
* \brief Clear the data from the last object list sent by the server. * \brief Clear the data from the last object list sent by the server.
* *
* This is used to initialize the sending of new Object packets. * \return void
*/
static void ClearObjectList() noexcept;
/**
* \brief Set the pid attached to the ObjectList.
* *
* \param pid The player ID to whom the object list should be attached. * \param pid The player ID to whom the object list should be attached.
* \return void * \return void
*/ */
static void InitializeObjectList(unsigned short pid) noexcept; static void SetObjectListPid(unsigned short pid) noexcept;
/**
* \brief Take the contents of the read-only object list last received by the
* server from a player and move its contents to the stored object list
* that can be sent by the server.
*
* \return void
*/
static void CopyLastObjectListToStore() noexcept;
/** /**
* \brief Get the number of indexes in the read object list's object changes. * \brief Get the number of indexes in the read object list's object changes.
@ -612,7 +631,7 @@ public:
/** /**
* \brief Set the action count of the container item at a certain itemIndex in the container * \brief Set the action count of the container item at a certain itemIndex in the container
* changes of the object at a certain objectIndex in the read object list's object changes. * changes of the object at a certain objectIndex in the object list stored on the server.
* *
* When resending a received Container packet, this allows you to correct the amount of items * When resending a received Container packet, this allows you to correct the amount of items
* removed from a container by a player when it conflicts with what other players have already * removed from a container by a player when it conflicts with what other players have already
@ -623,7 +642,7 @@ public:
* \param actionCount The action count. * \param actionCount The action count.
* \return void * \return void
*/ */
static void SetReceivedContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex, int actionCount) noexcept; static void SetContainerItemActionCountByIndex(unsigned int objectIndex, unsigned int itemIndex, int actionCount) noexcept;
/** /**
* \brief Add a copy of the server's temporary object to the server's temporary object list. * \brief Add a copy of the server's temporary object to the server's temporary object list.
@ -744,7 +763,7 @@ public:
* *
* \return void * \return void
*/ */
static void SendContainer(bool broadcast = false, bool useLastReadObjectList = false) noexcept; static void SendContainer(bool broadcast = false) noexcept;
/** /**
* \brief Send a ConsoleCommand packet. * \brief Send a ConsoleCommand packet.
@ -760,6 +779,7 @@ public:
// All methods below are deprecated versions of methods from above // All methods below are deprecated versions of methods from above
static void ReadLastEvent() noexcept; static void ReadLastEvent() noexcept;
static void InitializeObjectList(unsigned short pid) noexcept;
static void InitializeEvent(unsigned short pid) noexcept; static void InitializeEvent(unsigned short pid) noexcept;
static unsigned char GetEventAction() noexcept; static unsigned char GetEventAction() noexcept;
static unsigned char GetEventContainerSubAction() noexcept; static unsigned char GetEventContainerSubAction() noexcept;

Loading…
Cancel
Save