diff options
Diffstat (limited to 'server/examples')
-rw-r--r-- | server/examples/client.rs | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/server/examples/client.rs b/server/examples/client.rs index 69c50eaa..02c9c9e3 100644 --- a/server/examples/client.rs +++ b/server/examples/client.rs @@ -1,6 +1,52 @@ -fn main() { +use std::{ + io::{stdin, BufRead, BufReader, Write}, + net::TcpStream, + thread, +}; + +use glam::Vec2; +use undercooked::protocol::{PacketC, PacketS}; - +fn main() { + let mut sock = TcpStream::connect("127.0.0.1:27031").unwrap(); + let sock2 = BufReader::new(sock.try_clone().unwrap()); + thread::spawn(move || { + for line in sock2.lines() { + let line = line.unwrap(); + let packet: PacketC = serde_json::from_str(&line).unwrap(); + eprintln!("{packet:?}") + } + }); -}
\ No newline at end of file + for line in stdin().lines() { + let line = line.unwrap(); + let mut toks = line.split(" "); + let packet = match toks.next().unwrap() { + "j" => PacketS::Join { + name: "test".to_string(), + }, + "p" => PacketS::Position { + pos: Vec2::new( + toks.next().unwrap().parse().unwrap(), + toks.next().unwrap().parse().unwrap(), + ), + rot: 0., + }, + "i" => PacketS::Position { + pos: Vec2::new( + toks.next().unwrap().parse().unwrap(), + toks.next().unwrap().parse().unwrap(), + ), + rot: toks.next().unwrap_or("0").parse().unwrap(), + }, + _ => { + println!("unknown"); + continue; + } + }; + sock.write_all(serde_json::to_string(&packet).unwrap().as_bytes()) + .unwrap(); + sock.write_all(b"\n").unwrap(); + } +} |