Update GameSettings and add GameLinkEvent
This commit is contained in:
@ -107,6 +107,9 @@ fn route_msg(client: &mut Client, str_msg: &String) -> Result<(), ClientError> {
|
|||||||
Inbound::HeartBeatResponse(_) => {
|
Inbound::HeartBeatResponse(_) => {
|
||||||
// do nothing
|
// do nothing
|
||||||
},
|
},
|
||||||
|
Inbound::GameLinkEvent(msg) => {
|
||||||
|
info!(target: LOG_TARGET, "Watch game at {}", msg.url);
|
||||||
|
},
|
||||||
Inbound::UnrecognizedMessage => {
|
Inbound::UnrecognizedMessage => {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -135,7 +138,7 @@ impl ws::Handler for Client {
|
|||||||
if let ws::Message::Text(text) = msg {
|
if let ws::Message::Text(text) = msg {
|
||||||
let route_result = route_msg(self, &text);
|
let route_result = route_msg(self, &text);
|
||||||
match route_result {
|
match route_result {
|
||||||
Err(e) => error!(target: LOG_TARGET, "Got error {} when routing message: {}", e, text),
|
Err(e) => error!(target: LOG_TARGET, "Got error \'{:?}\' when routing message: {}", e, text),
|
||||||
Ok(_) => debug!(target: LOG_TARGET, "Succeeded in routing message {}", text)
|
Ok(_) => debug!(target: LOG_TARGET, "Succeeded in routing message {}", text)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -18,6 +18,8 @@ pub const INVALID_PLAYER_NAME: &'static str =
|
|||||||
"se.cygni.snake.api.exception.InvalidPlayerName";
|
"se.cygni.snake.api.exception.InvalidPlayerName";
|
||||||
pub const HEART_BEAT_RESPONSE: &'static str =
|
pub const HEART_BEAT_RESPONSE: &'static str =
|
||||||
"se.cygni.snake.api.request.HeartBeatResponse";
|
"se.cygni.snake.api.request.HeartBeatResponse";
|
||||||
|
pub const GAME_LINK_EVENT: &'static str =
|
||||||
|
"se.cygni.snake.api.event.GameLinkEvent";
|
||||||
|
|
||||||
// Outbound
|
// Outbound
|
||||||
const REGISTER_PLAYER_MESSAGE_TYPE: &'static str =
|
const REGISTER_PLAYER_MESSAGE_TYPE: &'static str =
|
||||||
@ -38,6 +40,7 @@ pub enum Inbound {
|
|||||||
PlayerRegistered(structs::PlayerRegistered),
|
PlayerRegistered(structs::PlayerRegistered),
|
||||||
InvalidPlayerName(structs::InvalidPlayerName),
|
InvalidPlayerName(structs::InvalidPlayerName),
|
||||||
HeartBeatResponse(structs::HeartBeatResponse),
|
HeartBeatResponse(structs::HeartBeatResponse),
|
||||||
|
GameLinkEvent(structs::GameLink),
|
||||||
UnrecognizedMessage
|
UnrecognizedMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +62,8 @@ pub fn parse_inbound_msg(msg: &String) -> Result<Inbound, Error> {
|
|||||||
Inbound::InvalidPlayerName(try!(from_str(msg)))
|
Inbound::InvalidPlayerName(try!(from_str(msg)))
|
||||||
} else if msg.contains(HEART_BEAT_RESPONSE) {
|
} else if msg.contains(HEART_BEAT_RESPONSE) {
|
||||||
Inbound::HeartBeatResponse(try!(from_str(msg)))
|
Inbound::HeartBeatResponse(try!(from_str(msg)))
|
||||||
|
} else if msg.contains(GAME_LINK_EVENT) {
|
||||||
|
Inbound::GameLinkEvent(try!(from_str(msg)))
|
||||||
} else {
|
} else {
|
||||||
Inbound::UnrecognizedMessage
|
Inbound::UnrecognizedMessage
|
||||||
};
|
};
|
||||||
@ -100,28 +105,21 @@ pub fn create_heart_beat_msg(id: String) -> Result<String, Error> {
|
|||||||
|
|
||||||
pub fn default_gamesettings() -> structs::GameSettings {
|
pub fn default_gamesettings() -> structs::GameSettings {
|
||||||
structs::GameSettings {
|
structs::GameSettings {
|
||||||
width: String::from("MEDIUM"),
|
|
||||||
height: String::from("MEDIUM"),
|
|
||||||
maxNoofPlayers: 5,
|
maxNoofPlayers: 5,
|
||||||
startSnakeLength: 1,
|
startSnakeLength: 1,
|
||||||
timeInMsPerTick: 250,
|
timeInMsPerTick: 250,
|
||||||
obstaclesEnabled: true,
|
obstaclesEnabled: true,
|
||||||
foodEnabled: true,
|
foodEnabled: true,
|
||||||
edgeWrapsAround: false,
|
|
||||||
headToTailConsumes: true,
|
headToTailConsumes: true,
|
||||||
tailConsumeGrows: false,
|
tailConsumeGrows: false,
|
||||||
addFoodLikelihood: 15,
|
addFoodLikelihood: 15,
|
||||||
removeFoodLikelihood: 5,
|
removeFoodLikelihood: 5,
|
||||||
addObstacleLikelihood: 15,
|
|
||||||
removeObstacleLikelihood: 15,
|
|
||||||
spontaneousGrowthEveryNWorldTick: 3,
|
spontaneousGrowthEveryNWorldTick: 3,
|
||||||
trainingGame: false,
|
trainingGame: false,
|
||||||
pointsPerLength: 1,
|
pointsPerLength: 1,
|
||||||
pointsPerFood: 2,
|
pointsPerFood: 2,
|
||||||
pointsPerCausedDeath: 5,
|
pointsPerCausedDeath: 5,
|
||||||
pointsPerNibble: 10,
|
pointsPerNibble: 10,
|
||||||
pointsLastSnakeLiving: 10,
|
|
||||||
noofRoundsTailProtectedAfterNibble: 3,
|
noofRoundsTailProtectedAfterNibble: 3,
|
||||||
pointsSuicide: -10,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,29 +2,22 @@
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct GameSettings {
|
pub struct GameSettings {
|
||||||
pub width: String,
|
|
||||||
pub height: String,
|
|
||||||
pub maxNoofPlayers: u32,
|
pub maxNoofPlayers: u32,
|
||||||
pub startSnakeLength: u32,
|
pub startSnakeLength: u32,
|
||||||
pub timeInMsPerTick: u32,
|
pub timeInMsPerTick: u32,
|
||||||
pub obstaclesEnabled: bool,
|
pub obstaclesEnabled: bool,
|
||||||
pub foodEnabled: bool,
|
pub foodEnabled: bool,
|
||||||
pub edgeWrapsAround: bool,
|
|
||||||
pub headToTailConsumes: bool,
|
pub headToTailConsumes: bool,
|
||||||
pub tailConsumeGrows: bool,
|
pub tailConsumeGrows: bool,
|
||||||
pub addFoodLikelihood: u32,
|
pub addFoodLikelihood: u32,
|
||||||
pub removeFoodLikelihood: u32,
|
pub removeFoodLikelihood: u32,
|
||||||
pub addObstacleLikelihood: u32,
|
|
||||||
pub removeObstacleLikelihood: u32,
|
|
||||||
pub spontaneousGrowthEveryNWorldTick: u32,
|
pub spontaneousGrowthEveryNWorldTick: u32,
|
||||||
pub trainingGame: bool,
|
pub trainingGame: bool,
|
||||||
pub pointsPerLength: u32,
|
pub pointsPerLength: u32,
|
||||||
pub pointsPerFood: u32,
|
pub pointsPerFood: u32,
|
||||||
pub pointsPerCausedDeath: u32,
|
pub pointsPerCausedDeath: u32,
|
||||||
pub pointsPerNibble: u32,
|
pub pointsPerNibble: u32,
|
||||||
pub pointsLastSnakeLiving: u32,
|
|
||||||
pub noofRoundsTailProtectedAfterNibble: u32,
|
pub noofRoundsTailProtectedAfterNibble: u32,
|
||||||
pub pointsSuicide: i32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@ -127,6 +120,15 @@ pub struct HeartBeatResponse {
|
|||||||
pub receivingPlayerId: Option<String>
|
pub receivingPlayerId: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
|
pub struct GameLink {
|
||||||
|
#[serde(rename="type")]
|
||||||
|
pub type_: String,
|
||||||
|
pub receivingPlayerId: String,
|
||||||
|
pub gameId: String,
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct TournamentEnded {
|
pub struct TournamentEnded {
|
||||||
#[serde(rename="type")]
|
#[serde(rename="type")]
|
||||||
|
|||||||
Reference in New Issue
Block a user