From c8c23314d608c8a7e5d0391a0437c25372906b8c Mon Sep 17 00:00:00 2001 From: FateJH Date: Sun, 5 Mar 2017 16:29:21 -0500 Subject: [PATCH 1/2] importing ItemTransactionResultMessage and tests from alt repo --- .../psforever/packet/GamePacketOpcode.scala | 2 +- .../game/ItemTransactionResultMessage.scala | 35 +++++++++++++++ .../ItemTransactionResultMessageTest.scala | 45 +++++++++++++++++++ .../src/main/scala/WorldSessionActor.scala | 1 + 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 common/src/main/scala/net/psforever/packet/game/ItemTransactionResultMessage.scala create mode 100644 common/src/test/scala/game/ItemTransactionResultMessageTest.scala diff --git a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala index 6a4845579..304e18a2e 100644 --- a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala +++ b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala @@ -400,7 +400,7 @@ object GamePacketOpcode extends Enumeration { case 0x42 => noDecoder(CargoMountPointStatusMessage) case 0x43 => noDecoder(BeginZoningMessage) case 0x44 => game.ItemTransactionMessage.decode - case 0x45 => noDecoder(ItemTransactionResultMessage) + case 0x45 => game.ItemTransactionResultMessage.decode case 0x46 => game.ChangeFireModeMessage.decode case 0x47 => game.ChangeAmmoMessage.decode // 0x48 diff --git a/common/src/main/scala/net/psforever/packet/game/ItemTransactionResultMessage.scala b/common/src/main/scala/net/psforever/packet/game/ItemTransactionResultMessage.scala new file mode 100644 index 000000000..252ea5603 --- /dev/null +++ b/common/src/main/scala/net/psforever/packet/game/ItemTransactionResultMessage.scala @@ -0,0 +1,35 @@ +// Copyright (c) 2016 PSForever.net to present +package net.psforever.packet.game + +import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket} +import net.psforever.types.TransactionType +import scodec.Codec +import scodec.codecs._ + +/** + * Dispatch to the client in response to an `ItemRequestMessage`, roughly after the request has been fulfilled. + * This TCP-like "after" behavior is typically supported by pushing this packet at the end of the `MultiPacket` that fulfills the request. + * @param terminal_guid the terminal used + * @param transaction_type the type of transaction + * @param success whether the transaction was a success + * @param error an error code, if applicable; + * no error by default + */ +final case class ItemTransactionResultMessage(terminal_guid : PlanetSideGUID, + transaction_type : TransactionType.Value, + success : Boolean, + error : Int = 0) + extends PlanetSideGamePacket { + type Packet = ItemTransactionResultMessage + def opcode = GamePacketOpcode.ItemTransactionResultMessage + def encode = ItemTransactionResultMessage.encode(this) +} + +object ItemTransactionResultMessage extends Marshallable[ItemTransactionResultMessage] { + implicit val codec : Codec[ItemTransactionResultMessage] = ( + ("terminal_guid" | PlanetSideGUID.codec) :: + ("transaction_type" | TransactionType.codec) :: + ("success" | bool) :: + ("error" | uint8L) + ).as[ItemTransactionResultMessage] +} diff --git a/common/src/test/scala/game/ItemTransactionResultMessageTest.scala b/common/src/test/scala/game/ItemTransactionResultMessageTest.scala new file mode 100644 index 000000000..558558bf5 --- /dev/null +++ b/common/src/test/scala/game/ItemTransactionResultMessageTest.scala @@ -0,0 +1,45 @@ +// Copyright (c) 2016 PSForever.net to present +package game + +import org.specs2.mutable._ +import net.psforever.packet._ +import net.psforever.packet.game._ +import net.psforever.types.TransactionType +import scodec.bits._ + +class ItemTransactionResultMessageTest extends Specification { + //these are paried packets come from the same capture + val string_request = hex"44 DD 03 40 00 11 40 73 75 70 70 72 65 73 73 6F 72 00 00 00" + val string_result = hex"45 DD 03 50 00" + "decode" in { + PacketCoding.DecodePacket(string_result).require match { + case ItemTransactionResultMessage(terminal_guid, transaction_type, is_success, error_code) => + terminal_guid mustEqual PlanetSideGUID(989) + transaction_type mustEqual TransactionType.Buy + is_success mustEqual true + error_code mustEqual 0 + case default => + ko + } + } + + "encode" in { + val msg = ItemTransactionResultMessage(PlanetSideGUID(989), TransactionType.Buy, true, 0) + val pkt = PacketCoding.EncodePacket(msg).require.toByteVector + + pkt mustEqual string_result + } + + "proper reply" in { + try { + val request = PacketCoding.DecodePacket(string_request).require.asInstanceOf[ItemTransactionMessage] + val result = PacketCoding.DecodePacket(string_result).require.asInstanceOf[ItemTransactionResultMessage] + request.terminal_guid mustEqual result.terminal_guid + request.transaction_type mustEqual result.transaction_type + } + catch { + case e : Exception => + ko + } + } +} diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index f32a9fa9d..0ca64ba3e 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -339,6 +339,7 @@ class WorldSessionActor extends Actor with MDCContextAware { case msg @ ItemTransactionMessage(terminal_guid, transaction_type, item_page, item_name, unk1, item_guid) => if(transaction_type == TransactionType.Sell) { sendResponse(PacketCoding.CreateGamePacket(0, ObjectDeleteMessage(item_guid, 0))) + sendResponse(PacketCoding.CreateGamePacket(0, ItemTransactionResultMessage(terminal_guid, transaction_type, true))) } log.info("ItemTransaction: " + msg) From eb27290617d2722c8b6492d42ba4e921aee19f1c Mon Sep 17 00:00:00 2001 From: FateJH Date: Sun, 5 Mar 2017 16:54:18 -0500 Subject: [PATCH 2/2] correction to WorldSessionActor case --- pslogin/src/main/scala/WorldSessionActor.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index 0ca64ba3e..1d6c09e0d 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -371,7 +371,7 @@ class WorldSessionActor extends Actor with MDCContextAware { case msg @ SquadDefinitionActionMessage(a, b, c, d, e, f, g, h, i) => log.info("SquadDefinitionAction: " + msg) - case msg @ GenericCollisionMsg(u1, p, t, php, thp, pvx, pvy, pvz, tvx, tvy, tvz, ppos, tpos, u2, u3, u4) => + case msg @ GenericCollisionMsg(u1, p, t, php, thp, pv, tv, ppos, tpos, u2, u3, u4) => log.info("Ouch! " + msg) case msg @ BugReportMessage(version_major,version_minor,version_date,bug_type,repeatable,location,zone,pos,summary,desc) =>