|
|
@ -47,15 +47,15 @@ impl MessageResponseData {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn to_response(self) -> MessageResponse {
|
|
|
|
fn into_response(self) -> MessageResponse {
|
|
|
|
MessageResponse {
|
|
|
|
MessageResponse {
|
|
|
|
event: self.get_name(),
|
|
|
|
event: self.get_name(),
|
|
|
|
data: self,
|
|
|
|
data: self,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn to_message(self) -> Message {
|
|
|
|
fn into_message(self) -> Message {
|
|
|
|
self.to_response().to_message()
|
|
|
|
self.into_response().to_message()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -89,7 +89,7 @@ impl Server {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn broadcast_player_count(&self) {
|
|
|
|
fn broadcast_player_count(&self) {
|
|
|
|
let response = MessageResponseData::PlayerCount { players: self.clients.len() as u64 }.to_response();
|
|
|
|
let response = MessageResponseData::PlayerCount { players: self.clients.len() as u64 }.into_response();
|
|
|
|
for (_client, responder) in self.clients.iter() {
|
|
|
|
for (_client, responder) in self.clients.iter() {
|
|
|
|
responder.send(response.to_message());
|
|
|
|
responder.send(response.to_message());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -97,7 +97,7 @@ impl Server {
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_connection(&mut self, client_id: u64, responder: Responder) {
|
|
|
|
fn handle_connection(&mut self, client_id: u64, responder: Responder) {
|
|
|
|
println!("A client connected with id #{}", client_id);
|
|
|
|
println!("A client connected with id #{}", client_id);
|
|
|
|
responder.send(MessageResponseData::Greeting { id: client_id }.to_message());
|
|
|
|
responder.send(MessageResponseData::Greeting { id: client_id }.into_message());
|
|
|
|
if let Some(ref last_response) = self.last_response {
|
|
|
|
if let Some(ref last_response) = self.last_response {
|
|
|
|
responder.send(last_response.to_message());
|
|
|
|
responder.send(last_response.to_message());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -160,7 +160,7 @@ impl Server {
|
|
|
|
message: String::from("Not in dictionary!"),
|
|
|
|
message: String::from("Not in dictionary!"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.to_response();
|
|
|
|
}.into_response();
|
|
|
|
|
|
|
|
|
|
|
|
match response.data {
|
|
|
|
match response.data {
|
|
|
|
// Send errors to only this client
|
|
|
|
// Send errors to only this client
|
|
|
|