|
@@ -7,6 +7,7 @@ use actix::prelude::*;
|
|
|
use actix_web::{web, Error, HttpRequest, HttpResponse};
|
|
|
use actix_web_actors::ws;
|
|
|
use crate::game;
|
|
|
+use crate::websocket;
|
|
|
use crate::websocket::*;
|
|
|
|
|
|
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
|
@@ -16,12 +17,15 @@ const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
|
|
#[rtype(result = "Answer")]
|
|
|
struct JoinRequest{ lobby_id: String, nick: String, p: Addr<GameConnection> }
|
|
|
|
|
|
-
|
|
|
#[derive(Message)]
|
|
|
#[rtype(result = "Answer")]
|
|
|
struct CreateLobbyRequest{ lobby_id: String, p: Addr<GameConnection> }
|
|
|
|
|
|
#[derive(Message)]
|
|
|
+#[rtype(result = "()")]
|
|
|
+struct SubmitWordMsg{ word: String, nick: String }
|
|
|
+
|
|
|
+#[derive(Message)]
|
|
|
#[rtype(result = "Result<game::Game, ()>")]
|
|
|
struct GetGame;
|
|
|
|
|
@@ -132,6 +136,13 @@ impl Handler<GetGame> for GameLobby {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+impl Handler<SubmitWordMsg> for GameLobby {
|
|
|
+ type Result = ();
|
|
|
+ fn handle(&mut self, swm: SubmitWordMsg, ctx: &mut Self::Context) -> Self::Result {
|
|
|
+ self.game.submit_creation(&swm.nick, swm.word);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl GameLobby {
|
|
|
pub fn new(gi: String) -> Self {
|
|
|
GameLobby {
|
|
@@ -150,7 +161,7 @@ impl GameLobby {
|
|
|
|
|
|
pub fn create_opaque_message(&self, nick: &str) -> GameData {
|
|
|
GameData {
|
|
|
- players: self.game.players.iter().map(|p| p.nick.clone()).collect::<Vec<_>>(),
|
|
|
+ players: self.game.players.iter().map(|p| websocket::PlayerData{ nick: p.nick.clone(), points: 0 }).collect::<Vec<_>>(),
|
|
|
state_data: GameStateData::Creating{ available_chars: vec!['a', 'b', 'c'] }
|
|
|
}
|
|
|
}
|
|
@@ -278,6 +289,16 @@ impl GameConnection {
|
|
|
}
|
|
|
}*/
|
|
|
},
|
|
|
+ ClientMessage::SubmitWord{ word } => {
|
|
|
+ if let Some(lobby) = &self.game_lobby {
|
|
|
+ if let Some(nick) = &self.nick {
|
|
|
+ lobby.do_send(SubmitWordMsg{ word: word, nick: nick.clone() });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ClientMessage::SubmitGuess{ guesses } => {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else {
|