~starkingdoms/starkingdoms

ref: 6d234cf18d7b6def2bffd0418685f3de50cdf677 starkingdoms/server/src/handler.rs -rw-r--r-- 684 bytes
6d234cf1 — ghostlyzsh haha oops apparently didnt add files (silly me) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::collections::HashMap;

use std::net::SocketAddr;
use std::sync::Arc;

use tokio::sync::mpsc::Sender;
use tokio::sync::RwLock;



#[derive(Clone)]
pub struct ClientManager {
    pub handlers: Arc<RwLock<HashMap<SocketAddr, ClientHandler>>>,
    pub usernames: Arc<RwLock<HashMap<SocketAddr, String>>>,
    pub players: Arc<RwLock<HashMap<SocketAddr, Player>>>
}

#[derive(Default)]
pub struct Player {
    pub id: u16,
    pub x: f64,
    pub y: f64,
    pub vel_x: f64,
    pub vel_y: f64,
}

#[derive(Clone)]
pub struct ClientHandler {
    pub tx: Sender<ClientHandlerMessage>
}

pub enum ClientHandlerMessage {
    Tick,
    ChatMessage { from: String, message: String }
}