removed these files, ready to start working on event system messages

This commit is contained in:
2025-11-12 15:14:07 +01:00
parent 532c5a42ea
commit 281f496c83
3 changed files with 0 additions and 73 deletions

View File

@@ -1,19 +0,0 @@
use crate::ConnectionMap;
use futures_util::SinkExt;
use tokio_tungstenite::tungstenite::Message as WsMessage;
pub async fn broadcast_message(connections: &ConnectionMap, msg: &WsMessage) {
let mut dead = vec![];
let mut map = connections.lock().await;
for (id, tx) in map.iter_mut() {
if let Err(e) = tx.send(msg.clone()).await {
eprintln!("Failed to send to {id}: {e}");
dead.push(*id);
}
}
for id in dead {
map.remove(&id);
}
}

View File

@@ -1,34 +0,0 @@
use crate::ConnectionMap;
use futures_util::StreamExt;
use tokio_tungstenite::accept_async;
use uuid::Uuid;
use super::broadcast_message::broadcast_message;
pub async fn handle_connection(stream: tokio::net::TcpStream, connections: ConnectionMap) {
let ws_stream = accept_async(stream).await.unwrap();
let (write, mut read) = ws_stream.split();
let id = Uuid::new_v4();
{
let mut map = connections.lock().await;
map.insert(id, write);
}
println!("New connection: {id}");
while let Some(Ok(msg)) = read.next().await {
if msg.is_text() {
println!("Recieved from {id}: {}", msg);
broadcast_message(&connections, &msg).await;
}
}
{
let mut map = connections.lock().await;
map.remove(&id);
}
println!("Connection removed: {id}");
}

View File

@@ -1,20 +0,0 @@
use uuid::Uuid;
struct Step {
from: String,
to: String,
}
enum ServerEvent {
PlayerJoined(Uuid), //tarolja el a kapcsolatot
PlayerLeft(Uuid), //torolje a jatekos a listabol mert kilepett
PlayerJoinedQeue(Uuid), //online jatekra var
PlayerJoinedMatch(Uuid), //player joined a match
PlayerRequestAvailableSteps(Uuid, String), //string board
PlayerSteps(Uuid, Step), //player moves piece
CheckWinner(Uuid, String), //player asks server if they won
PlayerIsInCheck(Uuid, String), //board state
PlayerOpponentUpdateUI(Uuid, String), //board state
PlayerLost(Uuid),
PlayerReturnToMenu(Uuid),
}