diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-08 13:31:18 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-08 13:31:18 +0200 |
commit | cd255848196da0d8732d31049cc0f98388205a30 (patch) | |
tree | 3813003cc153210d24a7819c0dce8d68b26867a2 /server | |
parent | 88241946e3144fede5c86f98d00bb723c1cc2761 (diff) | |
download | keks-meet-cd255848196da0d8732d31049cc0f98388205a30.tar keks-meet-cd255848196da0d8732d31049cc0f98388205a30.tar.bz2 keks-meet-cd255848196da0d8732d31049cc0f98388205a30.tar.zst |
more code
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main.rs | 35 | ||||
-rw-r--r-- | server/src/protocol.rs | 1 | ||||
-rw-r--r-- | server/src/room.rs | 1 |
3 files changed, 24 insertions, 13 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index b4121b9..6a8f11d 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -12,29 +12,38 @@ use warp::hyper::Server; use warp::ws::WebSocket; use warp::{Filter, Rejection, Reply}; -type Rooms = Arc<CHashMap<String, Room>>; +type Rooms = Arc<CHashMap<String, Arc<Room>>>; -#[tokio::main] -async fn main() { +fn main() { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(run()); +} + +async fn run() { env_logger::init_from_env("LOG"); let rooms = Rooms::default(); let rooms = warp::any().map(move || rooms.clone()); - let signaling = warp::path("signaling") - .and(warp::path::param::<String>()) + let app = warp::path!(String) + .map(|_| ()) + .untuple_one() + .and(warp::fs::file("../client-web/public/app.html")); + let signaling = warp::path!(String / "signaling") .and(rooms) .and(warp::ws()) .map(signaling_connect); - let static_routes = { - let index = warp::path::end().and(warp::fs::file("../client-web/public/start.html")); - let assets = warp::path("_assets").and(warp::fs::dir("../client-web/public/assets")); - - warp::get().and(index.or(assets)) - }; + let index = warp::path!().and(warp::fs::file("../client-web/public/start.html")); + let assets = warp::path("_assets").and(warp::fs::dir("../client-web/public/assets")); - let routes = static_routes.or(signaling).recover(handle_rejection); + let routes = warp::get() + .and(assets.or(app).or(index).or(signaling)) + .recover(handle_rejection) + .with(warp::log("stuff")); // if listender fd is passed from the outside world, use it. let mut listenfd = ListenFd::from_env(); @@ -76,7 +85,7 @@ fn signaling_connect(rname: String, rooms: Rooms, ws: warp::ws::Ws) -> impl Repl let room = match rooms.get(&rname) { Some(r) => r, None => { - rooms.insert(rname.to_owned(), Room::default()); + rooms.insert(rname.to_owned(), Default::default()); rooms.get(&rname).unwrap() // TODO never expect this to always work!! } }; diff --git a/server/src/protocol.rs b/server/src/protocol.rs index 780ae4a..f480ce7 100644 --- a/server/src/protocol.rs +++ b/server/src/protocol.rs @@ -23,6 +23,7 @@ pub enum ClientboundPacket { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum ServerboundPacket { + Ping, Relay { recipient: Option<usize>, message: RelayMessage, diff --git a/server/src/room.rs b/server/src/room.rs index 43cfa90..a47d2e5 100644 --- a/server/src/room.rs +++ b/server/src/room.rs @@ -86,6 +86,7 @@ impl Room { pub async fn client_message(&self, sender: usize, packet: ServerboundPacket) { match packet { + ServerboundPacket::Ping => (), ServerboundPacket::Relay { recipient, message } => { if let Some(recipient) = recipient { self.send_to_client(recipient, ClientboundPacket::Message { sender, message }) |