mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-03-05 13:10:20 +00:00
commit
885387b734
22 changed files with 1095 additions and 348 deletions
68
common/src/test/scala/game/DamageFeedbackMessageTest.scala
Normal file
68
common/src/test/scala/game/DamageFeedbackMessageTest.scala
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package game
|
||||
|
||||
import org.specs2.mutable._
|
||||
import net.psforever.packet._
|
||||
import net.psforever.packet.game._
|
||||
import scodec.bits._
|
||||
|
||||
class DamageFeedbackMessageTest extends Specification {
|
||||
val string = hex"7b 3d842f610b2040000000"
|
||||
|
||||
"decode" in {
|
||||
PacketCoding.DecodePacket(string).require match {
|
||||
case DamageFeedbackMessage(unk1, unk2, unk2a, unk2b, unk2c, unk3, unk3a, unk3b, unk3c, unk3d, unk4, unk5, unk6) =>
|
||||
unk1 mustEqual 3
|
||||
unk2 mustEqual true
|
||||
unk2a.contains(PlanetSideGUID(2913)) mustEqual true
|
||||
unk2b.isEmpty mustEqual true
|
||||
unk2c.isEmpty mustEqual true
|
||||
unk3 mustEqual true
|
||||
unk3a.contains(PlanetSideGUID(2913)) mustEqual true
|
||||
unk3b.isEmpty mustEqual true
|
||||
unk3c.isEmpty mustEqual true
|
||||
unk3d.isEmpty mustEqual true
|
||||
unk4 mustEqual 1
|
||||
unk5 mustEqual 2
|
||||
unk6 mustEqual 0
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"encode" in {
|
||||
val msg = DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0)
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
|
||||
pkt mustEqual string
|
||||
}
|
||||
|
||||
"assert catches" in {
|
||||
//unk2: no parameters
|
||||
DamageFeedbackMessage(3, true, None, None, None, true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
//unk2: two exclusive parameters
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), Some("error"), None, true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, Some(5), true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, true, None, Some("error"), Some(5), true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
//unk2: all parameters
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), Some("error"), Some(5), true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
//unk2: mismatched flag for strings
|
||||
DamageFeedbackMessage(3, true, None, None, Some(5), true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, false, None, Some("error"), None, true, Some(PlanetSideGUID(2913)), None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
|
||||
//unk3: no parameters
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, None, None, None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
//unk3: two exclusive parameters
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, Some(PlanetSideGUID(2913)), Some("error"), None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, Some(PlanetSideGUID(2913)), None, Some(5), None, 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, None, Some("error"), Some(5), Some(1), 1, 2, 0) must throwA[AssertionError]
|
||||
//unk3: all parameters
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, Some(PlanetSideGUID(2913)), Some("error"), Some(5), None, 1, 2, 0) must throwA[AssertionError]
|
||||
//unk3: mismatched fields
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, Some(PlanetSideGUID(2913)), None, None, Some(5), 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, None, Some("Error"), None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
//unk3: mismatched flag for strings
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, true, None, None, Some(5), None, 1, 2, 0) must throwA[AssertionError]
|
||||
DamageFeedbackMessage(3, true, Some(PlanetSideGUID(2913)), None, None, false, None, Some("error"), None, None, 1, 2, 0) must throwA[AssertionError]
|
||||
}
|
||||
}
|
||||
30
common/src/test/scala/game/DamageMessageTest.scala
Normal file
30
common/src/test/scala/game/DamageMessageTest.scala
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2019 PSForever
|
||||
package game
|
||||
|
||||
import org.specs2.mutable._
|
||||
import net.psforever.packet._
|
||||
import net.psforever.packet.game._
|
||||
import scodec.bits._
|
||||
|
||||
class DamageMessageTest extends Specification {
|
||||
val string = hex"0b610b02610b00"
|
||||
|
||||
"decode" in {
|
||||
PacketCoding.DecodePacket(string).require match {
|
||||
case DamageMessage(guid1, unk1, guid2, unk2) =>
|
||||
guid1 mustEqual PlanetSideGUID(2913)
|
||||
unk1 mustEqual 2
|
||||
guid2 mustEqual PlanetSideGUID(2913)
|
||||
unk2 mustEqual false
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"encode" in {
|
||||
val msg = DamageMessage(PlanetSideGUID(2913), 2, PlanetSideGUID(2913), false)
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
|
||||
pkt mustEqual string
|
||||
}
|
||||
}
|
||||
|
|
@ -8,23 +8,18 @@ import net.psforever.types.Vector3
|
|||
import scodec.bits._
|
||||
|
||||
class ProjectileStateMessageTest extends Specification {
|
||||
val string = hex"3f 259d c5019 30e4a 9514 c52c9541 d9ba05c2 c5973941 00 f8 ec 020000"
|
||||
val string = hex"3f 259d c5019 30e4a 9514 c52c9541 d9ba05c2 c5973941 00 f8 ec 02000000"
|
||||
|
||||
"decode" in {
|
||||
PacketCoding.DecodePacket(string).require match {
|
||||
case ProjectileStateMessage(projectile, pos, vel, unk1, unk2, unk3, unk4, time_alive) =>
|
||||
case ProjectileStateMessage(projectile, pos, vel, orient, sequence, explode, unk) =>
|
||||
projectile mustEqual PlanetSideGUID(40229)
|
||||
pos.x mustEqual 4611.539f
|
||||
pos.y mustEqual 5576.375f
|
||||
pos.z mustEqual 82.328125f
|
||||
vel.x mustEqual 18.64686f
|
||||
vel.y mustEqual -33.43247f
|
||||
vel.z mustEqual 11.599553f
|
||||
unk1 mustEqual 0
|
||||
unk2 mustEqual 248
|
||||
unk3 mustEqual 236
|
||||
unk4 mustEqual false
|
||||
time_alive mustEqual 4
|
||||
pos mustEqual Vector3(4611.539f, 5576.375f, 82.328125f)
|
||||
vel mustEqual Vector3(18.64686f, -33.43247f, 11.599553f)
|
||||
orient mustEqual Vector3(0, 22.5f, 146.25f)
|
||||
sequence mustEqual 2
|
||||
explode mustEqual false
|
||||
unk mustEqual PlanetSideGUID(0)
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
|
|
@ -35,10 +30,18 @@ class ProjectileStateMessageTest extends Specification {
|
|||
PlanetSideGUID(40229),
|
||||
Vector3(4611.539f, 5576.375f, 82.328125f),
|
||||
Vector3(18.64686f, -33.43247f, 11.599553f),
|
||||
0, 248, 236, false, 4
|
||||
Vector3(0, 22.5f, 146.25f),
|
||||
2,
|
||||
false,
|
||||
PlanetSideGUID(0)
|
||||
)
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
|
||||
pkt mustEqual string
|
||||
//pkt mustEqual string
|
||||
val pkt_bits = pkt.toBitVector
|
||||
val str_bits = string.toBitVector
|
||||
pkt_bits.take(184) mustEqual str_bits.take(184) //skip 1 bit
|
||||
pkt_bits.drop(185).take(7) mustEqual str_bits.drop(185).take(7) //skip 1 bit
|
||||
pkt_bits.drop(193) mustEqual str_bits.drop(193)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,118 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package game.objectcreate
|
||||
|
||||
import net.psforever.packet.PacketCoding
|
||||
import net.psforever.packet.game.{ObjectCreateMessage, PlanetSideGUID}
|
||||
import net.psforever.packet.game.objectcreate._
|
||||
import net.psforever.types.{PlanetSideEmpire, Vector3}
|
||||
import org.specs2.mutable._
|
||||
import scodec.bits._
|
||||
|
||||
class RemoteProjectileDataTest extends Specification {
|
||||
val string_striker_projectile = hex"17 C5000000 A4B 009D 4C129 0CB0A 9814 00 F5 E3 040000666686400"
|
||||
val string_hunter_seeker_missile_projectile = hex"17 c5000000 ca9 ab9e af127 ec465 3723 00 15 c4 2400009a99c9400"
|
||||
|
||||
"RemoteProjectileData" should {
|
||||
"decode (striker_missile_targeting_projectile)" in {
|
||||
PacketCoding.DecodePacket(string_striker_projectile).require match {
|
||||
case ObjectCreateMessage(len, cls, guid, parent, data) =>
|
||||
len mustEqual 197
|
||||
cls mustEqual ObjectClass.striker_missile_targeting_projectile
|
||||
guid mustEqual PlanetSideGUID(40192)
|
||||
parent.isDefined mustEqual false
|
||||
data match {
|
||||
case RemoteProjectileData(CommonFieldDataWithPlacement(pos, deploy), unk2, lim, unk3, unk4, unk5) =>
|
||||
pos.coord mustEqual Vector3(4644.5938f, 5472.0938f, 82.375f)
|
||||
pos.orient mustEqual Vector3(0, 30.9375f, 171.5625f)
|
||||
deploy.faction mustEqual PlanetSideEmpire.TR
|
||||
deploy.bops mustEqual false
|
||||
deploy.alternate mustEqual false
|
||||
deploy.v1 mustEqual true
|
||||
deploy.v2.isEmpty mustEqual true
|
||||
deploy.v3 mustEqual false
|
||||
deploy.v4.isEmpty mustEqual true
|
||||
deploy.v5.isEmpty mustEqual true
|
||||
deploy.guid mustEqual PlanetSideGUID(0)
|
||||
|
||||
unk2 mustEqual 26214
|
||||
lim mustEqual 134
|
||||
unk3 mustEqual FlightPhysics.State4
|
||||
unk4 mustEqual 0
|
||||
unk5 mustEqual 0
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"decode (hunter_seeker_missile_projectile)" in {
|
||||
PacketCoding.DecodePacket(string_hunter_seeker_missile_projectile).require match {
|
||||
case ObjectCreateMessage(len, cls, guid, parent, data) =>
|
||||
len mustEqual 197
|
||||
cls mustEqual ObjectClass.hunter_seeker_missile_projectile
|
||||
guid mustEqual PlanetSideGUID(40619)
|
||||
parent.isDefined mustEqual false
|
||||
data match {
|
||||
case RemoteProjectileData(CommonFieldDataWithPlacement(pos, deploy), unk2, lim, unk3, unk4, unk5) =>
|
||||
pos.coord mustEqual Vector3(3621.3672f, 2701.8438f, 140.85938f)
|
||||
pos.orient mustEqual Vector3(0, 300.9375f, 258.75f)
|
||||
deploy.faction mustEqual PlanetSideEmpire.NC
|
||||
deploy.bops mustEqual false
|
||||
deploy.alternate mustEqual false
|
||||
deploy.v1 mustEqual true
|
||||
deploy.v2.isEmpty mustEqual true
|
||||
deploy.v3 mustEqual false
|
||||
deploy.v4.isEmpty mustEqual true
|
||||
deploy.v5.isEmpty mustEqual true
|
||||
deploy.guid mustEqual PlanetSideGUID(0)
|
||||
|
||||
unk2 mustEqual 39577
|
||||
lim mustEqual 201
|
||||
unk3 mustEqual FlightPhysics.State4
|
||||
unk4 mustEqual 0
|
||||
unk5 mustEqual 0
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"encode (striker_missile_targeting_projectile)" in {
|
||||
val obj = RemoteProjectileData(
|
||||
CommonFieldDataWithPlacement(
|
||||
PlacementData(4644.5938f, 5472.0938f, 82.375f, 0f, 30.9375f, 171.5625f),
|
||||
CommonFieldData(PlanetSideEmpire.TR, false, false, true, None, false, None, None, PlanetSideGUID(0))
|
||||
),
|
||||
26214, 134, FlightPhysics.State4, 0, 0
|
||||
)
|
||||
val msg = ObjectCreateMessage(ObjectClass.striker_missile_targeting_projectile, PlanetSideGUID(40192), obj)
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
//pkt mustEqual string_striker_projectile
|
||||
|
||||
pkt.toBitVector.take(132) mustEqual string_striker_projectile.toBitVector.take(132)
|
||||
pkt.toBitVector.drop(133).take(7) mustEqual string_striker_projectile.toBitVector.drop(133).take(7)
|
||||
pkt.toBitVector.drop(141) mustEqual string_striker_projectile.toBitVector.drop(141)
|
||||
}
|
||||
}
|
||||
|
||||
"encode (hunter_seeker_missile_projectile)" in {
|
||||
val obj = RemoteProjectileData(
|
||||
CommonFieldDataWithPlacement(
|
||||
PlacementData(3621.3672f, 2701.8438f, 140.85938f, 0, 300.9375f, 258.75f),
|
||||
CommonFieldData(PlanetSideEmpire.NC, false, false, true, None, false, None, None, PlanetSideGUID(0))
|
||||
),
|
||||
39577, 201, FlightPhysics.State4, 0, 0
|
||||
)
|
||||
val msg = ObjectCreateMessage(ObjectClass.hunter_seeker_missile_projectile, PlanetSideGUID(40619), obj)
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
//pkt mustEqual string_hunter_seeker_missile_projectile
|
||||
|
||||
pkt.toBitVector.take(132) mustEqual string_hunter_seeker_missile_projectile.toBitVector.take(132)
|
||||
pkt.toBitVector.drop(133).take(7) mustEqual string_hunter_seeker_missile_projectile.toBitVector.drop(133).take(7)
|
||||
pkt.toBitVector.drop(141) mustEqual string_hunter_seeker_missile_projectile.toBitVector.drop(141)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package game.objectcreate
|
||||
|
||||
import net.psforever.packet.PacketCoding
|
||||
import net.psforever.packet.game.{ObjectCreateMessage, PlanetSideGUID}
|
||||
import net.psforever.packet.game.objectcreate._
|
||||
import net.psforever.types.{PlanetSideEmpire, Vector3}
|
||||
import org.specs2.mutable._
|
||||
import scodec.bits._
|
||||
|
||||
class TrackedProjectileDataTest extends Specification {
|
||||
val string_striker_projectile = hex"17 C5000000 A4B 009D 4C129 0CB0A 9814 00 F5 E3 040000666686400"
|
||||
|
||||
"TrackedProjectileData" should {
|
||||
"decode" in {
|
||||
PacketCoding.DecodePacket(string_striker_projectile).require match {
|
||||
case ObjectCreateMessage(len, cls, guid, parent, data) =>
|
||||
len mustEqual 197
|
||||
cls mustEqual ObjectClass.striker_missile_targeting_projectile
|
||||
guid mustEqual PlanetSideGUID(40192)
|
||||
parent.isDefined mustEqual false
|
||||
data match {
|
||||
case TrackedProjectileData(CommonFieldDataWithPlacement(pos, deploy), unk2, unk3) =>
|
||||
pos.coord mustEqual Vector3(4644.5938f, 5472.0938f, 82.375f)
|
||||
pos.orient mustEqual Vector3(0, 30.9375f, 171.5625f)
|
||||
deploy.faction mustEqual PlanetSideEmpire.TR
|
||||
deploy.bops mustEqual false
|
||||
deploy.alternate mustEqual false
|
||||
deploy.v1 mustEqual true
|
||||
deploy.v2.isEmpty mustEqual true
|
||||
deploy.v3 mustEqual false
|
||||
deploy.v4.isEmpty mustEqual true
|
||||
deploy.v5.isEmpty mustEqual true
|
||||
deploy.guid mustEqual PlanetSideGUID(0)
|
||||
|
||||
unk2 mustEqual TrackedProjectile.Striker
|
||||
|
||||
unk3 mustEqual 0
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"encode" in {
|
||||
val obj = TrackedProjectileData(
|
||||
CommonFieldDataWithPlacement(
|
||||
PlacementData(4644.5938f, 5472.0938f, 82.375f, 0f, 30.9375f, 171.5625f),
|
||||
CommonFieldData(PlanetSideEmpire.TR, false, false, true, None, false, None, None, PlanetSideGUID(0))
|
||||
),
|
||||
TrackedProjectile.Striker,
|
||||
0
|
||||
)
|
||||
val msg = ObjectCreateMessage(ObjectClass.striker_missile_targeting_projectile, PlanetSideGUID(40192), obj)
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
|
||||
pkt.toBitVector.take(132) mustEqual string_striker_projectile.toBitVector.take(132)
|
||||
pkt.toBitVector.drop(133).take(7) mustEqual string_striker_projectile.toBitVector.drop(133).take(7)
|
||||
pkt.toBitVector.drop(141) mustEqual string_striker_projectile.toBitVector.drop(141)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue