2017-03-06 19:30:45 -05:00
|
|
|
// Copyright (c) 2017 PSForever
|
2017-03-04 10:06:10 -05:00
|
|
|
package game
|
|
|
|
|
|
|
|
|
|
import org.specs2.mutable._
|
|
|
|
|
import net.psforever.packet._
|
|
|
|
|
import net.psforever.packet.game._
|
|
|
|
|
import net.psforever.types._
|
|
|
|
|
import scodec.bits._
|
|
|
|
|
|
|
|
|
|
class PlayerStateMessageTest extends Specification {
|
|
|
|
|
val string_short = hex"08 A006 DFD17 B5AEB 380B 0F80002990"
|
2020-07-14 05:54:05 +02:00
|
|
|
val string_mod =
|
|
|
|
|
hex"08 A006 DFD17 B5AEB 380B 0F80002985" //slightly modified from above to demonstrate active booleans
|
2017-03-04 10:06:10 -05:00
|
|
|
val string_vel = hex"08 A006 4DD47 CDB1B 0C0B A8C1A5000403008014A4"
|
|
|
|
|
|
|
|
|
|
"decode (short)" in {
|
Networking
The game uses a UDP-based protocol. Unlike TCP, UDP does not guarantee that
packets arrive, or that they arrive in the correct order. For this reason,
the game protocol implements those features using the following:
* All packets have a sequence number that is utilized for reordering
* Important packets are wrapped in a SlottedMetaPacket with a subslot number
* RelatedA packets ae used to request lost packets using the subslot number
* RelatedB packets are used to confirm received SlottedMetaPackets
All of these go both ways, server <-> client. We used to only partially
implement these features: Outgoing packet bundles used SMPs and could be
resent, but not all packets were bundled and there was no logic for requesting
lost packets from the client and there was no packet reordering, which resulted
in dire consequences in the case of packet loss (zoning failures, crashes and many
other odd bugs). This patch addresses all of these issues.
* Packet bundling: Packets are now automatically bundled and sent as
SlottedMetaPackets using a recurring timer. All manual bundling functionality
was removed.
* Packet reordering: Incoming packets, if received out of order, are stashed and
reordered. The maximum wait time for reordering is 20ms.
* Packet requesting: Missing SlottedMetaPackets are requested from the client.
* PacketCoding refactor: Dropped confusing packet container types. Fixes #5.
* Crypto rewrite: PSCrypto is based on a ancient buggy version of cryptopp.
Updating to a current version was not possible because it removed the
MD5-MAC algorithm. For more details, see Md5Mac.scala.
This patch replaces PSCrypto with native Scala code.
* Added two new actors:
* SocketActor: A simple typed UDP socket actor
* MiddlewareActor: The old session pipeline greatly simplified into a
typed actor that does most of the things mentioned above.
* Begun work on a headless client
* Fixed anniversary gun breaking stamina regen
* Resolved a few sentry errors
2020-09-17 17:04:06 +02:00
|
|
|
PacketCoding.decodePacket(string_short).require match {
|
2020-07-14 05:54:05 +02:00
|
|
|
case PlayerStateMessage(
|
|
|
|
|
guid,
|
|
|
|
|
pos,
|
|
|
|
|
vel,
|
|
|
|
|
facingYaw,
|
|
|
|
|
facingPitch,
|
|
|
|
|
facingUpper,
|
|
|
|
|
unk1,
|
|
|
|
|
crouching,
|
|
|
|
|
jumping,
|
|
|
|
|
jthrust,
|
|
|
|
|
cloaked
|
|
|
|
|
) =>
|
2017-03-04 10:06:10 -05:00
|
|
|
guid mustEqual PlanetSideGUID(1696)
|
|
|
|
|
pos.x mustEqual 4003.7422f
|
|
|
|
|
pos.y mustEqual 5981.414f
|
|
|
|
|
pos.z mustEqual 44.875f
|
|
|
|
|
vel.isDefined mustEqual false
|
2017-07-04 21:44:24 -04:00
|
|
|
facingYaw mustEqual 2.8125f
|
|
|
|
|
facingPitch mustEqual 0f
|
|
|
|
|
facingUpper mustEqual 0f
|
2017-03-04 10:06:10 -05:00
|
|
|
unk1 mustEqual 83
|
|
|
|
|
crouching mustEqual false
|
|
|
|
|
jumping mustEqual false
|
2017-03-19 18:32:26 -04:00
|
|
|
jthrust mustEqual false
|
|
|
|
|
cloaked mustEqual false
|
2017-03-04 10:06:10 -05:00
|
|
|
case _ =>
|
|
|
|
|
ko
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"decode (mod)" in {
|
Networking
The game uses a UDP-based protocol. Unlike TCP, UDP does not guarantee that
packets arrive, or that they arrive in the correct order. For this reason,
the game protocol implements those features using the following:
* All packets have a sequence number that is utilized for reordering
* Important packets are wrapped in a SlottedMetaPacket with a subslot number
* RelatedA packets ae used to request lost packets using the subslot number
* RelatedB packets are used to confirm received SlottedMetaPackets
All of these go both ways, server <-> client. We used to only partially
implement these features: Outgoing packet bundles used SMPs and could be
resent, but not all packets were bundled and there was no logic for requesting
lost packets from the client and there was no packet reordering, which resulted
in dire consequences in the case of packet loss (zoning failures, crashes and many
other odd bugs). This patch addresses all of these issues.
* Packet bundling: Packets are now automatically bundled and sent as
SlottedMetaPackets using a recurring timer. All manual bundling functionality
was removed.
* Packet reordering: Incoming packets, if received out of order, are stashed and
reordered. The maximum wait time for reordering is 20ms.
* Packet requesting: Missing SlottedMetaPackets are requested from the client.
* PacketCoding refactor: Dropped confusing packet container types. Fixes #5.
* Crypto rewrite: PSCrypto is based on a ancient buggy version of cryptopp.
Updating to a current version was not possible because it removed the
MD5-MAC algorithm. For more details, see Md5Mac.scala.
This patch replaces PSCrypto with native Scala code.
* Added two new actors:
* SocketActor: A simple typed UDP socket actor
* MiddlewareActor: The old session pipeline greatly simplified into a
typed actor that does most of the things mentioned above.
* Begun work on a headless client
* Fixed anniversary gun breaking stamina regen
* Resolved a few sentry errors
2020-09-17 17:04:06 +02:00
|
|
|
PacketCoding.decodePacket(string_mod).require match {
|
2020-07-14 05:54:05 +02:00
|
|
|
case PlayerStateMessage(
|
|
|
|
|
guid,
|
|
|
|
|
pos,
|
|
|
|
|
vel,
|
|
|
|
|
facingYaw,
|
|
|
|
|
facingPitch,
|
|
|
|
|
facingUpper,
|
|
|
|
|
unk1,
|
|
|
|
|
crouching,
|
|
|
|
|
jumping,
|
|
|
|
|
jthrust,
|
|
|
|
|
cloaked
|
|
|
|
|
) =>
|
2017-03-04 10:06:10 -05:00
|
|
|
guid mustEqual PlanetSideGUID(1696)
|
|
|
|
|
pos.x mustEqual 4003.7422f
|
|
|
|
|
pos.y mustEqual 5981.414f
|
|
|
|
|
pos.z mustEqual 44.875f
|
|
|
|
|
vel.isDefined mustEqual false
|
2017-07-04 21:44:24 -04:00
|
|
|
facingYaw mustEqual 2.8125f
|
|
|
|
|
facingPitch mustEqual 0f
|
|
|
|
|
facingUpper mustEqual 0f
|
2017-03-04 10:06:10 -05:00
|
|
|
unk1 mustEqual 83
|
|
|
|
|
crouching mustEqual false
|
|
|
|
|
jumping mustEqual true
|
2017-03-19 18:32:26 -04:00
|
|
|
jthrust mustEqual false
|
|
|
|
|
cloaked mustEqual true
|
2017-03-04 10:06:10 -05:00
|
|
|
case _ =>
|
|
|
|
|
ko
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"decode (vel)" in {
|
Networking
The game uses a UDP-based protocol. Unlike TCP, UDP does not guarantee that
packets arrive, or that they arrive in the correct order. For this reason,
the game protocol implements those features using the following:
* All packets have a sequence number that is utilized for reordering
* Important packets are wrapped in a SlottedMetaPacket with a subslot number
* RelatedA packets ae used to request lost packets using the subslot number
* RelatedB packets are used to confirm received SlottedMetaPackets
All of these go both ways, server <-> client. We used to only partially
implement these features: Outgoing packet bundles used SMPs and could be
resent, but not all packets were bundled and there was no logic for requesting
lost packets from the client and there was no packet reordering, which resulted
in dire consequences in the case of packet loss (zoning failures, crashes and many
other odd bugs). This patch addresses all of these issues.
* Packet bundling: Packets are now automatically bundled and sent as
SlottedMetaPackets using a recurring timer. All manual bundling functionality
was removed.
* Packet reordering: Incoming packets, if received out of order, are stashed and
reordered. The maximum wait time for reordering is 20ms.
* Packet requesting: Missing SlottedMetaPackets are requested from the client.
* PacketCoding refactor: Dropped confusing packet container types. Fixes #5.
* Crypto rewrite: PSCrypto is based on a ancient buggy version of cryptopp.
Updating to a current version was not possible because it removed the
MD5-MAC algorithm. For more details, see Md5Mac.scala.
This patch replaces PSCrypto with native Scala code.
* Added two new actors:
* SocketActor: A simple typed UDP socket actor
* MiddlewareActor: The old session pipeline greatly simplified into a
typed actor that does most of the things mentioned above.
* Begun work on a headless client
* Fixed anniversary gun breaking stamina regen
* Resolved a few sentry errors
2020-09-17 17:04:06 +02:00
|
|
|
PacketCoding.decodePacket(string_vel).require match {
|
2020-07-14 05:54:05 +02:00
|
|
|
case PlayerStateMessage(
|
|
|
|
|
guid,
|
|
|
|
|
pos,
|
|
|
|
|
vel,
|
|
|
|
|
facingYaw,
|
|
|
|
|
facingPitch,
|
|
|
|
|
facingUpper,
|
|
|
|
|
unk1,
|
|
|
|
|
crouching,
|
|
|
|
|
jumping,
|
|
|
|
|
jthrust,
|
|
|
|
|
cloaked
|
|
|
|
|
) =>
|
2017-03-04 10:06:10 -05:00
|
|
|
guid mustEqual PlanetSideGUID(1696)
|
|
|
|
|
pos.x mustEqual 4008.6016f
|
|
|
|
|
pos.y mustEqual 5987.6016f
|
|
|
|
|
pos.z mustEqual 44.1875f
|
|
|
|
|
vel.isDefined mustEqual true
|
2021-10-05 09:59:49 -04:00
|
|
|
vel.get.x mustEqual 9.1125f
|
|
|
|
|
vel.get.y mustEqual 23.625f
|
2017-03-04 10:06:10 -05:00
|
|
|
vel.get.z mustEqual 0.0f
|
2017-07-04 21:44:24 -04:00
|
|
|
facingYaw mustEqual 22.5f
|
2019-11-29 11:14:25 -05:00
|
|
|
facingPitch mustEqual -11.25f
|
2017-07-04 21:44:24 -04:00
|
|
|
facingUpper mustEqual 0f
|
2017-03-04 10:06:10 -05:00
|
|
|
unk1 mustEqual 165
|
|
|
|
|
crouching mustEqual false
|
|
|
|
|
jumping mustEqual false
|
2017-03-19 18:32:26 -04:00
|
|
|
jthrust mustEqual false
|
|
|
|
|
cloaked mustEqual false
|
2017-03-04 10:06:10 -05:00
|
|
|
case _ =>
|
|
|
|
|
ko
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"encode (short)" in {
|
|
|
|
|
val msg = PlayerStateMessage(
|
|
|
|
|
PlanetSideGUID(1696),
|
|
|
|
|
Vector3(4003.7422f, 5981.414f, 44.875f),
|
|
|
|
|
None,
|
2020-07-14 05:54:05 +02:00
|
|
|
2.8125f,
|
|
|
|
|
0f,
|
|
|
|
|
0f,
|
|
|
|
|
83,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false
|
|
|
|
|
)
|
Networking
The game uses a UDP-based protocol. Unlike TCP, UDP does not guarantee that
packets arrive, or that they arrive in the correct order. For this reason,
the game protocol implements those features using the following:
* All packets have a sequence number that is utilized for reordering
* Important packets are wrapped in a SlottedMetaPacket with a subslot number
* RelatedA packets ae used to request lost packets using the subslot number
* RelatedB packets are used to confirm received SlottedMetaPackets
All of these go both ways, server <-> client. We used to only partially
implement these features: Outgoing packet bundles used SMPs and could be
resent, but not all packets were bundled and there was no logic for requesting
lost packets from the client and there was no packet reordering, which resulted
in dire consequences in the case of packet loss (zoning failures, crashes and many
other odd bugs). This patch addresses all of these issues.
* Packet bundling: Packets are now automatically bundled and sent as
SlottedMetaPackets using a recurring timer. All manual bundling functionality
was removed.
* Packet reordering: Incoming packets, if received out of order, are stashed and
reordered. The maximum wait time for reordering is 20ms.
* Packet requesting: Missing SlottedMetaPackets are requested from the client.
* PacketCoding refactor: Dropped confusing packet container types. Fixes #5.
* Crypto rewrite: PSCrypto is based on a ancient buggy version of cryptopp.
Updating to a current version was not possible because it removed the
MD5-MAC algorithm. For more details, see Md5Mac.scala.
This patch replaces PSCrypto with native Scala code.
* Added two new actors:
* SocketActor: A simple typed UDP socket actor
* MiddlewareActor: The old session pipeline greatly simplified into a
typed actor that does most of the things mentioned above.
* Begun work on a headless client
* Fixed anniversary gun breaking stamina regen
* Resolved a few sentry errors
2020-09-17 17:04:06 +02:00
|
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
2017-03-04 10:06:10 -05:00
|
|
|
pkt mustEqual string_short
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"encode (mod)" in {
|
|
|
|
|
val msg = PlayerStateMessage(
|
|
|
|
|
PlanetSideGUID(1696),
|
|
|
|
|
Vector3(4003.7422f, 5981.414f, 44.875f),
|
|
|
|
|
None,
|
2020-07-14 05:54:05 +02:00
|
|
|
2.8125f,
|
|
|
|
|
0f,
|
|
|
|
|
0f,
|
|
|
|
|
83,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
)
|
Networking
The game uses a UDP-based protocol. Unlike TCP, UDP does not guarantee that
packets arrive, or that they arrive in the correct order. For this reason,
the game protocol implements those features using the following:
* All packets have a sequence number that is utilized for reordering
* Important packets are wrapped in a SlottedMetaPacket with a subslot number
* RelatedA packets ae used to request lost packets using the subslot number
* RelatedB packets are used to confirm received SlottedMetaPackets
All of these go both ways, server <-> client. We used to only partially
implement these features: Outgoing packet bundles used SMPs and could be
resent, but not all packets were bundled and there was no logic for requesting
lost packets from the client and there was no packet reordering, which resulted
in dire consequences in the case of packet loss (zoning failures, crashes and many
other odd bugs). This patch addresses all of these issues.
* Packet bundling: Packets are now automatically bundled and sent as
SlottedMetaPackets using a recurring timer. All manual bundling functionality
was removed.
* Packet reordering: Incoming packets, if received out of order, are stashed and
reordered. The maximum wait time for reordering is 20ms.
* Packet requesting: Missing SlottedMetaPackets are requested from the client.
* PacketCoding refactor: Dropped confusing packet container types. Fixes #5.
* Crypto rewrite: PSCrypto is based on a ancient buggy version of cryptopp.
Updating to a current version was not possible because it removed the
MD5-MAC algorithm. For more details, see Md5Mac.scala.
This patch replaces PSCrypto with native Scala code.
* Added two new actors:
* SocketActor: A simple typed UDP socket actor
* MiddlewareActor: The old session pipeline greatly simplified into a
typed actor that does most of the things mentioned above.
* Begun work on a headless client
* Fixed anniversary gun breaking stamina regen
* Resolved a few sentry errors
2020-09-17 17:04:06 +02:00
|
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
2017-03-04 10:06:10 -05:00
|
|
|
pkt mustEqual string_mod
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"encode (vel)" in {
|
|
|
|
|
val msg = PlayerStateMessage(
|
|
|
|
|
PlanetSideGUID(1696),
|
|
|
|
|
Vector3(4008.6016f, 5987.6016f, 44.1875f),
|
2021-10-05 09:59:49 -04:00
|
|
|
Some(Vector3(9.1125f, 23.625f, 0f)),
|
2020-07-14 05:54:05 +02:00
|
|
|
22.5f,
|
|
|
|
|
-11.25f,
|
|
|
|
|
0f,
|
|
|
|
|
165,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
false
|
|
|
|
|
)
|
Networking
The game uses a UDP-based protocol. Unlike TCP, UDP does not guarantee that
packets arrive, or that they arrive in the correct order. For this reason,
the game protocol implements those features using the following:
* All packets have a sequence number that is utilized for reordering
* Important packets are wrapped in a SlottedMetaPacket with a subslot number
* RelatedA packets ae used to request lost packets using the subslot number
* RelatedB packets are used to confirm received SlottedMetaPackets
All of these go both ways, server <-> client. We used to only partially
implement these features: Outgoing packet bundles used SMPs and could be
resent, but not all packets were bundled and there was no logic for requesting
lost packets from the client and there was no packet reordering, which resulted
in dire consequences in the case of packet loss (zoning failures, crashes and many
other odd bugs). This patch addresses all of these issues.
* Packet bundling: Packets are now automatically bundled and sent as
SlottedMetaPackets using a recurring timer. All manual bundling functionality
was removed.
* Packet reordering: Incoming packets, if received out of order, are stashed and
reordered. The maximum wait time for reordering is 20ms.
* Packet requesting: Missing SlottedMetaPackets are requested from the client.
* PacketCoding refactor: Dropped confusing packet container types. Fixes #5.
* Crypto rewrite: PSCrypto is based on a ancient buggy version of cryptopp.
Updating to a current version was not possible because it removed the
MD5-MAC algorithm. For more details, see Md5Mac.scala.
This patch replaces PSCrypto with native Scala code.
* Added two new actors:
* SocketActor: A simple typed UDP socket actor
* MiddlewareActor: The old session pipeline greatly simplified into a
typed actor that does most of the things mentioned above.
* Begun work on a headless client
* Fixed anniversary gun breaking stamina regen
* Resolved a few sentry errors
2020-09-17 17:04:06 +02:00
|
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
2017-03-04 10:06:10 -05:00
|
|
|
pkt mustEqual string_vel
|
|
|
|
|
}
|
|
|
|
|
}
|