From baf83fdeae17311080d775e84654b855122dc864 Mon Sep 17 00:00:00 2001 From: FateJH Date: Sat, 8 Oct 2016 18:16:15 -0400 Subject: [PATCH 1/2] initial FriendsRequest packet and tests; must track how server responds for more applicable testing --- .../psforever/packet/GamePacketOpcode.scala | 2 +- .../packet/game/FriendsRequest.scala | 22 +++++++++++++++++++ common/src/test/scala/GamePacketTest.scala | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala diff --git a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala index 6e9984e5..432fdd51 100644 --- a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala +++ b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala @@ -454,7 +454,7 @@ object GamePacketOpcode extends Enumeration { // OPCODES 0x70-7f case 0x70 => noDecoder(SquadMemberEvent) case 0x71 => noDecoder(PlatoonEvent) - case 0x72 => noDecoder(FriendsRequest) + case 0x72 => game.FriendsRequest.decode case 0x73 => noDecoder(FriendsResponse) case 0x74 => noDecoder(TriggerEnvironmentalDamageMessage) case 0x75 => noDecoder(TrainingZoneMessage) diff --git a/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala b/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala new file mode 100644 index 00000000..64ee35cf --- /dev/null +++ b/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala @@ -0,0 +1,22 @@ +// 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._ + +final case class FriendsRequest(unk : Int, + friend : String) + extends PlanetSideGamePacket { + type Packet = FriendsRequest + def opcode = GamePacketOpcode.FriendsRequest + def encode = FriendsRequest.encode(this) +} + +object FriendsRequest extends Marshallable[FriendsRequest] { + implicit val codec : Codec[FriendsRequest] = ( + ("unk" | uintL(3)) :: + ("friend" | PacketHelpers.encodedWideStringAligned(5)) + ).as[FriendsRequest] +} + diff --git a/common/src/test/scala/GamePacketTest.scala b/common/src/test/scala/GamePacketTest.scala index 2f7e8a11..e5de267c 100644 --- a/common/src/test/scala/GamePacketTest.scala +++ b/common/src/test/scala/GamePacketTest.scala @@ -830,6 +830,28 @@ class GamePacketTest extends Specification { } } + "FriendsRequest" should { + val string = hex"72 3 0a0 46004a0048004e004300" + + "decode" in { + PacketCoding.DecodePacket(string).require match { + case FriendsRequest(unk, friend) => + unk mustEqual 1 + friend.length mustEqual 5 + friend mustEqual "FJHNC" + case default => + ko + } + } + + "encode" in { + val msg = FriendsRequest(1, "FJHNC") + val pkt = PacketCoding.EncodePacket(msg).require.toByteVector + + pkt mustEqual string + } + } + "WeaponDryFireMessage" should { val string = hex"52 4C00" From 7a752a3279a34739aaf998b61a0a31cd60b4953d Mon Sep 17 00:00:00 2001 From: FateJH Date: Wed, 12 Oct 2016 19:39:00 -0400 Subject: [PATCH 2/2] wrote comments; re-named a parameter --- .../packet/game/FriendsRequest.scala | 30 +++++++++++++++++-- common/src/test/scala/GamePacketTest.scala | 6 ++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala b/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala index 64ee35cf..d0ded324 100644 --- a/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala +++ b/common/src/main/scala/net/psforever/packet/game/FriendsRequest.scala @@ -5,7 +5,33 @@ import net.psforever.packet.{GamePacketOpcode, Marshallable, PacketHelpers, Plan import scodec.Codec import scodec.codecs._ -final case class FriendsRequest(unk : Int, +/** + * Manage the lists of other players whose names are retained by the given player.
+ *
+ * Players can be remembered by their names and added to a list of remembered names - the "friends list." + * They can also be dropped from the list. + * A list of "ignored" player names can also be retained. + * Ignored players will have their comments stifled in the given player's chat window. + * No name will be appended or removed from any list until the response to this packet is received.
+ *
+ * Actions that involve the "remove" functionality will locate the entered name in the local list before dispatching this packet. + * A complaint will be logged to the event window if the name is not found.
+ *
+ * Actions:
+ * 0 - display friends list
+ * 1 - add player to friends list
+ * 2 - remove player from friends list
+ * 4 - display ignored player list
+ * 5 - add player to ignored player list
+ * 6 - remove player from ignored player list
+ *
+ * Exploration:
+ * Are action = 3 and action = 7 supposed to do anything? + * @param action the purpose of this packet + * @param friend the player name that was entered; + * blank in certain situations + */ +final case class FriendsRequest(action : Int, friend : String) extends PlanetSideGamePacket { type Packet = FriendsRequest @@ -15,7 +41,7 @@ final case class FriendsRequest(unk : Int, object FriendsRequest extends Marshallable[FriendsRequest] { implicit val codec : Codec[FriendsRequest] = ( - ("unk" | uintL(3)) :: + ("action" | uintL(3)) :: ("friend" | PacketHelpers.encodedWideStringAligned(5)) ).as[FriendsRequest] } diff --git a/common/src/test/scala/GamePacketTest.scala b/common/src/test/scala/GamePacketTest.scala index e5de267c..8e8fa814 100644 --- a/common/src/test/scala/GamePacketTest.scala +++ b/common/src/test/scala/GamePacketTest.scala @@ -831,12 +831,12 @@ class GamePacketTest extends Specification { } "FriendsRequest" should { - val string = hex"72 3 0a0 46004a0048004e004300" + val string = hex"72 3 0A0 46004A0048004E004300" "decode" in { PacketCoding.DecodePacket(string).require match { - case FriendsRequest(unk, friend) => - unk mustEqual 1 + case FriendsRequest(action, friend) => + action mustEqual 1 friend.length mustEqual 5 friend mustEqual "FJHNC" case default =>