feat(secure): add get_playing_session and start working on auto_matchmake_with_param_postpone with RmcSerialize macro
This commit is contained in:
parent
d8c184171d
commit
d01acbb931
16 changed files with 338 additions and 23 deletions
|
|
@ -17,22 +17,6 @@ impl<'a> RmcSerialize for &'a [u8]{
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> RmcSerialize for Vec<u8>{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
(&self[..]).serialize(writer)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
let len: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
|
||||
|
||||
let mut data = vec![0; len as usize];
|
||||
|
||||
reader.read_exact(&mut data)?;
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RmcSerialize for Box<[u8]>{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
(&self[..]).serialize(writer)
|
||||
|
|
|
|||
54
src/rmc/structures/matchmake.rs
Normal file
54
src/rmc/structures/matchmake.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use macros::RmcSerialize;
|
||||
use crate::kerberos::KerberosDateTime;
|
||||
use crate::rmc::structures::RmcSerialize;
|
||||
use crate::rmc::structures::variant::Variant;
|
||||
|
||||
// rmc structure
|
||||
#[derive(RmcSerialize)]
|
||||
#[rmc_struct(0)]
|
||||
struct Gathering{
|
||||
self_gid: u32,
|
||||
owner_pid: u32,
|
||||
host_pid: u32,
|
||||
minimum_participants: u16,
|
||||
maximum_participants: u16,
|
||||
participant_policy: u32,
|
||||
policy_argument: u32,
|
||||
flags: u32,
|
||||
state: u32,
|
||||
description: String
|
||||
}
|
||||
|
||||
// rmc structure
|
||||
#[derive(RmcSerialize)]
|
||||
#[rmc_struct(0)]
|
||||
struct MatchmakeParam{
|
||||
params: Vec<(String, Variant)>
|
||||
}
|
||||
|
||||
|
||||
// rmc structure
|
||||
#[derive(RmcSerialize)]
|
||||
#[rmc_struct(3)]
|
||||
struct MatchmakeSession{
|
||||
//inherits from
|
||||
#[extends]
|
||||
gathering: Gathering,
|
||||
|
||||
gamemode: u32,
|
||||
attributes: Vec<u32>,
|
||||
open_participation: bool,
|
||||
matchmake_system_type: u32,
|
||||
application_buffer: Vec<u8>,
|
||||
participation_count: u32,
|
||||
progress_score: u8,
|
||||
session_key: Vec<u8>,
|
||||
option0: u32,
|
||||
matchmake_param: MatchmakeParam,
|
||||
datetime: KerberosDateTime,
|
||||
user_password: String,
|
||||
refer_gid: u32,
|
||||
user_password_enabled: bool,
|
||||
system_password_enabled: bool
|
||||
}
|
||||
|
||||
|
|
@ -10,10 +10,14 @@ pub enum Error{
|
|||
#[error("Io Error: {0}")]
|
||||
Io(#[from] io::Error),
|
||||
#[error("UTF8 conversion Error: {0}")]
|
||||
Utf8(#[from] FromUtf8Error)
|
||||
Utf8(#[from] FromUtf8Error),
|
||||
#[error("unexpected value: {0}")]
|
||||
UnexpectedValue(u64),
|
||||
#[error("version mismatch: {0}")]
|
||||
VersionMismatch(u8),
|
||||
}
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
pub mod string;
|
||||
pub mod any;
|
||||
|
|
@ -23,6 +27,9 @@ pub mod connection_data;
|
|||
pub mod rmc_struct;
|
||||
pub mod list;
|
||||
pub mod qbuffer;
|
||||
pub mod primitives;
|
||||
pub mod matchmake;
|
||||
pub mod variant;
|
||||
|
||||
pub trait RmcSerialize: Sized{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> Result<()>;
|
||||
|
|
|
|||
94
src/rmc/structures/primitives.rs
Normal file
94
src/rmc/structures/primitives.rs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
use std::io::{Read, Write};
|
||||
use bytemuck::bytes_of;
|
||||
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
|
||||
use crate::rmc::structures::RmcSerialize;
|
||||
|
||||
impl RmcSerialize for u8{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for u16{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for u32{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for u64{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for i64{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for f64{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
Ok(writer.write_all(bytes_of(self))?)
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(reader.read_struct(IS_BIG_ENDIAN)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl RmcSerialize for bool{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
match self{
|
||||
true => writer.write_all(&[1])?,
|
||||
false => writer.write_all(&[0])?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(mut reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
Ok(u8::deserialize(reader)? != 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T: RmcSerialize, U: RmcSerialize> RmcSerialize for (T, U){
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
self.0.serialize(writer)?;
|
||||
self.1.serialize(writer)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
let first = T::deserialize(reader)?;
|
||||
let second = U::deserialize(reader)?;
|
||||
|
||||
Ok((first, second))
|
||||
}
|
||||
}
|
||||
|
|
@ -21,4 +21,5 @@ pub fn write_struct(mut writer: &mut dyn Write, version: u8, pred: impl Fn(&mut
|
|||
writer.write_all(&scratch_space)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
63
src/rmc/structures/variant.rs
Normal file
63
src/rmc/structures/variant.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use std::io::{Read, Write};
|
||||
use crate::kerberos::KerberosDateTime;
|
||||
use crate::rmc::structures;
|
||||
use crate::rmc::structures::RmcSerialize;
|
||||
|
||||
pub enum Variant{
|
||||
None,
|
||||
SInt64(i64),
|
||||
Double(f64),
|
||||
Bool(bool),
|
||||
String(String),
|
||||
DateTime(KerberosDateTime),
|
||||
UInt64(u64),
|
||||
}
|
||||
|
||||
impl RmcSerialize for Variant{
|
||||
fn serialize(&self, writer: &mut dyn Write) -> crate::rmc::structures::Result<()> {
|
||||
match self{
|
||||
Variant::None => {
|
||||
writer.write_all(&[0])?;
|
||||
}
|
||||
Variant::SInt64(v) => {
|
||||
writer.write_all(&[1])?;
|
||||
v.serialize(writer)?;
|
||||
}
|
||||
Variant::Double(v) => {
|
||||
writer.write_all(&[2])?;
|
||||
v.serialize(writer)?;
|
||||
}
|
||||
Variant::Bool(v) => {
|
||||
writer.write_all(&[3])?;
|
||||
v.serialize(writer)?;
|
||||
}
|
||||
Variant::String(v) => {
|
||||
writer.write_all(&[4])?;
|
||||
v.serialize(writer)?;
|
||||
}
|
||||
Variant::DateTime(v) => {
|
||||
writer.write_all(&[5])?;
|
||||
v.serialize(writer)?;
|
||||
}
|
||||
Variant::UInt64(v) => {
|
||||
writer.write_all(&[6])?;
|
||||
v.serialize(writer)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deserialize(reader: &mut dyn Read) -> crate::rmc::structures::Result<Self> {
|
||||
match u8::deserialize(reader)?{
|
||||
0 => Ok(Variant::None),
|
||||
1 => Ok(Variant::SInt64(i64::deserialize(reader)?)),
|
||||
2 => Ok(Variant::Double(f64::deserialize(reader)?)),
|
||||
3 => Ok(Variant::Bool(bool::deserialize(reader)?)),
|
||||
4 => Ok(Variant::String(String::deserialize(reader)?)),
|
||||
5 => Ok(Variant::DateTime(KerberosDateTime::deserialize(reader)?)),
|
||||
6 => Ok(Variant::UInt64(u64::deserialize(reader)?)),
|
||||
v => Err(structures::Error::UnexpectedValue(v as u64))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue