# HG changeset patch # User alfadur # Date 1531832614 -10800 # Node ID 5359ff75da3a0fdf5557ce7beba8653e10e7fd85 # Parent 8c5dd562c9f7736cbc3eacf2f1d4b080f982b193 indulge clippy diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/protocol/messages.rs --- a/gameServer2/src/protocol/messages.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/protocol/messages.rs Tue Jul 17 16:03:34 2018 +0300 @@ -41,7 +41,7 @@ // in room Part(Option), Cfg(GameCfg), - AddTeam(TeamInfo), + AddTeam(Box), RemoveTeam(String), SetHedgehogsNumber(String, u8), SetTeamColor(String, u8), @@ -245,7 +245,7 @@ } } -fn construct_message(header: &[&str], msg: &Vec) -> String { +fn construct_message(header: &[&str], msg: &[String]) -> String { let mut v: Vec<_> = header.iter().map(|s| *s).collect(); v.extend(msg.iter().map(|s| &s[..])); v.push("\n"); diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/protocol/parser.rs --- a/gameServer2/src/protocol/parser.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/protocol/parser.rs Tue Jul 17 16:03:34 2018 +0300 @@ -149,11 +149,11 @@ flag: a_line >> eol >> difficulty: u8_line >> eol >> hedgehogs: _8_hogs >> - (AddTeam(TeamInfo{ + (AddTeam(Box::new(TeamInfo{ name, color, grave, fort, voice_pack, flag, difficulty, hedgehogs, hedgehogs_number: 0 - }))) + })))) | do_parse!(tag!("HH_NUM") >> eol >> n: a_line >> eol >> c: u8_line >> diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/protocol/test.rs --- a/gameServer2/src/protocol/test.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/protocol/test.rs Tue Jul 17 16:03:34 2018 +0300 @@ -139,7 +139,7 @@ 28 => Stats(), 29 => Part(Option), 30 => Cfg(GameCfg), - 31 => AddTeam(TeamInfo), + 31 => AddTeam(Box), 32 => RemoveTeam(Ascii), 33 => SetHedgehogsNumber(Ascii, u8), 34 => SetTeamColor(Ascii, u8), diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/server/actions.rs --- a/gameServer2/src/server/actions.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/server/actions.rs Tue Jul 17 16:03:34 2018 +0300 @@ -116,7 +116,7 @@ pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) { match action { - Send(msg) => server.send(client_id, msg.destination, msg.message), + Send(msg) => server.send(client_id, &msg.destination, msg.message), ByeClient(msg) => { let room_id; let nick; @@ -126,12 +126,12 @@ nick = c.nick.clone(); } - room_id.map (|id| { + if let Some(id) = room_id{ if id != server.lobby_id { server.react(client_id, vec![ MoveToLobby(format!("quit: {}", msg.clone()))]); } - }); + } server.react(client_id, vec![ LobbyLeft(nick, msg.clone()).send_all().action(), @@ -273,7 +273,7 @@ v.push(ForwardEngineMessage(info.msg_log.clone()) .send_self().action()); - for name in team_names.iter() { + for name in &team_names { v.push(ForwardEngineMessage( vec![to_engine_msg(once(b'G').chain(name.bytes()))]) .send_all().in_room(r.id).action()); @@ -295,7 +295,7 @@ if config { actions.push(ConfigEntry("FULLMAPCONFIG".to_string(), r.map_config()) .send(to).action()); - for cfg in r.game_config().into_iter() { + for cfg in r.game_config() { actions.push(cfg.to_server_msg().send(to).action()); } } @@ -443,7 +443,7 @@ new_id } else { new_id.or_else(|| - room_client_ids.iter().find(|id| **id != client_id).map(|id| *id)) + room_client_ids.iter().find(|id| **id != client_id).cloned()) }; let new_nick = new_id.map(|id| server.clients[id].nick.clone()); @@ -468,7 +468,7 @@ .send_all().in_room(r.id).action()); } } - new_id.map(|id| server.clients[id].set_is_master(true)); + if let Some(id) = new_id { server.clients[id].set_is_master(true) } server.react(client_id, actions); } RemoveTeam(name) => { @@ -572,7 +572,7 @@ actions.push(SendRoomData{ to: c.id, teams: false, config: true, flags: false}); - for name in info.left_teams.iter() { + for name in &info.left_teams { actions.push(TeamRemove(name.clone()) .send(c.id).action()); } diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/server/handlers/common.rs --- a/gameServer2/src/server/handlers/common.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/server/handlers/common.rs Tue Jul 17 16:03:34 2018 +0300 @@ -4,7 +4,7 @@ use rand::{self, Rng, thread_rng}; use server::{actions::Action, server::HWServer}; -pub fn rnd_reply(options: &Vec) -> HWServerMessage { +pub fn rnd_reply(options: &[String]) -> HWServerMessage { let mut rng = thread_rng(); let reply = if options.is_empty() { (*rng.choose(&["heads", "tails"]).unwrap()).to_owned() diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/server/handlers/inroom.rs --- a/gameServer2/src/server/handlers/inroom.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/server/handlers/inroom.rs Tue Jul 17 16:03:34 2018 +0300 @@ -35,8 +35,8 @@ } } -fn by_msg(source: &Vec) -> ByMsg { - ByMsg {messages: &source[..]} +fn by_msg(source: &[u8]) -> ByMsg { + ByMsg {messages: source} } const VALID_MESSAGES: &[u8] = @@ -99,9 +99,10 @@ Part(Some(msg)) => server.react(client_id, vec![ MoveToLobby(format!("part: {}", msg))]), Chat(msg) => { + let actions = { let c = &mut server.clients[client_id]; - let chat_msg = ChatMsg {nick: c.nick.clone(), msg: msg}; + let chat_msg = ChatMsg {nick: c.nick.clone(), msg}; vec![chat_msg.send_all().in_room(room_id).but_self().action()] }; server.react(client_id, actions); @@ -179,7 +180,7 @@ } else if r.is_team_add_restricted() { actions.push(Warn("This room currently does not allow adding new teams.".to_string())); } else { - let team = r.add_team(c.id, info); + let team = r.add_team(c.id, *info); c.teams_in_game += 1; c.clan = Some(team.color); actions.push(TeamAccepted(team.name.clone()) diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/server/network.rs --- a/gameServer2/src/server/network.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/server/network.rs Tue Jul 17 16:03:34 2018 +0300 @@ -105,14 +105,14 @@ } pub fn send_raw_msg(&mut self, msg: &[u8]) { - self.buf_out.write(msg).unwrap(); + self.buf_out.write_all(msg).unwrap(); } - pub fn send_string(&mut self, msg: &String) { + pub fn send_string(&mut self, msg: &str) { self.send_raw_msg(&msg.as_bytes()); } - pub fn send_msg(&mut self, msg: HWServerMessage) { + pub fn send_msg(&mut self, msg: &HWServerMessage) { self.send_string(&msg.to_raw_protocol()); } } @@ -143,7 +143,7 @@ let mut client_exists = false; if let Some(ref client) = self.clients.get(id) { poll.deregister(&client.socket) - .ok().expect("could not deregister socket"); + .expect("could not deregister socket"); info!("client {} ({}) removed", client.id, client.peer_addr); client_exists = true; } @@ -156,7 +156,7 @@ poll.register(&client_socket, Token(id), Ready::readable() | Ready::writable(), PollOpt::edge()) - .ok().expect("could not register socket with event loop"); + .expect("could not register socket with event loop"); let entry = self.clients.vacant_entry(); let client = NetworkClient::new(id, client_socket, addr); @@ -189,7 +189,7 @@ Ok(()) } - fn operation_failed(&mut self, poll: &Poll, client_id: ClientId, error: Error, msg: &str) -> io::Result<()> { + fn operation_failed(&mut self, poll: &Poll, client_id: ClientId, error: &Error, msg: &str) -> io::Result<()> { let addr = if let Some(ref mut client) = self.clients.get_mut(client_id) { client.peer_addr } else { @@ -224,7 +224,7 @@ }; } Err(e) => self.operation_failed( - poll, client_id, e, + poll, client_id, &e, "Error while reading from client socket")? } @@ -256,7 +256,7 @@ }, Ok(_) => {} Err(e) => self.operation_failed( - poll, client_id, e, + poll, client_id, &e, "Error while writing to client socket")? } diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/server/room.rs --- a/gameServer2/src/server/room.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/server/room.rs Tue Jul 17 16:03:34 2018 +0300 @@ -53,7 +53,7 @@ } } -fn client_teams_impl(teams: &Vec<(ClientId, TeamInfo)>, client_id: ClientId) +fn client_teams_impl(teams: &[(ClientId, TeamInfo)], client_id: ClientId) -> impl Iterator + Clone { teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t) diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/server/server.rs --- a/gameServer2/src/server/server.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/server/server.rs Tue Jul 17 16:03:34 2018 +0300 @@ -40,7 +40,7 @@ let client = HWClient::new(entry.key()); entry.insert(client); } - self.send(key, Destination::ToSelf, HWServerMessage::Connected(utils::PROTOCOL_VERSION)); + self.send(key, &Destination::ToSelf, HWServerMessage::Connected(utils::PROTOCOL_VERSION)); key } @@ -64,8 +64,8 @@ } } - fn get_recipients(&self, client_id: ClientId, destination: Destination) -> Vec { - let mut ids = match destination { + fn get_recipients(&self, client_id: ClientId, destination: &Destination) -> Vec { + let mut ids = match *destination { Destination::ToSelf => vec![client_id], Destination::ToId(id) => vec![id], Destination::ToAll {room_id: Some(id), ..} => @@ -83,8 +83,8 @@ ids } - pub fn send(&mut self, client_id: ClientId, destination: Destination, message: HWServerMessage) { - let ids = self.get_recipients(client_id, destination); + pub fn send(&mut self, client_id: ClientId, destination: &Destination, message: HWServerMessage) { + let ids = self.get_recipients(client_id, &destination); self.output.push((ids, message)); } diff -r 8c5dd562c9f7 -r 5359ff75da3a gameServer2/src/utils.rs --- a/gameServer2/src/utils.rs Tue Jul 17 00:27:24 2018 +0300 +++ b/gameServer2/src/utils.rs Tue Jul 17 16:03:34 2018 +0300 @@ -3,7 +3,7 @@ use base64::{encode}; pub const PROTOCOL_VERSION : u32 = 3; -pub const SERVER: mio::Token = mio::Token(1000000000 + 0); +pub const SERVER: mio::Token = mio::Token(1_000_000_000); pub fn is_name_illegal(name: &str ) -> bool{ name.len() > 40 ||