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