diff --git a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala index 02a83d1eb..461d42a02 100644 --- a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala +++ b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala @@ -392,7 +392,7 @@ object GamePacketOpcode extends Enumeration { // OPCODE 60 case GenericCollisionMsg => noDecoder(opcode) - case QuantityUpdateMessage => noDecoder(opcode) + case QuantityUpdateMessage => game.QuantityUpdateMessage.decode case ArmorChangedMessage => noDecoder(opcode) case ProjectileStateMessage => noDecoder(opcode) case MountVehicleCargoMsg => noDecoder(opcode) diff --git a/common/src/main/scala/net/psforever/packet/game/QuantityUpdateMessage.scala b/common/src/main/scala/net/psforever/packet/game/QuantityUpdateMessage.scala new file mode 100644 index 000000000..f3d647566 --- /dev/null +++ b/common/src/main/scala/net/psforever/packet/game/QuantityUpdateMessage.scala @@ -0,0 +1,29 @@ +// Copyright (c) 2016 PSForever.net to present +package net.psforever.packet.game + +import net.psforever.packet.{GamePacketOpcode, Marshallable, PacketHelpers, PlanetSideGamePacket} +import scodec.Codec +import scodec.codecs._ + +/** + * Instructs client to update the quantity of an item when sent server to client. + * + * See also [[QuantityDeltaUpdateMessage]] + * + * @param item_guid the item to update + * @param quantity the quantity to update the item to + */ +final case class QuantityUpdateMessage(item_guid : PlanetSideGUID, + quantity : Int) + extends PlanetSideGamePacket { + type Packet = QuantityUpdateMessage + def opcode = GamePacketOpcode.QuantityUpdateMessage + def encode = QuantityUpdateMessage.encode(this) +} + +object QuantityUpdateMessage extends Marshallable[QuantityUpdateMessage] { + implicit val codec : Codec[QuantityUpdateMessage] = ( + ("item_guid" | PlanetSideGUID.codec) :: + ("quantity" | int32L) + ).as[QuantityUpdateMessage] +} diff --git a/common/src/test/scala/GamePacketTest.scala b/common/src/test/scala/GamePacketTest.scala index b7292d00b..f813c789f 100644 --- a/common/src/test/scala/GamePacketTest.scala +++ b/common/src/test/scala/GamePacketTest.scala @@ -837,6 +837,27 @@ class GamePacketTest extends Specification { } } + "QuantityUpdateMessage" should { + val string = hex"3D 5300 7B000000" + + "decode" in { + PacketCoding.DecodePacket(string).require match { + case QuantityUpdateMessage(item_guid, quantity) => + item_guid mustEqual PlanetSideGUID(83) + quantity mustEqual 123 + case default => + ko + } + } + + "encode" in { + val msg = QuantityUpdateMessage(PlanetSideGUID(83), 123) + val pkt = PacketCoding.EncodePacket(msg).require.toByteVector + + pkt mustEqual string + } + } + "PingMsg" should { val packet = hex"1a 00000000 b0360000"