~starkingdoms/starkingdoms

0a75df36c49fdefd362a84383756b520ade1ad58 — core 2 years ago eb15b74
fixup
3 files changed, 8 insertions(+), 11 deletions(-)

M client/src/chat.rs
M server/src/macros.rs
M server/src/main.rs
M client/src/chat.rs => client/src/chat.rs +2 -0
@@ 4,6 4,8 @@ use crate::CLIENT;
use futures::SinkExt;

#[wasm_bindgen]
// TODO: Switch to async-aware mutexes
#[allow(clippy::await_holding_lock)]
pub async fn send_chat(message: &str) -> Result<(), JsError> {
    let client_data = &mut CLIENT.write()?.client_data;


M server/src/macros.rs => server/src/macros.rs +0 -5
@@ 1,9 1,4 @@


use futures::{FutureExt, StreamExt};

use serde::{Serialize};

use tungstenite::Message;

#[macro_export]

M server/src/main.rs => server/src/main.rs +6 -6
@@ 28,7 28,7 @@ async fn handle_request(mut request: Request<Body>, remote_addr: SocketAddr, mgr
            info!("received connection from {}", remote_addr);
            //assume request is a handshake, so create the handshake response
            let response =
                match handshake::server::create_response_with_body(&request, || Body::empty()) {
                match handshake::server::create_response_with_body(&request, Body::empty) {
                    Ok(response) => {
                        //in case the handshake response creation succeeds,
                        //spawn a task to handle the websocket connection


@@ 105,12 105,12 @@ async fn handle_request(mut request: Request<Body>, remote_addr: SocketAddr, mgr
                        number: env!("STK_VERSION").to_string(), // Set by build.rs
                        protocol: PROTOCOL_VERSION,
                    },
                    players: cmgr.usernames.read().await.len() as u32,
                    players: CMGR.usernames.read().await.len() as u32,
                    description: env!("STK_SLP_DESCRIPTION").to_string(),
                }).unwrap()
            )).unwrap())
        },
        (_url@_, false) => {
        (_url, false) => {
            // typical HTTP file request
            // TODO
            Ok(Response::new(Body::empty()))


@@ 123,7 123,7 @@ async fn handle_request(mut request: Request<Body>, remote_addr: SocketAddr, mgr
}

lazy_static! {
    static ref cmgr: ClientManager = ClientManager {
    static ref CMGR: ClientManager = ClientManager {
        handlers: Arc::new(RwLock::new(Default::default())),
        usernames: Arc::new(RwLock::new(Default::default())),
    };


@@ 143,13 143,13 @@ async fn main() {
        async move {
            Ok::<_, Infallible>(service_fn({
                move |request: Request<Body>| {
                    handle_request(request, remote_addr, cmgr.clone())
                    handle_request(request, remote_addr, CMGR.clone())
                }
            }))
        }
    });

    let mgr_timer = cmgr.clone();
    let mgr_timer = CMGR.clone();
    let _timer_thread = tokio::spawn(async move {
        timer_main(mgr_timer).await;
    });