mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-13 19:53:38 +00:00
Initial Commit
This commit is contained in:
commit
d96fce6299
21 changed files with 1989 additions and 0 deletions
68
common/src/test/scala/PacketCodingTest.scala
Normal file
68
common/src/test/scala/PacketCodingTest.scala
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import org.specs2.mutable._
|
||||
import psforever.crypto.CryptoInterface
|
||||
import psforever.net._
|
||||
import scodec.bits._
|
||||
|
||||
class PacketCodingTest extends Specification {
|
||||
/*def roundTrip[Container <: PlanetSidePacketContainer, Packet <: PlanetSidePacket](cont : Container, pkt : Packet) = {
|
||||
|
||||
val filledContainer = cont match {
|
||||
case x : ControlPacket => x.copy(packet = pkt.asInstanceOf[PlanetSideControlPacket])
|
||||
}
|
||||
val pktEncoded = PacketCoding.MarshalPacket(ControlPacket(packetUnderTest.opcode, packetUnderTest)).require
|
||||
val pktDecoded = PacketCoding.UnMarshalPacket(pkt.toByteVector).require.asInstanceOf[ControlPacket]
|
||||
val recvPkt = decoded.packet.asInstanceOf[ServerStart]
|
||||
|
||||
}*/
|
||||
|
||||
"Packet coding" should {
|
||||
"correctly decode control packets" in {
|
||||
val packet = PacketCoding.UnmarshalPacket(hex"0001 00000002 00261e27 000001f0").require
|
||||
|
||||
packet.isInstanceOf[ControlPacket] mustEqual true
|
||||
|
||||
val controlPacket = packet.asInstanceOf[ControlPacket]
|
||||
controlPacket.opcode mustEqual ControlPacketOpcode.ClientStart
|
||||
controlPacket.packet mustEqual ClientStart(656287232)
|
||||
}
|
||||
|
||||
"encode and decode to identical packets" in {
|
||||
val clientNonce = 213129
|
||||
val serverNonce = 848483
|
||||
|
||||
val packetUnderTest = ServerStart(clientNonce, serverNonce)
|
||||
val pkt = PacketCoding.MarshalPacket(ControlPacket(packetUnderTest.opcode, packetUnderTest)).require
|
||||
|
||||
val decoded = PacketCoding.UnmarshalPacket(pkt.toByteVector).require.asInstanceOf[ControlPacket]
|
||||
val recvPkt = decoded.packet.asInstanceOf[ServerStart]
|
||||
|
||||
packetUnderTest mustEqual recvPkt
|
||||
}
|
||||
|
||||
"reject corrupted control packets" in {
|
||||
val packet = PacketCoding.UnmarshalPacket(hex"0001 00001002 00261e27 004101f0")
|
||||
|
||||
packet.isSuccessful mustEqual false
|
||||
}
|
||||
|
||||
"correctly decode crypto packets" in {
|
||||
val packet = PacketCoding.UnmarshalPacket(hex"0001 00000002 00261e27 000001f0").require
|
||||
|
||||
packet.isInstanceOf[ControlPacket] mustEqual true
|
||||
|
||||
val controlPacket = packet.asInstanceOf[ControlPacket]
|
||||
controlPacket.opcode mustEqual ControlPacketOpcode.ClientStart
|
||||
controlPacket.packet mustEqual ClientStart(656287232)
|
||||
}
|
||||
|
||||
"reject bad packet types" in {
|
||||
PacketCoding.UnmarshalPacket(hex"ff414141").isFailure mustEqual true
|
||||
}
|
||||
|
||||
"reject small packets" in {
|
||||
PacketCoding.UnmarshalPacket(hex"00").isFailure mustEqual true
|
||||
PacketCoding.UnmarshalPacket(hex"").isFailure mustEqual true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue