summaryrefslogtreecommitdiff
path: root/server/examples/client.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-16 23:10:05 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-16 23:10:05 +0200
commitc10d66de1bd2ef04e4010223dcd82443a5d558f0 (patch)
tree300283fd71569b8d8375001657795b4c4293d0aa /server/examples/client.rs
parentf21cccf9f381bd52dffbd3a9e6822300d5525897 (diff)
downloadhurrycurry-c10d66de1bd2ef04e4010223dcd82443a5d558f0.tar
hurrycurry-c10d66de1bd2ef04e4010223dcd82443a5d558f0.tar.bz2
hurrycurry-c10d66de1bd2ef04e4010223dcd82443a5d558f0.tar.zst
a
Diffstat (limited to 'server/examples/client.rs')
-rw-r--r--server/examples/client.rs52
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();
+ }
+}