mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-03-09 23:40:32 +00:00
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
76 lines
2.1 KiB
Scala
76 lines
2.1 KiB
Scala
// Copyright (c) 2017 PSForever
|
|
package game
|
|
|
|
import org.specs2.mutable._
|
|
import net.psforever.packet._
|
|
import net.psforever.packet.game._
|
|
import net.psforever.types.{PlanetSideGUID, Vector3}
|
|
import scodec.bits._
|
|
|
|
class HitMessageTest extends Specification {
|
|
val string_hitgeneric = hex"09 09E9A70200"
|
|
val string_hitobj = hex"09 99292705F4B1FB9514585F08BDD3D454CC5EE80300"
|
|
|
|
"decode (generic)" in {
|
|
PacketCoding.decodePacket(string_hitgeneric).require match {
|
|
case HitMessage(seq_time, projectile_guid, unk1, hit_info, unk2, unk3, unk4) =>
|
|
seq_time mustEqual 777
|
|
projectile_guid mustEqual PlanetSideGUID(40102)
|
|
unk1 mustEqual 0
|
|
hit_info mustEqual None
|
|
unk2 mustEqual true
|
|
unk3 mustEqual false
|
|
unk4 mustEqual None
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"decode (object)" in {
|
|
PacketCoding.decodePacket(string_hitobj).require match {
|
|
case HitMessage(seq_time, projectile_guid, unk1, hit_info, unk2, unk3, unk4) =>
|
|
seq_time mustEqual 153
|
|
projectile_guid mustEqual PlanetSideGUID(40100)
|
|
unk1 mustEqual 0
|
|
hit_info mustEqual Some(
|
|
HitInfo(
|
|
Vector3(3672.9766f, 2729.8594f, 92.34375f),
|
|
Vector3(3679.5156f, 2722.6172f, 92.796875f),
|
|
Some(PlanetSideGUID(372))
|
|
)
|
|
)
|
|
unk2 mustEqual true
|
|
unk3 mustEqual false
|
|
unk4 mustEqual None
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"encode (generic)" in {
|
|
val msg_hitgeneric = HitMessage(777, PlanetSideGUID(40102), 0, None, true, false, None)
|
|
val pkt_hitgeneric = PacketCoding.encodePacket(msg_hitgeneric).require.toByteVector
|
|
pkt_hitgeneric mustEqual string_hitgeneric
|
|
}
|
|
|
|
"encode (object)" in {
|
|
val msg_hitobj = HitMessage(
|
|
153,
|
|
PlanetSideGUID(40100),
|
|
0,
|
|
Some(
|
|
HitInfo(
|
|
Vector3(3672.9766f, 2729.8594f, 92.34375f),
|
|
Vector3(3679.5156f, 2722.6172f, 92.796875f),
|
|
Some(PlanetSideGUID(372))
|
|
)
|
|
),
|
|
true,
|
|
false,
|
|
None
|
|
)
|
|
val pkt_hitobj = PacketCoding.encodePacket(msg_hitobj).require.toByteVector
|
|
|
|
pkt_hitobj mustEqual string_hitobj
|
|
}
|
|
}
|