mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-04-29 07:45:26 +00:00
Merge pull request #1159 from Resaec/squad_voice_host_request_message
Fully implement the VoiceHostRequest packet
This commit is contained in:
commit
da32c68479
2 changed files with 98 additions and 21 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
// Copyright (c) 2017 PSForever
|
// Copyright (c) 2017 PSForever
|
||||||
package net.psforever.packet.game
|
package net.psforever.packet.game
|
||||||
|
|
||||||
import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket}
|
import net.psforever.packet.{GamePacketOpcode, Marshallable, PacketHelpers, PlanetSideGamePacket}
|
||||||
import net.psforever.types.PlanetSideGUID
|
|
||||||
import scodec.Codec
|
import scodec.Codec
|
||||||
import scodec.bits.ByteVector
|
import scodec.bits.ByteVector
|
||||||
import scodec.codecs._
|
import scodec.codecs._
|
||||||
|
|
@ -11,21 +10,34 @@ import scodec.codecs._
|
||||||
* Used by PlanetSide in conjunction with wiredred/pscs.exe to establish local platoon/squad voice chat.
|
* Used by PlanetSide in conjunction with wiredred/pscs.exe to establish local platoon/squad voice chat.
|
||||||
* We are not focusing on implementation of this feature.
|
* We are not focusing on implementation of this feature.
|
||||||
* At the most, we will merely record data about who requested it.
|
* At the most, we will merely record data about who requested it.
|
||||||
* @param unk na
|
*
|
||||||
* @param player_guid the player who sent this request
|
* @param remote_host true if the player provides info for a remote host (remote_ip)
|
||||||
* @param data everything else
|
* @param port the port to connect to
|
||||||
|
* @param bandwidth the bandwidth set by the player (valid values are 3, 201, 203)
|
||||||
|
* @param remote_ip the IP of the remote voice server, only set if remote_host == true
|
||||||
*/
|
*/
|
||||||
final case class VoiceHostRequest(unk: Boolean, player_guid: PlanetSideGUID, data: ByteVector)
|
final case class VoiceHostRequest(
|
||||||
extends PlanetSideGamePacket {
|
remote_host: Boolean,
|
||||||
type Packet = VoiceHostRequest
|
port: Int,
|
||||||
|
bandwidth: Int,
|
||||||
|
remote_ip: String,
|
||||||
|
data: ByteVector
|
||||||
|
) extends PlanetSideGamePacket {
|
||||||
|
require(port > 0)
|
||||||
|
require(port <= 65535)
|
||||||
|
require(bandwidth == 3 || bandwidth == 201 || bandwidth == 203)
|
||||||
|
require(remote_host == (remote_ip != ""))
|
||||||
|
|
||||||
def opcode = GamePacketOpcode.VoiceHostRequest
|
def opcode = GamePacketOpcode.VoiceHostRequest
|
||||||
def encode = VoiceHostRequest.encode(this)
|
def encode = VoiceHostRequest.encode(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
object VoiceHostRequest extends Marshallable[VoiceHostRequest] {
|
object VoiceHostRequest extends Marshallable[VoiceHostRequest] {
|
||||||
implicit val codec: Codec[VoiceHostRequest] = (
|
implicit val codec: Codec[VoiceHostRequest] = (
|
||||||
("unk" | bool) ::
|
("remote_host" | bool) ::
|
||||||
("player_guid" | PlanetSideGUID.codec) ::
|
("port" | uint16L) ::
|
||||||
|
("bandwidth" | uint8L) ::
|
||||||
|
("remote_ip" | PacketHelpers.encodedStringAligned(7)) ::
|
||||||
("data" | bytes)
|
("data" | bytes)
|
||||||
).as[VoiceHostRequest]
|
).as[VoiceHostRequest]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,91 @@ package game
|
||||||
import org.specs2.mutable._
|
import org.specs2.mutable._
|
||||||
import net.psforever.packet._
|
import net.psforever.packet._
|
||||||
import net.psforever.packet.game._
|
import net.psforever.packet.game._
|
||||||
import net.psforever.types.PlanetSideGUID
|
|
||||||
import scodec.bits._
|
import scodec.bits._
|
||||||
|
|
||||||
class VoiceHostRequestTest extends Specification {
|
class VoiceHostRequestTest extends Specification {
|
||||||
val string_request = hex"b0 2580 00"
|
val string_request_local_75_high = hex"b0 2580 01 c0 00"
|
||||||
|
val string_request_local_1111_mid = hex"b0 2b82 64 c0 00"
|
||||||
|
val string_request_local_1112_mid = hex"b0 2c02 64 c0 00"
|
||||||
|
val string_request_remote_12345_high = hex"b0 9c98 01 c7 803131312e3232322e3132332e323334"
|
||||||
|
|
||||||
"decode" in {
|
"decode local 75 high" in {
|
||||||
PacketCoding.decodePacket(string_request).require match {
|
PacketCoding.decodePacket(string_request_local_75_high).require match {
|
||||||
case VoiceHostRequest(unk, player, _) =>
|
case VoiceHostRequest(remote_host, port, bandwidth, server_ip, data) =>
|
||||||
unk mustEqual false
|
remote_host mustEqual false
|
||||||
player mustEqual PlanetSideGUID(75)
|
port mustEqual 75
|
||||||
|
bandwidth mustEqual 3
|
||||||
|
server_ip mustEqual ""
|
||||||
|
data mustEqual ByteVector.empty
|
||||||
case _ =>
|
case _ =>
|
||||||
ko
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"encode" in {
|
"encode local 75 high" in {
|
||||||
val msg = VoiceHostRequest(false, PlanetSideGUID(75), ByteVector.empty)
|
val msg = VoiceHostRequest(remote_host = false, 75, 3, "", ByteVector.empty)
|
||||||
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
||||||
|
|
||||||
pkt mustEqual string_request
|
pkt mustEqual string_request_local_75_high
|
||||||
|
}
|
||||||
|
|
||||||
|
"decode local 1111 mid" in {
|
||||||
|
PacketCoding.decodePacket(string_request_local_1111_mid).require match {
|
||||||
|
case VoiceHostRequest(remote_host, port, bandwidth, server_ip, data) =>
|
||||||
|
remote_host mustEqual false
|
||||||
|
port mustEqual 1111
|
||||||
|
bandwidth mustEqual 201
|
||||||
|
server_ip mustEqual ""
|
||||||
|
data mustEqual ByteVector.empty
|
||||||
|
case _ =>
|
||||||
|
ko
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"encode local 1111 mid" in {
|
||||||
|
val msg = VoiceHostRequest(remote_host = false, 1111, 201, "", ByteVector.empty)
|
||||||
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
||||||
|
|
||||||
|
pkt mustEqual string_request_local_1111_mid
|
||||||
|
}
|
||||||
|
|
||||||
|
"decode local 1112 mid" in {
|
||||||
|
PacketCoding.decodePacket(string_request_local_1112_mid).require match {
|
||||||
|
case VoiceHostRequest(remote_host, port, bandwidth, server_ip, data) =>
|
||||||
|
remote_host mustEqual false
|
||||||
|
port mustEqual 1112
|
||||||
|
bandwidth mustEqual 201
|
||||||
|
server_ip mustEqual ""
|
||||||
|
data mustEqual ByteVector.empty
|
||||||
|
case _ =>
|
||||||
|
ko
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"encode local 1112 mid" in {
|
||||||
|
val msg = VoiceHostRequest(remote_host = false, 1112, 201, "", ByteVector.empty)
|
||||||
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
||||||
|
|
||||||
|
pkt mustEqual string_request_local_1112_mid
|
||||||
|
}
|
||||||
|
|
||||||
|
"decode remote 12345 high" in {
|
||||||
|
PacketCoding.decodePacket(string_request_remote_12345_high).require match {
|
||||||
|
case VoiceHostRequest(remote, port, codec, server_ip, data) =>
|
||||||
|
remote mustEqual true
|
||||||
|
port mustEqual 12345
|
||||||
|
codec mustEqual 3
|
||||||
|
server_ip mustEqual "111.222.123.234"
|
||||||
|
data mustEqual ByteVector.empty
|
||||||
|
case _ =>
|
||||||
|
ko
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"encode remote 12345 high" in {
|
||||||
|
val msg = VoiceHostRequest(remote_host = true, port = 12345, bandwidth = 3, remote_ip = "111.222.123.234", ByteVector.empty)
|
||||||
|
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
|
||||||
|
|
||||||
|
pkt mustEqual string_request_remote_12345_high
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue