From 31d02e8bf186e601b2d7664df0eca5606efd8c09 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 31 Oct 2016 17:16:41 +0200 Subject: [PATCH] Move Networking code for ID_GAME_INVENTORY next to ID_GAME_EQUIPMENT --- apps/openmw-mp/Networking.cpp | 14 ++--- apps/openmw/mwmp/Networking.cpp | 100 ++++++++++++++++---------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index a569792c5..a76ef22d6 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -221,6 +221,13 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) break; } + case ID_GAME_INVENTORY: + { + DEBUG_PRINTF("ID_GAME_INVENTORY\n"); + myPacket->Read(player); + break; + } + case ID_GAME_ATTACK: { DEBUG_PRINTF("ID_GAME_ATTACK\n"); @@ -358,13 +365,6 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) break; } - case ID_GAME_INVENTORY: - { - DEBUG_PRINTF("ID_GAME_INVENTORY\n"); - myPacket->Read(player); - break; - } - default: LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 02a2b3ecd..5375c66cb 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -285,6 +285,56 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) } break; } + case ID_GAME_INVENTORY: + { + if (guid == myGuid) + { + if (packet->length == myPacket->headerSize()) + { + printf("ID_GAME_INVENTORY update only\n"); + getLocalPlayer()->updateInventory(true); + GetPlayerPacket(ID_GAME_INVENTORY)->Send(getLocalPlayer()); + } + else + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::ContainerStore &conStore = ptr.getClass().getContainerStore(ptr); + if (getLocalPlayer()->inventory.action == Inventory::ADDITEM) + { + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) + { + mwmp::Item item = getLocalPlayer()->inventory.items[i]; + MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); + if (item.health != -1) + itemPtr.getCellRef().setCharge(item.health); + } + } + else if (getLocalPlayer()->inventory.action == Inventory::REMOVEITEM) + { + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) + { + mwmp::Item item = getLocalPlayer()->inventory.items[i]; + conStore.remove(item.refid, item.count, ptr); + } + } + else // update + { + conStore.clear(); + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) + { + mwmp::Item item = getLocalPlayer()->inventory.items[i]; + MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); + if (item.health != -1) + itemPtr.getCellRef().setCharge(item.health); + printf("%s %d %d\n", item.refid.c_str(), item.count, item.health); + } + getLocalPlayer()->setInventory(); // restore equipped items + } + } + } + break; + } case ID_GAME_ATTACK: { if (pl != 0) @@ -607,56 +657,6 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) } } } - case ID_GAME_INVENTORY: - { - if (guid == myGuid) - { - if (packet->length == myPacket->headerSize()) - { - printf("ID_GAME_INVENTORY update only\n"); - getLocalPlayer()->updateInventory(true); - GetPlayerPacket(ID_GAME_INVENTORY)->Send(getLocalPlayer()); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore &conStore = ptr.getClass().getContainerStore(ptr); - if (getLocalPlayer()->inventory.action == Inventory::ADDITEM) - { - for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) - { - mwmp::Item item = getLocalPlayer()->inventory.items[i]; - MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); - if(item.health != -1) - itemPtr.getCellRef().setCharge(item.health); - } - } - else if (getLocalPlayer()->inventory.action == Inventory::REMOVEITEM) - { - for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) - { - mwmp::Item item = getLocalPlayer()->inventory.items[i]; - conStore.remove(item.refid, item.count, ptr); - } - } - else // update - { - conStore.clear(); - for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) - { - mwmp::Item item = getLocalPlayer()->inventory.items[i]; - MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); - if(item.health != -1) - itemPtr.getCellRef().setCharge(item.health); - printf("%s %d %d\n", item.refid.c_str(), item.count, item.health); - } - getLocalPlayer()->setInventory(); // restore equipped items - } - } - } - break; - } case ID_GAME_TIME: { if (guid == myGuid)