mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-03-24 22:59:09 +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.5 KiB
Scala
76 lines
2.5 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 TriggerEffectMessageTest extends Specification {
|
|
val string_motionalarmsensor = hex"51 970B 82 6F6E FA00C00000"
|
|
val string_boomer = hex"51 0000 93 737061776E5F6F626A6563745F656666656374 417BB2CB3B4F8E00000000"
|
|
val string_boomer_explode = hex"51 DF09 8F 6465746F6E6174655F626F6F6D6572 00"
|
|
|
|
"decode (motion alarm sensor)" in {
|
|
PacketCoding.decodePacket(string_motionalarmsensor).require match {
|
|
case TriggerEffectMessage(guid, effect, unk, location) =>
|
|
guid mustEqual PlanetSideGUID(2967)
|
|
effect mustEqual "on"
|
|
unk.isDefined mustEqual true
|
|
unk.get.unk1 mustEqual true
|
|
unk.get.unk2 mustEqual 1000L
|
|
location.isDefined mustEqual false
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"decode (boomer)" in {
|
|
PacketCoding.decodePacket(string_boomer).require match {
|
|
case TriggerEffectMessage(guid, effect, unk, location) =>
|
|
guid mustEqual PlanetSideGUID(0)
|
|
effect mustEqual "spawn_object_effect"
|
|
unk.isDefined mustEqual false
|
|
location.isDefined mustEqual true
|
|
location.get.pos mustEqual Vector3(3567.0156f, 3278.6953f, 114.484375f)
|
|
location.get.orient mustEqual Vector3(0, 0, 90)
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"decode (boomer explode)" in {
|
|
PacketCoding.decodePacket(string_boomer_explode).require match {
|
|
case TriggerEffectMessage(guid, effect, unk, location) =>
|
|
guid mustEqual PlanetSideGUID(2527)
|
|
effect mustEqual "detonate_boomer"
|
|
unk.isDefined mustEqual false
|
|
location.isDefined mustEqual false
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"encode (motion alarm sensor)" in {
|
|
val msg = TriggerEffectMessage(PlanetSideGUID(2967), "on", true, 1000L)
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
|
|
|
pkt mustEqual string_motionalarmsensor
|
|
}
|
|
|
|
"encode (boomer)" in {
|
|
val msg =
|
|
TriggerEffectMessage("spawn_object_effect", Vector3(3567.0156f, 3278.6953f, 114.484375f), Vector3(0, 0, 90))
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
|
|
|
pkt mustEqual string_boomer
|
|
}
|
|
|
|
"encode (boomer explode)" in {
|
|
val msg = TriggerEffectMessage(PlanetSideGUID(2527), "detonate_boomer")
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
|
|
|
pkt mustEqual string_boomer_explode
|
|
}
|
|
}
|