Browse Source

moved padding logic to libpso, changed return type from Box to Result

pbs
andy 5 years ago
parent
commit
e0da49d048
  1. 17
      src/ship/ship.rs

17
src/ship/ship.rs

@ -316,19 +316,14 @@ impl<EG: EntityGateway> ShipServerState<EG> {
}).collect::<Vec<_>>().into_iter())
}
fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
let mut cmsg = PlayerChat::new(0x00010000, client.user.guildcard.unwrap(), msg.message.clone());
let mut mlen = (cmsg.message.len() * 2) + 0x12;
while mlen & 0x07 != 0 {
cmsg.message.push('\0');
mlen += 1;
}
fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)>>, ShipError> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
let cmsg = PlayerChat::new(0x00010000, client.user.guildcard.unwrap(), msg.message.clone());
Box::new(self.client_location.get_area_by_user(id).clients().iter()
Ok(Box::new(self.client_location.get_area_by_user(id).clients().iter()
.map(move |client| {
(client.client_id, SendShipPacket::PlayerChat(cmsg.clone()))
}).collect::<Vec<_>>().into_iter())
}).collect::<Vec<_>>().into_iter()))
}
}
@ -375,7 +370,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
},
RecvShipPacket::PlayerChat(msg) => {
self.player_chat(id, msg)
Box::new(self.player_chat(id, msg)?.into_iter())
},
})
}

Loading…
Cancel
Save