2020-11-21 23:45:27 -07:00

24 lines
1.2 KiB
Rust

use libpso::packet::ship::*;
use libpso::packet::login::RedirectClient;
use crate::common::serverstate::ClientId;
use crate::common::interserver::Ship;
use crate::ship::ship::{SendShipPacket, ShipError, Clients};
use crate::ship::packet::builder;
pub fn ship_list(id: ClientId, ship_list: &Vec<Ship>)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
Box::new(vec![(id, SendShipPacket::ShipList(builder::ship::ship_list(ship_list)))].into_iter())
}
pub fn block_list(id: ClientId, shipname: &str, num_blocks: usize)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
Box::new(vec![(id, SendShipPacket::ShipBlockList(ShipBlockList::new(shipname, num_blocks)))].into_iter())
}
pub fn selected_ship(id: ClientId, menuselect: &MenuSelect, ship_list: &Vec<Ship>)
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
let ship = ship_list.get(menuselect.item as usize).ok_or(ShipError::InvalidShip(menuselect.item as usize))?;
let ip = u32::from_ne_bytes(ship.ip.octets());
Ok(Box::new(vec![(id, SendShipPacket::RedirectClient(RedirectClient::new(ip, ship.port)))].into_iter()))
}