// Copyright 2022-2024 Gabriel Bjørnager Jensen. use crate::{Client, ServerConnection}; use bowshock::net::{Request, Response, DEFAULT_SERVER_PORT}; use bzipper::FixedString; impl Client { pub fn run(self) -> Result<(), i32> { let server_addr = format!("127.0.0.1:{DEFAULT_SERVER_PORT}"); eprintln!("connecting to server at {server_addr}"); let mut connection = ServerConnection::new(server_addr); let mut request = Request::Ping; connection.send_request(&request); let mut response = connection.recieve_response(); eprintln!("got response {response:?}"); request = Request::Join { username: FixedString::try_from("delta").unwrap() }; connection.send_request(&request); response = connection.recieve_response(); eprintln!("got response {response:?}"); let Response::JoinAccepted { token } = response else { eprintln!("expected approved join :("); return Err(0x1); }; request = Request::Quit { token }; connection.send_request(&request); Ok(()) } }