2017-12-05 00:37:24 -05:00
|
|
|
// Copyright (c) 2017 PSForever
|
|
|
|
|
package game.objectcreate
|
|
|
|
|
|
|
|
|
|
import net.psforever.packet.PacketCoding
|
2020-01-06 08:45:55 -05:00
|
|
|
import net.psforever.packet.game.ObjectCreateMessage
|
2017-12-05 00:37:24 -05:00
|
|
|
import net.psforever.packet.game.objectcreate._
|
2020-01-06 08:45:55 -05:00
|
|
|
import net.psforever.types.{PlanetSideEmpire, PlanetSideGUID}
|
2017-12-05 00:37:24 -05:00
|
|
|
import org.specs2.mutable._
|
|
|
|
|
import scodec.bits._
|
|
|
|
|
|
|
|
|
|
class CaptureFlagDataTest extends Specification {
|
2020-07-14 05:54:05 +02:00
|
|
|
val string_captureflag =
|
|
|
|
|
hex"17 E5000000 CE8EA10 04A47 B818A FE0E 00 00 0F 24000015000400160B09000" //LLU for Qumu on Amerish
|
2017-12-05 00:37:24 -05:00
|
|
|
|
|
|
|
|
"CaptureFlagData" in {
|
|
|
|
|
"decode" 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_captureflag).require match {
|
2017-12-05 00:37:24 -05:00
|
|
|
case ObjectCreateMessage(len, cls, guid, parent, data) =>
|
|
|
|
|
len mustEqual 229
|
|
|
|
|
cls mustEqual ObjectClass.capture_flag
|
|
|
|
|
guid mustEqual PlanetSideGUID(4330)
|
|
|
|
|
parent.isDefined mustEqual false
|
2019-03-03 08:23:30 -05:00
|
|
|
data.isInstanceOf[CaptureFlagData] mustEqual true
|
|
|
|
|
val flag = data.asInstanceOf[CaptureFlagData]
|
2017-12-05 00:37:24 -05:00
|
|
|
flag.pos.coord.x mustEqual 3912.0312f
|
|
|
|
|
flag.pos.coord.y mustEqual 5169.4375f
|
|
|
|
|
flag.pos.coord.z mustEqual 59.96875f
|
|
|
|
|
flag.pos.orient.x mustEqual 0f
|
|
|
|
|
flag.pos.orient.y mustEqual 0f
|
|
|
|
|
flag.pos.orient.z mustEqual 47.8125f
|
|
|
|
|
flag.faction mustEqual PlanetSideEmpire.NC
|
2021-01-26 23:03:42 +00:00
|
|
|
flag.owningBaseGuid mustEqual 21
|
|
|
|
|
flag.targetBaseGuid mustEqual 4
|
|
|
|
|
flag.milliseconds_remaining mustEqual 592662
|
2017-12-05 00:37:24 -05:00
|
|
|
case _ =>
|
|
|
|
|
ko
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"encode" in {
|
2021-01-27 22:39:23 +00:00
|
|
|
val obj = CaptureFlagData(PlacementData(3912.0312f, 5169.4375f, 59.96875f, 0f, 0f, 47.8125f), PlanetSideEmpire.NC, 21, 4, 592662)
|
2017-12-05 00:37:24 -05:00
|
|
|
val msg = ObjectCreateMessage(ObjectClass.capture_flag, PlanetSideGUID(4330), obj)
|
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-12-05 00:37:24 -05:00
|
|
|
pkt mustEqual string_captureflag
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|