22 lines
1020 B
Rust
Raw Normal View History

2020-11-21 23:45:27 -07:00
use libpso::packet::ship::*;
use libpso::packet::login::RedirectClient;
use crate::common::serverstate::ClientId;
use crate::common::interserver::Ship;
2021-06-18 11:53:23 -06:00
use crate::ship::ship::{SendShipPacket, ShipError};
2020-11-21 23:45:27 -07:00
use crate::ship::packet::builder;
2022-10-18 04:46:21 -06:00
pub fn ship_list(id: ClientId, ship_list: &[Ship]) -> Vec<(ClientId, SendShipPacket)> {
vec![(id, SendShipPacket::ShipList(builder::ship::ship_list(ship_list)))]
2020-11-21 23:45:27 -07:00
}
2022-10-18 04:46:21 -06:00
pub fn block_list(id: ClientId, shipname: &str, num_blocks: usize) -> Vec<(ClientId, SendShipPacket)> {
vec![(id, SendShipPacket::ShipBlockList(ShipBlockList::new(shipname, num_blocks)))]
2020-11-21 23:45:27 -07:00
}
2022-10-18 04:46:21 -06:00
pub fn selected_ship(id: ClientId, menuselect: MenuSelect, ship_list: &[Ship])
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
2022-10-18 17:55:47 -06:00
let ship = ship_list.get(menuselect.item as usize).ok_or_else(|| ShipError::InvalidShip(menuselect.item as usize))?;
2020-11-21 23:45:27 -07:00
let ip = u32::from_ne_bytes(ship.ip.octets());
2022-10-18 04:46:21 -06:00
Ok(vec![(id, SendShipPacket::RedirectClient(RedirectClient::new(ip, ship.port)))])
2020-11-21 23:45:27 -07:00
}