Send ClientInfo to the server
This commit is contained in:
12
src/main.rs
12
src/main.rs
@ -7,6 +7,8 @@ extern crate serde;
|
||||
#[macro_use] extern crate quick_error;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate log4rs;
|
||||
extern crate target_info;
|
||||
extern crate rustc_version;
|
||||
|
||||
mod structs;
|
||||
mod messages;
|
||||
@ -123,8 +125,16 @@ impl ws::Handler for Client {
|
||||
fn on_open(&mut self, _: ws::Handshake) -> ws::Result<()> {
|
||||
debug!(target: LOG_TARGET, "Connection to Websocket opened");
|
||||
|
||||
let parse_msg = messages::create_play_registration_msg(self.snake.get_name());
|
||||
let client_info = messages::create_client_info_msg();
|
||||
if let Ok(message) = client_info {
|
||||
info!(target: LOG_TARGET, "Sending client info to server: {:?}", message);
|
||||
try!(self.out.send(message));
|
||||
} else {
|
||||
error!(target: LOG_TARGET, "Unable to create client info message {:?}", client_info);
|
||||
try!(self.out.close(ws::CloseCode::Error));
|
||||
}
|
||||
|
||||
let parse_msg = messages::create_play_registration_msg(self.snake.get_name());
|
||||
if let Ok(response) = parse_msg {
|
||||
info!(target: LOG_TARGET, "Registering player with message: {:?}", response);
|
||||
self.out.send(response)
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
use structs;
|
||||
use serde_json::{ from_str, to_string, Error };
|
||||
use target_info::Target;
|
||||
use rustc_version;
|
||||
|
||||
// Inbound
|
||||
pub const GAME_ENDED: &'static str =
|
||||
@ -30,6 +32,8 @@ const REGISTER_MOVE: &'static str =
|
||||
"se.cygni.snake.api.request.RegisterMove";
|
||||
const HEART_BEAT_REQUEST: &'static str =
|
||||
"se.cygni.snake.api.request.HeartBeatRequest";
|
||||
const CLIENT_INFO: &'static str =
|
||||
"se.cygni.snake.api.request.ClientInfo";
|
||||
|
||||
pub enum Inbound {
|
||||
GameEnded(structs::GameEnded),
|
||||
@ -103,6 +107,17 @@ pub fn create_heart_beat_msg(id: String) -> Result<String, Error> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_client_info_msg() -> Result<String, Error> {
|
||||
to_string(&structs::ClientInfo {
|
||||
type_: String::from(CLIENT_INFO),
|
||||
language: String::from("rust"),
|
||||
languageVersion: format!("{}", rustc_version::version()),
|
||||
operatingSystem: String::from(Target::os()),
|
||||
operatingSystemVersion: String::from(""),
|
||||
clientVersion: String::from(option_env!("CARGO_PKG_VERSION").unwrap_or(""))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn default_gamesettings() -> structs::GameSettings {
|
||||
structs::GameSettings {
|
||||
maxNoofPlayers: 5,
|
||||
|
||||
@ -3,7 +3,7 @@ use maputil::{ Direction };
|
||||
use util::{ translate_positions };
|
||||
|
||||
const LOG_TARGET: &'static str = "snake";
|
||||
pub const TRAINING_VENUE: &'static str = "tournament";
|
||||
pub const TRAINING_VENUE: &'static str = "training";
|
||||
|
||||
pub struct Snake;
|
||||
|
||||
|
||||
@ -28,6 +28,17 @@ pub struct PlayRegistration {
|
||||
pub gameSettings: GameSettings,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ClientInfo {
|
||||
#[serde(rename="type")]
|
||||
pub type_: String,
|
||||
pub language: String,
|
||||
pub languageVersion: String,
|
||||
pub operatingSystem: String,
|
||||
pub operatingSystemVersion: String,
|
||||
pub clientVersion: String
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct RegisterMove {
|
||||
#[serde(rename="type")]
|
||||
|
||||
Reference in New Issue
Block a user