PSF-BotServer/src/test/scala/game/ItemTransactionMessageTest.scala

78 lines
2.6 KiB
Scala
Raw Normal View History

2017-03-06 19:30:45 -05:00
// Copyright (c) 2017 PSForever
package game
import org.specs2.mutable._
import net.psforever.packet._
import net.psforever.packet.game._
import net.psforever.types.{PlanetSideGUID, TransactionType}
import scodec.bits._
class ItemTransactionMessageTest extends Specification {
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
val string_buy = hex"44 4C03 4000110070756E6973686572000000"
val string_sell = hex"44 5303 60001000004E00"
val string_forget = hex"44 BA00 600011006861726173736572000000"
"decode (buy)" in {
PacketCoding.DecodePacket(string_buy).require match {
case ItemTransactionMessage(terminal_guid, transaction_type, item_page, item_name, unk1, item_guid) =>
terminal_guid mustEqual PlanetSideGUID(844)
transaction_type mustEqual TransactionType.Buy
item_page mustEqual 0
item_name mustEqual "punisher"
unk1 mustEqual 0
item_guid mustEqual PlanetSideGUID(0)
case _ =>
ko
}
}
"decode (sell)" in {
PacketCoding.DecodePacket(string_sell).require match {
case ItemTransactionMessage(terminal_guid, transaction_type, item_page, item_name, unk1, item_guid) =>
terminal_guid mustEqual PlanetSideGUID(851)
transaction_type mustEqual TransactionType.Sell
item_page mustEqual 0
item_name mustEqual ""
unk1 mustEqual 0
item_guid mustEqual PlanetSideGUID(78)
case _ =>
ko
}
}
"decode (forget)" in {
PacketCoding.DecodePacket(string_forget).require match {
case ItemTransactionMessage(terminal_guid, transaction_type, item_page, item_name, unk1, item_guid) =>
terminal_guid mustEqual PlanetSideGUID(186)
transaction_type mustEqual TransactionType.Sell
item_page mustEqual 0
item_name mustEqual "harasser"
unk1 mustEqual 0
item_guid mustEqual PlanetSideGUID(0)
case _ =>
ko
}
}
"encode (buy)" in {
val msg_buy = ItemTransactionMessage(PlanetSideGUID(844), TransactionType.Buy, 0, "punisher", 0, PlanetSideGUID(0))
val pkt_buy = PacketCoding.EncodePacket(msg_buy).require.toByteVector
pkt_buy mustEqual string_buy
}
"encode (sell)" in {
val msg_sell = ItemTransactionMessage(PlanetSideGUID(851), TransactionType.Sell, 0, "", 0, PlanetSideGUID(78))
val pkt_sell = PacketCoding.EncodePacket(msg_sell).require.toByteVector
pkt_sell mustEqual string_sell
}
"encode (forget)" in {
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
val msg_forget =
ItemTransactionMessage(PlanetSideGUID(186), TransactionType.Sell, 0, "harasser", 0, PlanetSideGUID(0))
val pkt_forget = PacketCoding.EncodePacket(msg_forget).require.toByteVector
pkt_forget mustEqual string_forget
}
}