1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use byteorder::{NetworkEndian, WriteBytesExt};
pub trait TcpTag: std::fmt::Debug {
fn id(&self) -> u8;
fn data(&self) -> Vec<u8>;
fn construct(&self) -> Vec<u8> {
let mut buf = vec![self.id()];
buf.extend_from_slice(self.data().as_slice());
let mut vec = vec![];
vec.write_u16::<NetworkEndian>(buf.len() as u16);
vec.extend_from_slice(buf.as_slice());
vec
}
}
#[derive(Debug, Clone)]
pub struct MatchInfo {
pub competition: String,
pub match_type: MatchType,
}
#[derive(Debug, Copy, Clone)]
pub enum MatchType {
None,
Practice,
Qualifications,
Eliminations,
}
#[derive(Debug, Clone)]
pub struct GameData(pub String);
pub struct Joystick {}
#[repr(i8)]
pub enum JoystickType {
Unknown = -1,
XinputUnknown = 0,
XinputGamepad = 1,
XinputWheel = 2,
XinputArcade = 3,
XinputFlightStick = 4,
XinputDancePad = 5,
XinputGuitar = 6,
XinputGuitar2 = 7,
XinputDrumKit = 8,
XinputGuitar3 = 11,
XinputAracadePad = 19,
HIDJoystick = 20,
HIDGamepad = 21,
HIDDriving = 22,
HIDFlight = 23,
HID1stPerson = 24,
}
impl TcpTag for MatchInfo {
fn id(&self) -> u8 {
0x07
}
fn data(&self) -> Vec<u8> {
let mut buf = vec![];
buf.extend_from_slice(self.competition.as_bytes());
buf.push(match self.match_type {
MatchType::None => 0,
MatchType::Practice => 1,
MatchType::Qualifications => 2,
MatchType::Eliminations => 3,
});
buf
}
}
impl TcpTag for GameData {
fn id(&self) -> u8 {
0x0e
}
fn data(&self) -> Vec<u8> {
Vec::from(self.0.as_bytes())
}
}