-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental tcp stuff. Does not currently work.
- Loading branch information
Showing
6 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,89 @@ | ||
pub mod tcp { | ||
use joystick::{AxisType, JoystickType}; | ||
use states::MatchType; | ||
|
||
pub trait Tag { | ||
fn id(&self) -> u8; | ||
|
||
fn as_bytes(&self) -> Vec<u8>; | ||
|
||
fn to_packet(&self) -> Vec<u8> { | ||
let mut buf = Vec::new(); | ||
buf.push(self.id()); | ||
buf.extend(self.as_bytes()); | ||
let len = buf.len(); | ||
buf.insert(0, len as u8); | ||
|
||
buf | ||
} | ||
} | ||
|
||
pub enum TcpTag { | ||
JoystickDescriptor(JoystickDescriptor), | ||
MatchInfo(MatchInfo), | ||
GameData(GameData), | ||
} | ||
|
||
impl TcpTag { | ||
pub fn to_packet(&self) -> Vec<u8> { | ||
match self { | ||
TcpTag::JoystickDescriptor(jd) => Vec::new(), // TODO | ||
TcpTag::MatchInfo(mi) => mi.to_packet(), | ||
TcpTag::GameData(gd) => gd.to_packet(), | ||
} | ||
} | ||
} | ||
|
||
pub struct JoystickDescriptor { | ||
index: u8, | ||
is_xbox: bool, | ||
stick_type: JoystickType, | ||
name: String, | ||
axis_count: u8, | ||
axis_types: Vec<AxisType>, | ||
button_count: u8, | ||
pov_count: u8, | ||
} | ||
|
||
pub struct MatchInfo { | ||
competition: String, | ||
match_type: MatchType, | ||
} | ||
|
||
impl Tag for MatchInfo { | ||
fn id(&self) -> u8 { | ||
0x07 | ||
} | ||
|
||
fn as_bytes(&self) -> Vec<u8> { | ||
let mut buf = Vec::new(); | ||
buf.extend(self.competition.as_bytes()); | ||
buf.push(self.match_type as u8); | ||
|
||
buf | ||
} | ||
} | ||
|
||
pub struct GameData { | ||
data: String, | ||
} | ||
|
||
impl GameData { | ||
pub fn new(data: String) -> Self { | ||
Self { data } | ||
} | ||
} | ||
|
||
impl Tag for GameData { | ||
fn id(&self) -> u8 { | ||
0x0e | ||
} | ||
|
||
fn as_bytes(&self) -> Vec<u8> { | ||
let mut buf = Vec::new(); | ||
buf.extend(self.data.as_bytes()); | ||
|
||
buf | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ impl Alliance { | |
} | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
pub enum MatchType { | ||
None = 0, | ||
Practice = 1, | ||
|