idk girl this is strange
This commit is contained in:
parent
abfc03434c
commit
f66600cabc
5 changed files with 22 additions and 8 deletions
|
@ -2,13 +2,13 @@ use std::fmt::Display;
|
|||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Clone)]
|
||||
pub struct Card {
|
||||
pub suit: Suit,
|
||||
pub value: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
pub enum Suit {
|
||||
Hearts,
|
||||
Diamonds,
|
||||
|
|
|
@ -4,6 +4,7 @@ use rand::rng;
|
|||
use crate::card::Card;
|
||||
use crate::card::Suit;
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub struct Deck {
|
||||
pub deck: Vec<Card>,
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{deck::Deck, player::Player};
|
||||
use petname::Generator;
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone)]
|
||||
pub struct Lobby {
|
||||
pub id: String,
|
||||
pub players: Vec<Player>,
|
||||
|
@ -32,4 +33,8 @@ impl Lobby {
|
|||
pub fn get_deck(self) -> Deck {
|
||||
self.deck
|
||||
}
|
||||
|
||||
pub fn get_id(&self) -> String {
|
||||
self.id.clone()
|
||||
}
|
||||
}
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -1,3 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::io::{self, Error};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
|
@ -50,15 +51,22 @@ async fn main() -> io::Result<()> {
|
|||
let address = "127.0.0.1:8080".to_string();
|
||||
let listener = TcpListener::bind(&address).await?;
|
||||
|
||||
let mut lobbies: Vec<Lobby> = Vec::new();
|
||||
let mut lobbies: HashMap<String, Lobby> = HashMap::new();
|
||||
|
||||
loop {
|
||||
let (mut stream, addr) = listener.accept().await?;
|
||||
|
||||
tokio::spawn(async move {
|
||||
println!("new connection from: {}", addr);
|
||||
let (player, lobby) = handle_connection(stream, addr).await;
|
||||
});
|
||||
println!("new connection from: {}", addr);
|
||||
|
||||
let lobby_player_handle = tokio::spawn(handle_connection(stream, addr));
|
||||
|
||||
let (player, lobby) = lobby_player_handle.await?;
|
||||
|
||||
match lobby {
|
||||
Some(lobby) => lobbies.insert(lobby.get_id(), lobby),
|
||||
None => continue,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -4,7 +4,7 @@ use sha256::digest;
|
|||
|
||||
use crate::card::Card;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash, Clone)]
|
||||
pub struct Player {
|
||||
// addr will change because at this stage i really
|
||||
// don't know what i am doing
|
||||
|
|
Loading…
Add table
Reference in a new issue