initial FriendsResponse packet and tests; though the packet works, it displays odd behavior when decoded by client; might be intentional

This commit is contained in:
FateJH 2016-10-08 17:40:55 -04:00
parent daa22c572e
commit 5564d98395
4 changed files with 66 additions and 1 deletions

View file

@ -455,7 +455,7 @@ object GamePacketOpcode extends Enumeration {
case 0x70 => noDecoder(SquadMemberEvent)
case 0x71 => noDecoder(PlatoonEvent)
case 0x72 => noDecoder(FriendsRequest)
case 0x73 => noDecoder(FriendsResponse)
case 0x73 => game.FriendsReponse.decode
case 0x74 => noDecoder(TriggerEnvironmentalDamageMessage)
case 0x75 => noDecoder(TrainingZoneMessage)
case 0x76 => noDecoder(DeployableObjectsInfoMessage)

View file

@ -203,4 +203,17 @@ object PacketHelpers {
def encodedStringWithLimit(limit : Int) : Codec[String] = variableSizeBytes(encodedStringSizeWithLimit(limit), ascii)
*/
/**
* Construct a `Codec` for reading `wchar_t` (wide character) `Strings` whose length field are constrained to specific bit size proportions.
* Padding may also exist between the length field and the beginning of the contents.
* @param lenSize a codec that defines the bit size that encodes the length
* @param adjustment the optional alignment for padding; defaults to 0
* @return the `String` `Codec`
*/
def specSizeWideStringAligned(lenSize : Codec[Int], adjustment : Int = 0) : Codec[String] =
variableSizeBytes((lenSize <~ ignore(adjustment)).xmap(
insize => insize*2, // number of symbols -> number of bytes (decode)
outSize => outSize/2 // number of bytes -> number of symbols (encode)
), utf16)
}

View file

@ -0,0 +1,29 @@
// Copyright (c) 2016 PSForever.net to present
package net.psforever.packet.game
import net.psforever.packet.{GamePacketOpcode, Marshallable, PacketHelpers, PlanetSideGamePacket}
import scodec.Codec
import scodec.codecs._
/**
* na
* @param player_guid the player
* @param friend the name of the friend
* @param unk na
*/
final case class FriendsResponse(player_guid : PlanetSideGUID,
friend : String,
unk : Int)
extends PlanetSideGamePacket {
type Packet = FriendsResponse
def opcode = GamePacketOpcode.FriendsResponse
def encode = FriendsReponse.encode(this)
}
object FriendsReponse extends Marshallable[FriendsResponse] {
implicit val codec : Codec[FriendsResponse] = (
("player_guid" | PlanetSideGUID.codec) ::
("friend" | PacketHelpers.specSizeWideStringAligned(uint(5), 3)) ::
("unk" | uint8L)
).as[FriendsResponse]
}

View file

@ -830,6 +830,29 @@ class GamePacketTest extends Specification {
}
}
"FriendsResponse" should {
val string = hex"73 618C 60 4B007500720074004800650063007400690063002D004700 00"
"decode" in {
PacketCoding.DecodePacket(string).require match {
case FriendsResponse(player_guid, friend, unk) =>
player_guid mustEqual PlanetSideGUID(35937)
friend.length mustEqual 12
friend mustEqual "KurtHectic-G"
unk mustEqual 0
case default =>
ko
}
}
"encode" in {
val msg = FriendsResponse(PlanetSideGUID(35937), "KurtHectic-G", 0)
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
pkt mustEqual string
}
}
"WeaponDryFireMessage" should {
val string = hex"52 4C00"