mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-03-09 15:30:31 +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
67 lines
2.3 KiB
Scala
67 lines
2.3 KiB
Scala
// Copyright (c) 2019 PSForever
|
|
package game
|
|
|
|
import net.psforever.packet._
|
|
import net.psforever.packet.game._
|
|
import net.psforever.types.SquadRequestType
|
|
import org.specs2.mutable._
|
|
import scodec.bits._
|
|
|
|
class SquadMembershipRequestTest extends Specification {
|
|
//481c897e-b47b-41cc-b7ad-c604606d985e / PSCap-2016-03-18_12-48-12-PM.gcap / Game record 5521 at 662.786844s
|
|
val string1 = hex"6e015aa7a0224d87a0280000"
|
|
//... / PSCap-2016-06-29_07-49-26-PM (last).gcap / Game record 77 at 9.732430 (found in MultiPacket)
|
|
val string2 = hex"6E265DD7A02800"
|
|
//TODO find example where player_name field is defined
|
|
//TODO find example where unk field is defined and is a string
|
|
|
|
"decode (1)" in {
|
|
PacketCoding.decodePacket(string1).require match {
|
|
case SquadMembershipRequest(req_type, unk2, unk3, p_name, unk5) =>
|
|
req_type mustEqual SquadRequestType.Invite
|
|
unk2 mustEqual 41593365L
|
|
unk3.contains(41605156L) mustEqual true
|
|
p_name mustEqual ""
|
|
unk5.contains(None) mustEqual true
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"decode (2)" in {
|
|
PacketCoding.decodePacket(string2).require match {
|
|
case SquadMembershipRequest(req_type, unk2, unk3, p_name, unk5) =>
|
|
req_type mustEqual SquadRequestType.Accept
|
|
unk2 mustEqual 41606501L
|
|
unk3.isEmpty mustEqual true
|
|
p_name mustEqual ""
|
|
unk5.isEmpty mustEqual true
|
|
case _ =>
|
|
ko
|
|
}
|
|
}
|
|
|
|
"encode (1)" in {
|
|
val msg = SquadMembershipRequest(SquadRequestType.Invite, 41593365, Some(41605156L), "", Some(None))
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
|
pkt mustEqual string1
|
|
}
|
|
|
|
"encode (1; failure 1)" in {
|
|
SquadMembershipRequest(SquadRequestType.Invite, 41593365, None, "", Some(None)) must throwA[AssertionError]
|
|
}
|
|
|
|
"encode (1; failure 2)" in {
|
|
SquadMembershipRequest(SquadRequestType.Invite, 41593365, Some(41605156L), "", None) must throwA[AssertionError]
|
|
}
|
|
|
|
"encode (2)" in {
|
|
val msg = SquadMembershipRequest(SquadRequestType.Accept, 41606501, None, "", None)
|
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
|
pkt mustEqual string2
|
|
}
|
|
|
|
"encode (2; failure)" in {
|
|
SquadMembershipRequest(SquadRequestType.Accept, 41606501, Some(41606501), "", None) must throwA[AssertionError]
|
|
}
|
|
}
|