mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-01-19 18:44:45 +00:00
initial packet for GenericObjectAction2Message and tests; repaired transcoders and tests for TRAP and small turrets
This commit is contained in:
parent
73a0bf5ae7
commit
abfbf1c439
|
|
@ -24,7 +24,7 @@ class SmallTurretConverter extends ObjectCreateConverter[TurretDeployable]() {
|
|||
v1 = true,
|
||||
None,
|
||||
obj.Jammed,
|
||||
Some(true),
|
||||
None,
|
||||
None,
|
||||
obj.OwnerGuid match {
|
||||
case Some(owner) => owner
|
||||
|
|
@ -67,7 +67,7 @@ object SmallTurretConverter {
|
|||
private def MakeMountings(obj: WeaponTurret): List[InventoryItemData.InventoryItem] = {
|
||||
obj.Weapons
|
||||
.map({
|
||||
case ((index, slot)) =>
|
||||
case (index, slot) =>
|
||||
val equip: Equipment = slot.Equipment.get
|
||||
val equipDef = equip.Definition
|
||||
InventoryItemData(equipDef.ObjectId, equip.GUID, index, equipDef.Packet.ConstructorData(equip).get)
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ class TRAPConverter extends ObjectCreateConverter[TrapDeployable]() {
|
|||
obj.Faction,
|
||||
bops = false,
|
||||
alternate = false,
|
||||
true,
|
||||
v1 = true,
|
||||
None,
|
||||
jammered = false,
|
||||
None,
|
||||
false,
|
||||
Some(true),
|
||||
None,
|
||||
obj.OwnerGuid match {
|
||||
case Some(owner) => owner
|
||||
|
|
@ -42,9 +42,9 @@ class TRAPConverter extends ObjectCreateConverter[TrapDeployable]() {
|
|||
obj.Faction,
|
||||
bops = false,
|
||||
alternate = true,
|
||||
true,
|
||||
v1 = true,
|
||||
None,
|
||||
false,
|
||||
jammered = false,
|
||||
Some(true),
|
||||
None,
|
||||
PlanetSideGUID(0)
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ object GamePacketOpcode extends Enumeration {
|
|||
case 0x7f => game.AvatarStatisticsMessage.decode
|
||||
|
||||
// OPCODES 0x80-8f
|
||||
case 0x80 => noDecoder(GenericObjectAction2Message)
|
||||
case 0x80 => game.GenericObjectAction2Message.decode
|
||||
case 0x81 => game.DestroyDisplayMessage.decode
|
||||
case 0x82 => noDecoder(TriggerBotAction)
|
||||
case 0x83 => game.SquadWaypointRequest.decode
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2024 PSForever
|
||||
package net.psforever.packet.game
|
||||
|
||||
import net.psforever.packet.GamePacketOpcode.Type
|
||||
import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket}
|
||||
import net.psforever.types.PlanetSideGUID
|
||||
import scodec.bits.BitVector
|
||||
import scodec.codecs._
|
||||
import scodec.{Attempt, Codec}
|
||||
|
||||
/**
|
||||
* na
|
||||
* @param unk na
|
||||
* @param guid1 na
|
||||
* @param guid2 na
|
||||
*/
|
||||
final case class GenericObjectAction2Message(
|
||||
unk: Int,
|
||||
guid1: PlanetSideGUID,
|
||||
guid2: PlanetSideGUID
|
||||
) extends PlanetSideGamePacket {
|
||||
type Packet = GenericObjectActionMessage
|
||||
def opcode: Type = GamePacketOpcode.GenericObjectAction2Message
|
||||
def encode: Attempt[BitVector] = GenericObjectAction2Message.encode(this)
|
||||
}
|
||||
|
||||
object GenericObjectAction2Message extends Marshallable[GenericObjectAction2Message] {
|
||||
implicit val codec: Codec[GenericObjectAction2Message] = (
|
||||
("unk" | uint(bits = 3)) :: //dword_D32FC0
|
||||
("guid1" | PlanetSideGUID.codec) ::
|
||||
("guid2" | PlanetSideGUID.codec)
|
||||
).as[GenericObjectAction2Message]
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ final case class SmallTurretData(
|
|||
case None =>
|
||||
0
|
||||
}
|
||||
22L + deploySize + internalSize //8u + 7u + 4u + 2u + 1u
|
||||
23L + deploySize + internalSize //1u + 8u + 7u + 4u + 2u + 1u
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +50,7 @@ object SmallTurretData extends Marshallable[SmallTurretData] {
|
|||
|
||||
implicit val codec: Codec[SmallTurretData] = (
|
||||
("deploy" | CommonFieldDataWithPlacement.codec) ::
|
||||
ignore(size = 1) ::
|
||||
("health" | uint8L) ::
|
||||
uintL(bits = 7) ::
|
||||
uint4L ::
|
||||
|
|
@ -57,7 +58,7 @@ object SmallTurretData extends Marshallable[SmallTurretData] {
|
|||
("internals" | optional(bool, InventoryData.codec))
|
||||
).exmap[SmallTurretData](
|
||||
{
|
||||
case deploy :: health :: 0 :: 0xf :: 0 :: internals :: HNil =>
|
||||
case deploy :: _ :: health :: 0 :: 0xf :: 0 :: internals :: HNil =>
|
||||
val (newHealth, newInternals) = if (health == 0 || internals.isEmpty || internals.get.contents.isEmpty) {
|
||||
(0, None)
|
||||
} else {
|
||||
|
|
@ -75,7 +76,7 @@ object SmallTurretData extends Marshallable[SmallTurretData] {
|
|||
} else {
|
||||
(health, internals)
|
||||
}
|
||||
Attempt.successful(deploy :: newHealth :: 0 :: 0xf :: 0 :: newInternals :: HNil)
|
||||
Attempt.successful(deploy :: () :: newHealth :: 0 :: 0xf :: 0 :: newInternals :: HNil)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,20 +14,21 @@ import shapeless.{::, HNil}
|
|||
*/
|
||||
final case class TRAPData(deploy: CommonFieldDataWithPlacement, health: Int) extends ConstructorData {
|
||||
override def bitsize: Long = {
|
||||
22L + deploy.bitsize //8u + 7u + 4u + 3u
|
||||
23L + deploy.bitsize //1u + 8u + 7u + 4u + 3u
|
||||
}
|
||||
}
|
||||
|
||||
object TRAPData extends Marshallable[TRAPData] {
|
||||
implicit val codec: Codec[TRAPData] = (
|
||||
("deploy" | CommonFieldDataWithPlacement.codec) ::
|
||||
ignore(size = 1) ::
|
||||
("health" | uint8L) ::
|
||||
uint(bits = 7) ::
|
||||
uint4L ::
|
||||
uint(bits = 3)
|
||||
).exmap[TRAPData](
|
||||
{
|
||||
case deploy :: health :: 0 :: 15 :: 0 :: HNil =>
|
||||
case deploy :: _:: health :: 0 :: 15 :: 0 :: HNil =>
|
||||
Attempt.successful(TRAPData(deploy, health))
|
||||
|
||||
case data =>
|
||||
|
|
@ -35,7 +36,7 @@ object TRAPData extends Marshallable[TRAPData] {
|
|||
},
|
||||
{
|
||||
case TRAPData(deploy, health) =>
|
||||
Attempt.successful(deploy :: health :: 0 :: 15 :: 0 :: HNil)
|
||||
Attempt.successful(deploy :: () :: health :: 0 :: 15 :: 0 :: HNil)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
30
src/test/scala/game/GenericObjectAction2MessageTest.scala
Normal file
30
src/test/scala/game/GenericObjectAction2MessageTest.scala
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package game
|
||||
|
||||
import org.specs2.mutable._
|
||||
import net.psforever.packet._
|
||||
import net.psforever.packet.game._
|
||||
import net.psforever.types.PlanetSideGUID
|
||||
import scodec.bits._
|
||||
|
||||
class GenericObjectAction2MessageTest extends Specification {
|
||||
val string = hex"80 38C139212 0"
|
||||
|
||||
"decode" in {
|
||||
PacketCoding.decodePacket(string).require match {
|
||||
case GenericObjectAction2Message(unk, guid1, guid2) =>
|
||||
unk mustEqual 1
|
||||
guid1 mustEqual PlanetSideGUID(2502)
|
||||
guid2 mustEqual PlanetSideGUID(2505)
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"encode" in {
|
||||
val msg = GenericObjectAction2Message(1, PlanetSideGUID(2502), PlanetSideGUID(2505))
|
||||
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
||||
|
||||
pkt mustEqual string
|
||||
}
|
||||
}
|
||||
|
|
@ -32,9 +32,9 @@ class SmallTurretDataTest extends Specification {
|
|||
deploy.v1 mustEqual true
|
||||
deploy.v2.isEmpty mustEqual true
|
||||
deploy.jammered mustEqual false
|
||||
deploy.v4.contains(false) mustEqual true
|
||||
deploy.v4.isEmpty mustEqual true
|
||||
deploy.v5.isEmpty mustEqual true
|
||||
deploy.guid mustEqual PlanetSideGUID(7742)
|
||||
deploy.guid mustEqual PlanetSideGUID(3871)
|
||||
|
||||
health mustEqual 0
|
||||
case _ =>
|
||||
|
|
@ -63,9 +63,9 @@ class SmallTurretDataTest extends Specification {
|
|||
deploy.v1 mustEqual true
|
||||
deploy.v2.isEmpty mustEqual true
|
||||
deploy.jammered mustEqual false
|
||||
deploy.v4.contains(true) mustEqual true
|
||||
deploy.v4.isEmpty mustEqual true
|
||||
deploy.v5.isEmpty mustEqual true
|
||||
deploy.guid mustEqual PlanetSideGUID(8208)
|
||||
deploy.guid mustEqual PlanetSideGUID(4232)
|
||||
|
||||
health mustEqual 255
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ class SmallTurretDataTest extends Specification {
|
|||
val obj = SmallTurretData(
|
||||
CommonFieldDataWithPlacement(
|
||||
PlacementData(Vector3(4577.7812f, 5624.828f, 72.046875f), Vector3(0, 2.8125f, 264.375f)),
|
||||
CommonFieldData(PlanetSideEmpire.NC, false, true, true, None, false, Some(false), None, PlanetSideGUID(7742))
|
||||
CommonFieldData(PlanetSideEmpire.NC, bops = false, alternate = true, v1 = true, None, jammered = false, None, None, PlanetSideGUID(3871))
|
||||
),
|
||||
0
|
||||
)
|
||||
|
|
@ -137,7 +137,7 @@ class SmallTurretDataTest extends Specification {
|
|||
val obj = SmallTurretData(
|
||||
CommonFieldDataWithPlacement(
|
||||
PlacementData(Vector3(4527.633f, 6271.3594f, 70.265625f), Vector3(0, 0, 154.6875f)),
|
||||
CommonFieldData(PlanetSideEmpire.VS, false, false, true, None, false, Some(true), None, PlanetSideGUID(8208))
|
||||
CommonFieldData(PlanetSideEmpire.VS, bops = false, alternate = false, v1 = true, None, jammered = false, None, None, PlanetSideGUID(4232))
|
||||
),
|
||||
255,
|
||||
InventoryData(
|
||||
|
|
@ -149,11 +149,11 @@ class SmallTurretDataTest extends Specification {
|
|||
WeaponData(
|
||||
CommonFieldData(
|
||||
PlanetSideEmpire.NEUTRAL,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
bops = false,
|
||||
alternate = false,
|
||||
v1 = true,
|
||||
None,
|
||||
false,
|
||||
jammered = false,
|
||||
None,
|
||||
None,
|
||||
PlanetSideGUID(0)
|
||||
|
|
@ -166,11 +166,11 @@ class SmallTurretDataTest extends Specification {
|
|||
0,
|
||||
CommonFieldData(
|
||||
PlanetSideEmpire.NEUTRAL,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
bops = false,
|
||||
alternate = false,
|
||||
v1 = true,
|
||||
None,
|
||||
false,
|
||||
jammered = false,
|
||||
Some(false),
|
||||
None,
|
||||
PlanetSideGUID(0)
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ class TRAPDataTest extends Specification {
|
|||
deploy.v1 mustEqual true
|
||||
deploy.v2.isEmpty mustEqual true
|
||||
deploy.jammered mustEqual false
|
||||
deploy.v4.contains(true) mustEqual true
|
||||
deploy.v4.isEmpty mustEqual true
|
||||
deploy.v5.isEmpty mustEqual true
|
||||
deploy.guid mustEqual PlanetSideGUID(4748)
|
||||
deploy.guid mustEqual PlanetSideGUID(2502)
|
||||
health mustEqual 255
|
||||
case _ =>
|
||||
ko
|
||||
|
|
@ -45,7 +45,7 @@ class TRAPDataTest extends Specification {
|
|||
val obj = TRAPData(
|
||||
CommonFieldDataWithPlacement(
|
||||
PlacementData(Vector3(3572.4453f, 3277.9766f, 114.0f), Vector3.z(90)),
|
||||
CommonFieldData(PlanetSideEmpire.VS, false, false, true, None, false, Some(true), None, PlanetSideGUID(4748))
|
||||
CommonFieldData(PlanetSideEmpire.VS, bops = false, alternate = false, v1 = true, None, jammered = false, None, None, PlanetSideGUID(2502))
|
||||
),
|
||||
255
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue