Merge pull request #110 from Fate-JH/transaction-result

Packet: ItemTransactionResultMessage (caution)
This commit is contained in:
Fate-JH 2017-03-05 18:45:59 -05:00 committed by GitHub
commit ff66a6aab3
4 changed files with 83 additions and 2 deletions

View file

@ -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

View file

@ -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]
}

View file

@ -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
}
}
}

View file

@ -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)
@ -370,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) =>