~starkingdoms/starkingdoms

6d234cf18d7b6def2bffd0418685f3de50cdf677 — ghostlyzsh 2 years ago 22dfe0e
haha oops apparently didnt add files (silly me)
M protocol/src/lib.rs => protocol/src/lib.rs +8 -3
@@ 24,7 24,7 @@ pub enum MessageC2S {
        message: String
    },

    Ping {}
    Ping {},
}

#[derive(Serialize, Deserialize, Debug, Clone)]


@@ 44,7 44,12 @@ pub enum MessageS2C {
        message: String
    },

    Pong {}
    Pong {},

    Position {
        x: f64,
        y: f64,
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]


@@ 62,4 67,4 @@ pub fn pc2s(pkt: &MessageC2S) -> Vec<u8> {
}
pub fn ps2c(pkt: &MessageS2C) -> Vec<u8> {
    rmp_serde::to_vec(pkt).unwrap()
}
\ No newline at end of file
}

M server/src/handler.rs => server/src/handler.rs +12 -2
@@ 11,7 11,17 @@ use tokio::sync::RwLock;
#[derive(Clone)]
pub struct ClientManager {
    pub handlers: Arc<RwLock<HashMap<SocketAddr, ClientHandler>>>,
    pub usernames: Arc<RwLock<HashMap<SocketAddr, String>>>
    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)]


@@ 22,4 32,4 @@ pub struct ClientHandler {
pub enum ClientHandlerMessage {
    Tick,
    ChatMessage { from: String, message: String }
}
\ No newline at end of file
}

M server/src/main.rs => server/src/main.rs +2 -1
@@ 126,6 126,7 @@ lazy_static! {
    static ref CMGR: ClientManager = ClientManager {
        handlers: Arc::new(RwLock::new(Default::default())),
        usernames: Arc::new(RwLock::new(Default::default())),
        players: Arc::new(RwLock::new(Default::default())),
    };
}



@@ 173,4 174,4 @@ pub struct ServerPingResponseVersion {
    pub name: String,
    pub number: String,
    pub protocol: u32
}
\ No newline at end of file
}

M server/src/timer.rs => server/src/timer.rs +3 -1
@@ 9,6 9,8 @@ pub async fn timer_main(mgr: ClientManager) {
    loop {
        sleep(Duration::from_millis(5)).await;



        for (_addr, client_thread) in mgr.handlers.read().await.iter() {
            match client_thread.tx.send(ClientHandlerMessage::Tick).await {
                Ok(_) => (),


@@ 18,4 20,4 @@ pub async fn timer_main(mgr: ClientManager) {
            }
        }
    }
}
\ No newline at end of file
}

A web/static/img/spritesheet-512.png => web/static/img/spritesheet-512.png +0 -0