diff options
author | stale <redkugelblitzin@gmail.com> | 2022-05-11 10:02:10 -0300 |
---|---|---|
committer | stale <redkugelblitzin@gmail.com> | 2022-05-11 10:02:10 -0300 |
commit | cedcb4049a5dd690b9617d34b99f25feb0095c7a (patch) | |
tree | b2e9f8edcff11721d52595df723594fb2cc65cdc /src/conn.rs | |
parent | 8d02c5653079039bf748e1d0748d220cf933b725 (diff) |
more fixes
Diffstat (limited to 'src/conn.rs')
-rw-r--r-- | src/conn.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/conn.rs b/src/conn.rs index fda3a2b..de0f704 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -47,17 +47,17 @@ pub async fn peer_connection(socket: warp::ws::WebSocket, conndata: ConnData) { "pos" => { match parse_pos(fields) { Some(pos) => { - let (name, id) = { + let (name, clr, id) = { let mut peers = peers.write().await; let mut entry = peers.get_mut(&addr).unwrap(); entry.position = pos.clone(); - (entry.name.clone(), entry.seq_id) + (entry.name.clone(), entry.clr.clone(), entry.seq_id) }; let sanitized_name = name.replace(" ", " ").to_string(); { let peers = peers.read().await; for peer_tx in peers.iter().filter(|(s, _)| **s != addr).map(|(_,p)| &p.tx) { - let r = peer_tx.send(Message::text(format!("pos {id} {sanitized_name} {} {}", pos.0, pos.1))); + let r = peer_tx.send(Message::text(format!("pos {id} {sanitized_name} {} {} {}", clr, pos.0, pos.1))); if let Err(e) = r { println!("error sending pos update: {e}"); } @@ -102,12 +102,16 @@ pub async fn peer_connection(socket: warp::ws::WebSocket, conndata: ConnData) { } }, "register" => { - let name = fields.collect::<Vec<&str>>().join(&" "); + let all_fields = fields.collect::<Vec<&str>>(); + let fcount = all_fields.len(); + peer_name = "anon".into(); let id; - if name.is_empty() { - peer_name = "anon".to_string(); - } else { - peer_name = name; + if fcount >= 2 { + peer_name = all_fields[..fcount-1].join(" "); + } + let mut clr = all_fields[fcount-1].chars().filter(|c| c.is_digit(16) || *c == '#').collect::<String>(); + if clr.is_empty() { + clr = "#f03333".into(); } { // new scope cuz paranoid bout deadlocks let mut peers = peers.write().await; @@ -116,10 +120,11 @@ pub async fn peer_connection(socket: warp::ws::WebSocket, conndata: ConnData) { tx: tx.clone(), seq_id: id, name: peer_name.clone(), + clr, position: (0,0) }); } - tx.send(Message::text(format!("id {id}"))).unwrap(); + tx.send(Message::text(format!("id {}", id))).unwrap(); if let Err(e) = cmd_tx.send(MetaMove::Dump) { println!("couldn't send game dump to \"{peer_name}\"@{addr}: {e}"); } |