From 318c108f141bbe37bb4fd74d44c96840ecdd1fb5 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 13 Oct 2019 13:11:52 -0700 Subject: [PATCH] store ship list in serverstate --- src/login/character.rs | 46 ++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/login/character.rs b/src/login/character.rs index 2476db2..74f6f0b 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -145,23 +145,47 @@ impl ClientState { } } +struct Ship { + flags: u32, + name: String, + ip: [u8; 4], + port: u16, +} + +impl Ship { + fn new(name: &str, ip: [u8; 4], port: u16) -> Ship { + Ship { + flags: 0, + name: name.to_owned(), + ip: ip, + port: port, + } + } +} + pub struct CharacterServerState { entity_gateway: EG, param_header: ParamDataHeader, param_data: Vec, clients: HashMap, + ships: Vec, } impl CharacterServerState { pub fn new(entity_gateway: EG) -> CharacterServerState { let (param_header, param_data) = generate_param_data("param/"); + let ships = vec![Ship::new("Sona-Nyl", [127,0,0,1], 23423), + Ship::new("Dylath-Leen", [127,0,0,1], 23424), + Ship::new("Thalarion", [127,0,0,1], 23425), + ]; CharacterServerState { //shared_state: shared_state, entity_gateway: entity_gateway, param_header: param_header, param_data: param_data, clients: HashMap::new(), + ships: ships, } } @@ -184,28 +208,16 @@ impl CharacterServerState { fn send_ship_list(&mut self, _id: ClientId, _pkt: &Login) -> Result, CharacterError> { Ok(vec![SendCharacterPacket::Timestamp(Timestamp::new(chrono::Utc::now())), - SendCharacterPacket::ShipList(ShipList { + SendCharacterPacket::ShipList(ShipList { flag: 0, - ships: vec![ - ShipListEntry { - menu: 0, - item: 1, - flags: 0, - name: utf8_to_utf16_array!("Sona-Nyl", 0x11), - }, - ShipListEntry { - menu: 0, - item: 2, - flags: 0, - name: utf8_to_utf16_array!("Dylath-Leen", 0x11), - }, + ships: self.ships.iter().enumerate().map(|(i, s)| { ShipListEntry { menu: 0, - item: 2, + item: i as u32, flags: 0, - name: utf8_to_utf16_array!("Innsmouth", 0x11), + name: utf8_to_utf16_array!(s.name, 0x11) } - ] + }).collect() })]) }