You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

914 lines
42 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
2 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
2 years ago
5 years ago
2 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
2 years ago
2 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
2 years ago
2 years ago
5 years ago
3 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
2 years ago
2 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
  1. #![allow(dead_code, unused_must_use)]
  2. use std::net::Ipv4Addr;
  3. use std::collections::HashMap;
  4. use async_std::channel;
  5. use async_std::sync::{Arc, Mutex, RwLock};
  6. use rand::Rng;
  7. use thiserror::Error;
  8. use libpso::packet::ship::*;
  9. use libpso::packet::login::{RedirectClient, Login, LoginResponse, ShipList};
  10. use libpso::packet::messages::*;
  11. use libpso::{PacketParseError, PSOPacket};
  12. use libpso::crypto::bb::PSOBBCipher;
  13. use libpso::packet::ship::{BLOCK_MENU_ID, ROOM_MENU_ID};
  14. use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY};
  15. use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
  16. use crate::common::interserver::{AuthToken, Ship, ServerId, InterserverActor, LoginMessage, ShipMessage};
  17. use crate::login::character::SHIP_MENU_ID;
  18. use crate::entity::gateway::{EntityGateway, GatewayError};
  19. use crate::entity::character::SectionID;
  20. use crate::ship::location::{ClientLocation, RoomLobby, ClientLocationError, RoomId};
  21. use crate::ship::drops::DropTable;
  22. use crate::ship::items;
  23. use crate::ship::room;
  24. use crate::ship::map::{Maps, MapsError, MapAreaError, generate_free_roam_maps};
  25. use crate::ship::packet::handler;
  26. use crate::ship::shops::{WeaponShop, ToolShop, ArmorShop};
  27. use crate::ship::trade::TradeState;
  28. // TODO: remove once stuff settles down
  29. pub use crate::ship::client::*;
  30. pub const SHIP_PORT: u16 = 23423;
  31. pub const QUEST_CATEGORY_MENU_ID: u32 = 0xA2;
  32. pub const QUEST_SELECT_MENU_ID: u32 = 0xA3;
  33. #[derive(Clone, Copy)]
  34. pub enum ShipEvent {
  35. None,
  36. Christmas,
  37. Valentines,
  38. Easter,
  39. Halloween,
  40. Sonic,
  41. NewYear,
  42. Summer,
  43. White,
  44. Wedding,
  45. Fall,
  46. Spring,
  47. Summer2,
  48. Spring2,
  49. }
  50. impl From<ShipEvent> for u32 {
  51. fn from(other: ShipEvent) -> u32 {
  52. u16::from(other) as u32
  53. }
  54. }
  55. impl From<ShipEvent> for u16 {
  56. fn from(other: ShipEvent) -> u16 {
  57. u8::from(other) as u16
  58. }
  59. }
  60. impl From<ShipEvent> for u8 {
  61. fn from(other: ShipEvent) -> u8 {
  62. match other {
  63. ShipEvent::None => 0,
  64. ShipEvent::Christmas => 1,
  65. ShipEvent::Valentines => 3,
  66. ShipEvent::Easter => 4,
  67. ShipEvent::Halloween => 5,
  68. ShipEvent::Sonic => 6,
  69. ShipEvent::NewYear => 7,
  70. ShipEvent::Summer => 8,
  71. ShipEvent::White => 9,
  72. ShipEvent::Wedding => 10,
  73. ShipEvent::Fall => 11,
  74. ShipEvent::Spring => 12,
  75. ShipEvent::Summer2 => 13,
  76. ShipEvent::Spring2 => 14,
  77. }
  78. }
  79. }
  80. #[derive(Error, Debug)]
  81. pub enum ShipError {
  82. #[error("client not found {0}")]
  83. ClientNotFound(ClientId),
  84. #[error("no character in slot {0} {1}")]
  85. NoCharacterInSlot(ClientId, u32),
  86. #[error("invalid slot {0} {1}")]
  87. InvalidSlot(ClientId, u32),
  88. #[error("too many clients")]
  89. TooManyClients,
  90. #[error("client location {0}")]
  91. ClientLocationError(ClientLocationError),
  92. #[error("maps error {0}")]
  93. MapsError(#[from] MapsError),
  94. #[error("map area error {0}")]
  95. MapAreaError(#[from] MapAreaError),
  96. #[error("invalid room {0}")]
  97. InvalidRoom(u32),
  98. #[error("monster already droppped item {0} {1}")]
  99. MonsterAlreadyDroppedItem(ClientId, u16),
  100. #[error("slice error {0}")]
  101. SliceError(#[from] std::array::TryFromSliceError),
  102. #[error("item error")]
  103. ItemError, // TODO: refine this
  104. #[error("pick up invalid item id {0}")]
  105. PickUpInvalidItemId(u32),
  106. #[error("drop invalid item id {0}")]
  107. DropInvalidItemId(u32),
  108. #[error("item state error {0}")]
  109. ItemStateError(#[from] items::state::ItemStateError),
  110. #[error("item drop location not set")]
  111. ItemDropLocationNotSet,
  112. #[error("box already dropped item {0} {1}")]
  113. BoxAlreadyDroppedItem(ClientId, u16),
  114. #[error("invalid quest category {0}")]
  115. InvalidQuestCategory(u16),
  116. #[error("invalid quest {0}")]
  117. InvalidQuest(u16),
  118. #[error("invalid quest filename {0}")]
  119. InvalidQuestFilename(String),
  120. #[error("io error {0}")]
  121. IoError(#[from] std::io::Error),
  122. #[error("not enough meseta {0} {1}")]
  123. NotEnoughMeseta(ClientId, u32),
  124. #[error("shop error")]
  125. ShopError,
  126. #[error("gateway error {0}")]
  127. GatewayError(#[from] GatewayError),
  128. #[error("unknown monster {0}")]
  129. UnknownMonster(crate::ship::monster::MonsterType),
  130. #[error("invalid ship {0}")]
  131. InvalidShip(usize),
  132. #[error("invalid block {0}")]
  133. InvalidBlock(usize),
  134. #[error("invalid item {0}")]
  135. InvalidItem(items::ClientItemId),
  136. #[error("trade error {0}")]
  137. TradeError(#[from] crate::ship::packet::handler::trade::TradeError),
  138. #[error("trade state error {0}")]
  139. TradeStateError(#[from] crate::ship::trade::TradeStateError),
  140. #[error("message error {0}")]
  141. MessageError(#[from] crate::ship::packet::handler::direct_message::MessageError),
  142. #[error("room creation error {0}")]
  143. RoomCreationError(#[from] room::RoomCreationError),
  144. #[error("channel send error {0}")]
  145. SendError(#[from] async_std::channel::SendError<ShipMessage>),
  146. }
  147. /*
  148. impl<I: Into<ClientLocationError>> From<I> for ShipError {
  149. fn from(other: I) -> ShipError {
  150. ShipError::ClientLocationError(other.into())
  151. }
  152. }
  153. */
  154. #[derive(Debug)]
  155. pub enum RecvShipPacket {
  156. Login(Login),
  157. MenuSelect(MenuSelect),
  158. RoomPasswordReq(RoomPasswordReq),
  159. CharData(CharData),
  160. Message(Message),
  161. DirectMessage(DirectMessage),
  162. PlayerChat(PlayerChat),
  163. CreateRoom(CreateRoom),
  164. RoomNameRequest(RoomNameRequest),
  165. ViewInfoboardRequest(ViewInfoboardRequest),
  166. WriteInfoboard(WriteInfoboard),
  167. RoomListRequest(RoomListRequest),
  168. Like62ButCooler(Like62ButCooler),
  169. ClientCharacterData(ClientCharacterData),
  170. DoneBursting(DoneBursting),
  171. DoneBursting2(DoneBursting2),
  172. LobbySelect(LobbySelect),
  173. RequestQuestList(RequestQuestList),
  174. MenuDetail(MenuDetail),
  175. QuestDetailRequest(QuestDetailRequest),
  176. QuestMenuSelect(QuestMenuSelect),
  177. QuestFileRequest(QuestFileRequest),
  178. QuestChunkAck(QuestChunkAck),
  179. DoneLoadingQuest(DoneLoadingQuest),
  180. FullCharacterData(Box<FullCharacterData>),
  181. SaveOptions(SaveOptions),
  182. RequestShipList(RequestShipList),
  183. RequestShipBlockList(RequestShipBlockList),
  184. ItemsToTrade(ItemsToTrade),
  185. TradeConfirmed(TradeConfirmed),
  186. KeyboardConfig(KeyboardConfig),
  187. GamepadConfig(GamepadConfig),
  188. UpdateConfig(UpdateConfig),
  189. }
  190. impl RecvServerPacket for RecvShipPacket {
  191. fn from_bytes(data: &[u8]) -> Result<RecvShipPacket, PacketParseError> {
  192. match u16::from_le_bytes([data[2], data[3]]) {
  193. 0x93 => Ok(RecvShipPacket::Login(Login::from_bytes(data)?)),
  194. 0x09 => match data[8] as u32 {
  195. QUEST_SELECT_MENU_ID => Ok(RecvShipPacket::QuestDetailRequest(QuestDetailRequest::from_bytes(data)?)),
  196. _ => Ok(RecvShipPacket::MenuDetail(MenuDetail::from_bytes(data)?)),
  197. }
  198. 0x10 => match (data[0], data[8] as u32) {
  199. (16, QUEST_SELECT_MENU_ID) => Ok(RecvShipPacket::QuestMenuSelect(QuestMenuSelect::from_bytes(data)?)),
  200. (16, _) => Ok(RecvShipPacket::MenuSelect(MenuSelect::from_bytes(data)?)),
  201. (48, _) => Ok(RecvShipPacket::RoomPasswordReq(RoomPasswordReq::from_bytes(data)?)),
  202. _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())),
  203. },
  204. 0x13 => Ok(RecvShipPacket::QuestChunkAck(QuestChunkAck::from_bytes(data)?)),
  205. 0x44 => Ok(RecvShipPacket::QuestFileRequest(QuestFileRequest::from_bytes(data)?)),
  206. 0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)),
  207. 0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)),
  208. 0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)),
  209. 0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)),
  210. 0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)),
  211. 0x8A => Ok(RecvShipPacket::RoomNameRequest(RoomNameRequest::from_bytes(data)?)),
  212. 0xD8 => Ok(RecvShipPacket::ViewInfoboardRequest(ViewInfoboardRequest::from_bytes(data)?)),
  213. 0xD9 => Ok(RecvShipPacket::WriteInfoboard(WriteInfoboard::from_bytes(data)?)),
  214. 0x08 => Ok(RecvShipPacket::RoomListRequest(RoomListRequest::from_bytes(data)?)),
  215. 0x6D => Ok(RecvShipPacket::Like62ButCooler(Like62ButCooler::from_bytes(data)?)),
  216. 0x98 => Ok(RecvShipPacket::ClientCharacterData(ClientCharacterData::from_bytes(data)?)),
  217. 0x6F => Ok(RecvShipPacket::DoneBursting(DoneBursting::from_bytes(data)?)),
  218. 0x16F => Ok(RecvShipPacket::DoneBursting2(DoneBursting2::from_bytes(data)?)),
  219. 0x84 => Ok(RecvShipPacket::LobbySelect(LobbySelect::from_bytes(data)?)),
  220. 0xA0 => Ok(RecvShipPacket::RequestShipList(RequestShipList::from_bytes(data)?)),
  221. 0xA1 => Ok(RecvShipPacket::RequestShipBlockList(RequestShipBlockList::from_bytes(data)?)),
  222. 0xA2 => Ok(RecvShipPacket::RequestQuestList(RequestQuestList::from_bytes(data)?)),
  223. 0xAC => Ok(RecvShipPacket::DoneLoadingQuest(DoneLoadingQuest::from_bytes(data)?)),
  224. 0xD0 => Ok(RecvShipPacket::ItemsToTrade(ItemsToTrade::from_bytes(data)?)),
  225. 0xD2 => Ok(RecvShipPacket::TradeConfirmed(TradeConfirmed::from_bytes(data)?)),
  226. 0xE7 => Ok(RecvShipPacket::FullCharacterData(Box::new(FullCharacterData::from_bytes(data)?))),
  227. 0x1ED => Ok(RecvShipPacket::SaveOptions(SaveOptions::from_bytes(data)?)),
  228. 0x4ED => Ok(RecvShipPacket::KeyboardConfig(KeyboardConfig::from_bytes(data)?)),
  229. 0x5ED => Ok(RecvShipPacket::GamepadConfig(GamepadConfig::from_bytes(data)?)),
  230. 0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
  231. _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
  232. }
  233. }
  234. }
  235. #[derive(Debug, Clone, PartialEq)]
  236. pub enum SendShipPacket {
  237. ShipWelcome(ShipWelcome),
  238. LoginResponse(LoginResponse),
  239. ShipList(ShipList),
  240. ShipBlockList(ShipBlockList),
  241. FullCharacter(Box<FullCharacter>),
  242. CharDataRequest(CharDataRequest),
  243. JoinLobby(JoinLobby),
  244. AddToLobby(AddToLobby),
  245. Message(Message),
  246. DirectMessage(DirectMessage),
  247. PlayerChat(PlayerChat),
  248. SmallDialog(SmallDialog),
  249. SmallLeftDialog(SmallLeftDialog),
  250. JoinRoom(JoinRoom),
  251. AddToRoom(AddToRoom),
  252. LeaveLobby(LeaveLobby),
  253. LeaveRoom(LeaveRoom),
  254. RoomNameResponse(RoomNameResponse),
  255. ViewInfoboardResponse(ViewInfoboardResponse),
  256. RoomListResponse(RoomListResponse),
  257. Like62ButCooler(Like62ButCooler),
  258. BurstDone72(BurstDone72),
  259. DoneBursting(DoneBursting),
  260. DoneBursting2(DoneBursting2),
  261. LobbyList(LobbyList),
  262. QuestCategoryList(QuestCategoryList),
  263. QuestOptionList(QuestOptionList),
  264. QuestDetail(QuestDetail),
  265. QuestHeader(QuestHeader),
  266. QuestChunk(QuestChunk),
  267. DoneLoadingQuest(DoneLoadingQuest),
  268. BankItemList(BankItemList),
  269. RedirectClient(RedirectClient),
  270. RareMonsterList(RareMonsterList),
  271. AcknowledgeTrade(AcknowledgeTrade),
  272. CancelTrade(CancelTrade),
  273. TradeSuccessful(TradeSuccessful),
  274. LobbyEvent(LobbyEvent),
  275. }
  276. impl SendServerPacket for SendShipPacket {
  277. fn as_bytes(&self) -> Vec<u8> {
  278. match self {
  279. SendShipPacket::ShipWelcome(pkt) => pkt.as_bytes(),
  280. SendShipPacket::LoginResponse(pkt) => pkt.as_bytes(),
  281. SendShipPacket::ShipList(pkt) => pkt.as_bytes(),
  282. SendShipPacket::ShipBlockList(pkt) => pkt.as_bytes(),
  283. SendShipPacket::FullCharacter(pkt) => pkt.as_bytes(),
  284. SendShipPacket::CharDataRequest(pkt) => pkt.as_bytes(),
  285. SendShipPacket::JoinLobby(pkt) => pkt.as_bytes(),
  286. SendShipPacket::AddToLobby(pkt) => pkt.as_bytes(),
  287. SendShipPacket::Message(pkt) => pkt.as_bytes(),
  288. SendShipPacket::DirectMessage(pkt) => pkt.as_bytes(),
  289. SendShipPacket::PlayerChat(pkt) => pkt.as_bytes(),
  290. SendShipPacket::SmallDialog(pkt) => pkt.as_bytes(),
  291. SendShipPacket::SmallLeftDialog(pkt) => pkt.as_bytes(),
  292. SendShipPacket::JoinRoom(pkt) => pkt.as_bytes(),
  293. SendShipPacket::AddToRoom(pkt) => pkt.as_bytes(),
  294. SendShipPacket::LeaveLobby(pkt) => pkt.as_bytes(),
  295. SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
  296. SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
  297. SendShipPacket::ViewInfoboardResponse(pkt) => pkt.as_bytes(),
  298. SendShipPacket::RoomListResponse(pkt) => pkt.as_bytes(),
  299. SendShipPacket::Like62ButCooler(pkt) => pkt.as_bytes(),
  300. SendShipPacket::BurstDone72(pkt) => pkt.as_bytes(),
  301. SendShipPacket::DoneBursting(pkt) => pkt.as_bytes(),
  302. SendShipPacket::DoneBursting2(pkt) => pkt.as_bytes(),
  303. SendShipPacket::LobbyList(pkt) => pkt.as_bytes(),
  304. SendShipPacket::QuestCategoryList(pkt) => pkt.as_bytes(),
  305. SendShipPacket::QuestOptionList(pkt) => pkt.as_bytes(),
  306. SendShipPacket::QuestDetail(pkt) => pkt.as_bytes(),
  307. SendShipPacket::QuestHeader(pkt) => pkt.as_bytes(),
  308. SendShipPacket::QuestChunk(pkt) => pkt.as_bytes(),
  309. SendShipPacket::DoneLoadingQuest(pkt) => pkt.as_bytes(),
  310. SendShipPacket::BankItemList(pkt) => pkt.as_bytes(),
  311. SendShipPacket::RedirectClient(pkt) => pkt.as_bytes(),
  312. SendShipPacket::RareMonsterList(pkt) => pkt.as_bytes(),
  313. SendShipPacket::AcknowledgeTrade(pkt) => pkt.as_bytes(),
  314. SendShipPacket::CancelTrade(pkt) => pkt.as_bytes(),
  315. SendShipPacket::TradeSuccessful(pkt) => pkt.as_bytes(),
  316. SendShipPacket::LobbyEvent(pkt) => pkt.as_bytes(),
  317. }
  318. }
  319. }
  320. #[derive(Clone)]
  321. pub struct ItemShops {
  322. pub weapon_shop: HashMap<(room::Difficulty, SectionID), Arc<Mutex<WeaponShop<rand_chacha::ChaCha20Rng>>>>,
  323. pub tool_shop: Arc<Mutex<ToolShop<rand_chacha::ChaCha20Rng>>>,
  324. pub armor_shop: Arc<Mutex<ArmorShop<rand_chacha::ChaCha20Rng>>>,
  325. }
  326. impl Default for ItemShops {
  327. fn default() -> ItemShops {
  328. let difficulty = [room::Difficulty::Normal, room::Difficulty::Hard, room::Difficulty::VeryHard, room::Difficulty::Ultimate];
  329. let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum,
  330. SectionID::Pinkal, SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill];
  331. let mut weapon_shop = HashMap::new();
  332. for d in difficulty.iter() {
  333. for id in section_id.iter() {
  334. weapon_shop.insert((*d, *id), Arc::new(Mutex::new(WeaponShop::new(*d, *id))));
  335. }
  336. }
  337. ItemShops {
  338. weapon_shop,
  339. tool_shop: Arc::new(Mutex::new(ToolShop::default())),
  340. armor_shop: Arc::new(Mutex::new(ArmorShop::default())),
  341. }
  342. }
  343. }
  344. pub struct ShipServerStateBuilder<EG: EntityGateway + Clone + 'static> {
  345. entity_gateway: Option<EG>,
  346. name: Option<String>,
  347. ip: Option<Ipv4Addr>,
  348. port: Option<u16>,
  349. auth_token: Option<AuthToken>,
  350. event: Option<ShipEvent>,
  351. map_builder: Option<Box<dyn Fn(room::RoomMode, ShipEvent) -> Maps + Send + Sync>>,
  352. drop_table_builder: Option<Box<dyn Fn(room::Episode, room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
  353. num_blocks: usize,
  354. }
  355. impl<EG: EntityGateway + Clone + 'static> Default for ShipServerStateBuilder<EG> {
  356. fn default() -> ShipServerStateBuilder<EG> {
  357. ShipServerStateBuilder {
  358. entity_gateway: None,
  359. name: None,
  360. ip: None,
  361. port: None,
  362. auth_token: None,
  363. event: None,
  364. map_builder: None,
  365. drop_table_builder: None,
  366. num_blocks: 2,
  367. }
  368. }
  369. }
  370. impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
  371. #[must_use]
  372. pub fn gateway(mut self, entity_gateway: EG) -> ShipServerStateBuilder<EG> {
  373. self.entity_gateway = Some(entity_gateway);
  374. self
  375. }
  376. #[must_use]
  377. pub fn name(mut self, name: String) -> ShipServerStateBuilder<EG> {
  378. self.name = Some(name);
  379. self
  380. }
  381. #[must_use]
  382. pub fn ip(mut self, ip: Ipv4Addr) -> ShipServerStateBuilder<EG> {
  383. self.ip = Some(ip);
  384. self
  385. }
  386. #[must_use]
  387. pub fn port(mut self, port: u16) -> ShipServerStateBuilder<EG> {
  388. self.port = Some(port);
  389. self
  390. }
  391. #[must_use]
  392. pub fn auth_token(mut self, auth_token: AuthToken) -> ShipServerStateBuilder<EG> {
  393. self.auth_token = Some(auth_token);
  394. self
  395. }
  396. #[must_use]
  397. pub fn event(mut self, event: ShipEvent) -> ShipServerStateBuilder<EG> {
  398. self.event = Some(event);
  399. self
  400. }
  401. #[must_use]
  402. pub fn map_builder(mut self, map_builder: Box<dyn Fn(room::RoomMode, ShipEvent) -> Maps + Send + Sync>) -> ShipServerStateBuilder<EG> {
  403. self.map_builder = Some(map_builder);
  404. self
  405. }
  406. #[must_use]
  407. pub fn drop_table_builder(mut self, drop_table_builder: Box<dyn Fn(room::Episode, room::Difficulty, SectionID) -> DropTable + Send + Sync>) -> ShipServerStateBuilder<EG> {
  408. self.drop_table_builder = Some(drop_table_builder);
  409. self
  410. }
  411. #[must_use]
  412. pub fn blocks(mut self, num_blocks: usize) -> ShipServerStateBuilder<EG> {
  413. self.num_blocks = num_blocks;
  414. self
  415. }
  416. pub fn build(self) -> ShipServerState<EG> {
  417. let blocks = std::iter::repeat_with(Block::default).take(self.num_blocks).collect(); // Block doesn't have a Clone impl which limits the easy ways to init this
  418. ShipServerState {
  419. entity_gateway: self.entity_gateway.unwrap(),
  420. clients: Clients::default(),
  421. name: self.name.unwrap_or_else(|| "NAMENOTSET".into()),
  422. item_state: items::state::ItemState::default(),
  423. ip: self.ip.unwrap_or_else(|| Ipv4Addr::new(127,0,0,1)),
  424. port: self.port.unwrap_or(SHIP_PORT),
  425. shops: ItemShops::default(),
  426. blocks: Blocks(blocks),
  427. event: self.event.unwrap_or(ShipEvent::None),
  428. map_builder: Arc::new(self.map_builder.unwrap_or(Box::new(generate_free_roam_maps))),
  429. drop_table_builder: Arc::new(self.drop_table_builder.unwrap_or(Box::new(DropTable::new))),
  430. auth_token: self.auth_token.unwrap_or_else(|| AuthToken("".into())),
  431. ship_list: Arc::new(RwLock::new(Vec::new())),
  432. shipgate_sender: None,
  433. trades: Default::default(),
  434. }
  435. }
  436. }
  437. #[derive(Clone, Default)]
  438. pub struct Block {
  439. client_location: ClientLocation,
  440. pub rooms: room::Rooms,
  441. }
  442. #[derive(Clone)]
  443. pub struct Blocks(pub Vec<Block>);
  444. impl Blocks {
  445. async fn get_from_client(&mut self, id: ClientId, clients: &Clients) -> Result<&mut Block, anyhow::Error> {
  446. let block = clients.with(id, |client| Box::pin(async move {
  447. client.block
  448. })).await?;
  449. self.0
  450. .get_mut(block)
  451. .ok_or_else(|| ShipError::InvalidBlock(block).into())
  452. }
  453. }
  454. #[derive(Clone)]
  455. pub struct ShipServerState<EG: EntityGateway + Clone + 'static> {
  456. entity_gateway: EG,
  457. pub clients: Clients,
  458. name: String,
  459. item_state: items::state::ItemState,
  460. shops: ItemShops,
  461. pub blocks: Blocks,
  462. event: ShipEvent,
  463. ip: Ipv4Addr,
  464. port: u16,
  465. auth_token: AuthToken,
  466. ship_list: Arc<RwLock<Vec<Ship>>>,
  467. shipgate_sender: Option<channel::Sender<ShipMessage>>,
  468. trades: TradeState,
  469. map_builder: Arc<Box<dyn Fn(room::RoomMode, ShipEvent) -> Maps + Send + Sync>>,
  470. drop_table_builder: Arc<Box<dyn Fn(room::Episode, room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
  471. }
  472. impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> {
  473. pub fn builder() -> ShipServerStateBuilder<EG> {
  474. ShipServerStateBuilder::default()
  475. }
  476. async fn message(&mut self, id: ClientId, msg: Message) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
  477. Ok(match msg.msg {
  478. GameMessage::RequestExp(request_exp) => {
  479. let block = self.blocks.get_from_client(id, &self.clients).await?;
  480. handler::message::request_exp(id, request_exp, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms).await?
  481. },
  482. GameMessage::PlayerDropItem(player_drop_item) => {
  483. let block = self.blocks.get_from_client(id, &self.clients).await?;
  484. handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await?
  485. },
  486. GameMessage::DropCoordinates(drop_coordinates) => {
  487. let block = self.blocks.get_from_client(id, &self.clients).await?;
  488. handler::message::drop_coordinates(id, drop_coordinates, &block.client_location, &self.clients, &block.rooms).await?
  489. },
  490. GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => {
  491. let block = self.blocks.get_from_client(id, &self.clients).await?;
  492. handler::message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  493. },
  494. GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) |
  495. GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) |
  496. GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) |
  497. GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
  498. let block = self.blocks.get_from_client(id, &self.clients).await?;
  499. handler::message::update_player_position(id, msg, &self.clients, &block.client_location, &block.rooms).await?
  500. },
  501. GameMessage::ChargeAttack(charge_attack) => {
  502. let block = self.blocks.get_from_client(id, &self.clients).await?;
  503. handler::message::charge_attack(id, charge_attack, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  504. },
  505. GameMessage::PlayerUseItem(player_use_item) => {
  506. let block = self.blocks.get_from_client(id, &self.clients).await?;
  507. handler::message::player_uses_item(id, player_use_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  508. },
  509. GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => {
  510. let block = self.blocks.get_from_client(id, &self.clients).await?;
  511. handler::message::player_used_medical_center(id, player_used_medical_center, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  512. },
  513. GameMessage::PlayerFeedMag(player_feed_mag) => {
  514. let block = self.blocks.get_from_client(id, &self.clients).await?;
  515. handler::message::player_feed_mag(id, player_feed_mag, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  516. },
  517. GameMessage::PlayerEquipItem(player_equip_item) => {
  518. handler::message::player_equips_item(id, player_equip_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
  519. },
  520. GameMessage::PlayerUnequipItem(player_unequip_item) => {
  521. handler::message::player_unequips_item(id, player_unequip_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
  522. },
  523. GameMessage::SortItems(sort_items) => {
  524. handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
  525. },
  526. GameMessage::PlayerSoldItem(player_sold_item) => {
  527. handler::message::player_sells_item(id, player_sold_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
  528. },
  529. _ => {
  530. let cmsg = msg.clone();
  531. let block = self.blocks.get_from_client(id, &self.clients).await?;
  532. block.client_location.get_client_neighbors(id).await.unwrap().into_iter()
  533. .map(move |client| {
  534. (client.client, SendShipPacket::Message(cmsg.clone()))
  535. })
  536. .collect()
  537. },
  538. })
  539. }
  540. async fn direct_message(&mut self, id: ClientId, msg: DirectMessage) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
  541. let target = msg.flag;
  542. let block = self.blocks.get_from_client(id, &self.clients).await?;
  543. Ok(match msg.msg {
  544. GameMessage::GuildcardSend(guildcard_send) => {
  545. handler::direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients).await?
  546. },
  547. GameMessage::RequestItem(request_item) => {
  548. handler::direct_message::request_item(id, request_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await?
  549. },
  550. GameMessage::PickupItem(pickup_item) => {
  551. handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  552. },
  553. GameMessage::BoxDropRequest(box_drop_request) => {
  554. handler::direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await?
  555. },
  556. GameMessage::BankRequest(_bank_request) => {
  557. handler::direct_message::send_bank_list(id, &self.clients, &mut self.item_state).await?
  558. },
  559. GameMessage::BankInteraction(bank_interaction) => {
  560. handler::direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  561. },
  562. GameMessage::ShopRequest(shop_request) => {
  563. handler::direct_message::shop_request(id, shop_request, &block.client_location, &self.clients, &block.rooms, &self.shops).await?
  564. },
  565. GameMessage::BuyItem(buy_item) => {
  566. handler::direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  567. },
  568. GameMessage::TekRequest(tek_request) => {
  569. handler::direct_message::request_tek_item(id, tek_request, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
  570. },
  571. GameMessage::TekAccept(tek_accept) => {
  572. handler::direct_message::accept_tek_item(id, tek_accept, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await?
  573. },
  574. GameMessage::TradeRequest(trade_request) => {
  575. handler::trade::trade_request(id, trade_request, target, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
  576. },
  577. _ => {
  578. let cmsg = msg.clone();
  579. block.client_location.get_all_clients_by_client(id).await.unwrap().into_iter()
  580. .filter(move |client| client.local_client.id() == target as u8)
  581. .map(move |client| {
  582. (client.client, SendShipPacket::DirectMessage(cmsg.clone()))
  583. })
  584. .collect()
  585. },
  586. })
  587. }
  588. }
  589. #[async_trait::async_trait]
  590. impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
  591. type SendPacket = SendShipPacket;
  592. type RecvPacket = RecvShipPacket;
  593. type Cipher = PSOBBCipher;
  594. type PacketError = anyhow::Error;
  595. async fn on_connect(&mut self, _id: ClientId) -> Result<Vec<OnConnect<Self::SendPacket, Self::Cipher>>, anyhow::Error> {
  596. let mut rng = rand::thread_rng();
  597. let mut server_key = [0u8; 48];
  598. let mut client_key = [0u8; 48];
  599. rng.fill(&mut server_key[..]);
  600. rng.fill(&mut client_key[..]);
  601. Ok(vec![OnConnect::Packet(SendShipPacket::ShipWelcome(ShipWelcome::new(server_key, client_key))),
  602. OnConnect::Cipher(PSOBBCipher::new(ELSEWHERE_PARRAY, ELSEWHERE_PRIVATE_KEY, client_key),
  603. PSOBBCipher::new(ELSEWHERE_PARRAY, ELSEWHERE_PRIVATE_KEY, server_key))
  604. ])
  605. }
  606. async fn handle(&mut self, id: ClientId, pkt: RecvShipPacket) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
  607. if let Ok((char_id, char_playtime)) = self.clients.with_mut(id, |client| Box::pin(async move {
  608. client.update_playtime();
  609. (client.character.id, client.character.playtime)
  610. })).await {
  611. self.entity_gateway.set_character_playtime(&char_id, char_playtime).await?;
  612. }
  613. Ok(match pkt {
  614. RecvShipPacket::Login(login) => {
  615. handler::auth::validate_login(id, login, &mut self.entity_gateway, &mut self.clients, &mut self.item_state, &self.shipgate_sender, &self.name, self.blocks.0.len())
  616. .await?
  617. .into_iter()
  618. .map(move |pkt| (id, pkt))
  619. .collect()
  620. },
  621. RecvShipPacket::QuestDetailRequest(questdetailrequest) => {
  622. let block = self.blocks.get_from_client(id, &self.clients).await?;
  623. match questdetailrequest.menu {
  624. QUEST_SELECT_MENU_ID => handler::quest::quest_detail(id, questdetailrequest, &block.client_location, &block.rooms).await?,
  625. _ => unreachable!(),
  626. }
  627. },
  628. RecvShipPacket::MenuSelect(menuselect) => {
  629. let block = self.blocks.get_from_client(id, &self.clients).await?;
  630. match menuselect.menu {
  631. SHIP_MENU_ID => {
  632. let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten();
  633. let select_ship = handler::ship::selected_ship(id, menuselect, &self.ship_list).await?;
  634. leave_lobby.chain(select_ship).collect()
  635. }
  636. BLOCK_MENU_ID => {
  637. let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten();
  638. let select_block = handler::lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter();
  639. leave_lobby.chain(select_block).collect()
  640. }
  641. ROOM_MENU_ID => handler::room::join_room(id, menuselect, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.event).await?,
  642. QUEST_CATEGORY_MENU_ID => handler::quest::select_quest_category(id, menuselect, &block.client_location, &block.rooms).await?,
  643. _ => unreachable!(),
  644. }
  645. },
  646. RecvShipPacket::QuestMenuSelect(questmenuselect) => {
  647. let block = self.blocks.get_from_client(id, &self.clients).await?;
  648. handler::quest::player_chose_quest(id, questmenuselect, &self.clients, &block.client_location, &block.rooms, self.event).await?
  649. },
  650. RecvShipPacket::MenuDetail(menudetail) => {
  651. let block = self.blocks.get_from_client(id, &self.clients).await?;
  652. handler::lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &self.clients).await?
  653. },
  654. RecvShipPacket::RoomPasswordReq(room_password_req) => {
  655. let block = self.blocks.get_from_client(id, &self.clients).await?;
  656. let room_password = block.rooms.with(RoomId(room_password_req.item as usize), |room| Box::pin(async move {
  657. room.password
  658. })).await?;
  659. if room_password_req.password == room_password {
  660. let menuselect = MenuSelect {
  661. menu: room_password_req.menu,
  662. item: room_password_req.item,
  663. };
  664. handler::room::join_room(id, menuselect, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.event).await?
  665. }
  666. else {
  667. vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Incorrect password".into())))]
  668. }
  669. },
  670. RecvShipPacket::CharData(chardata) => {
  671. let block = self.blocks.get_from_client(id, &self.clients).await?;
  672. handler::lobby::send_player_to_lobby(id, chardata, &mut block.client_location, &self.clients, &self.item_state, self.event).await?
  673. },
  674. RecvShipPacket::Message(msg) => {
  675. self.message(id, msg).await?
  676. },
  677. RecvShipPacket::DirectMessage(msg) => {
  678. self.direct_message(id, msg).await?
  679. },
  680. RecvShipPacket::PlayerChat(msg) => {
  681. let block = self.blocks.get_from_client(id, &self.clients).await?;
  682. handler::communication::player_chat(id, msg, &block.client_location, &self.clients).await?
  683. },
  684. RecvShipPacket::CreateRoom(create_room) => {
  685. let block = self.blocks.get_from_client(id, &self.clients).await?;
  686. handler::room::create_room(id, create_room, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.map_builder.clone(), self.drop_table_builder.clone(), self.event).await?
  687. },
  688. RecvShipPacket::RoomNameRequest(_req) => {
  689. let block = self.blocks.get_from_client(id, &self.clients).await?;
  690. handler::room::room_name_request(id, &block.client_location, &block.rooms).await?
  691. },
  692. RecvShipPacket::UpdateConfig(pkt) => {
  693. handler::settings::update_config(id, pkt, &self.clients, &mut self.entity_gateway).await?
  694. },
  695. RecvShipPacket::ViewInfoboardRequest(_pkt) => {
  696. let block = self.blocks.get_from_client(id, &self.clients).await?;
  697. handler::communication::request_infoboard(id, &block.client_location, &self.clients).await?
  698. },
  699. RecvShipPacket::WriteInfoboard(pkt) => {
  700. handler::communication::write_infoboard(id, pkt, &self.clients, &mut self.entity_gateway).await?
  701. },
  702. RecvShipPacket::RoomListRequest(_req) => {
  703. let block = self.blocks.get_from_client(id, &self.clients).await?;
  704. handler::room::request_room_list(id, &block.client_location, &block.rooms).await
  705. },
  706. RecvShipPacket::Like62ButCooler(cool62) => {
  707. let block = self.blocks.get_from_client(id, &self.clients).await?;
  708. handler::room::cool_62(id, cool62, &block.client_location).await?
  709. },
  710. RecvShipPacket::ClientCharacterData(_) => {
  711. // TOOD: validate this in some way?
  712. Vec::new()
  713. },
  714. RecvShipPacket::DoneBursting(_) => {
  715. let block = self.blocks.get_from_client(id, &self.clients).await?;
  716. handler::room::done_bursting(id, &block.client_location, &block.rooms).await?
  717. },
  718. RecvShipPacket::DoneBursting2(_) => {
  719. let block = self.blocks.get_from_client(id, &self.clients).await?;
  720. handler::room::done_bursting(id, &block.client_location, &block.rooms).await?
  721. },
  722. RecvShipPacket::LobbySelect(pkt) => {
  723. let block = self.blocks.get_from_client(id, &self.clients).await?;
  724. handler::lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, &mut self.entity_gateway, self.event).await?
  725. },
  726. RecvShipPacket::RequestQuestList(rql) => {
  727. let block = self.blocks.get_from_client(id, &self.clients).await?;
  728. handler::quest::send_quest_category_list(id, rql, &block.client_location, &block.rooms).await?
  729. },
  730. RecvShipPacket::QuestFileRequest(quest_file_request) => {
  731. let block = self.blocks.get_from_client(id, &self.clients).await?;
  732. handler::quest::quest_file_request(id, quest_file_request, &block.client_location, &mut block.rooms).await?
  733. },
  734. RecvShipPacket::QuestChunkAck(quest_chunk_ack) => {
  735. let block = self.blocks.get_from_client(id, &self.clients).await?;
  736. handler::quest::quest_chunk_ack(id, quest_chunk_ack, &block.client_location, &block.rooms).await?
  737. },
  738. RecvShipPacket::DoneLoadingQuest(_) => {
  739. let block = self.blocks.get_from_client(id, &self.clients).await?;
  740. handler::quest::done_loading_quest(id, &self.clients, &block.client_location).await?
  741. },
  742. RecvShipPacket::FullCharacterData(_full_character_data) => {
  743. Vec::new()
  744. },
  745. RecvShipPacket::SaveOptions(save_options) => {
  746. handler::settings::save_options(id, save_options, &self.clients, &mut self.entity_gateway).await?
  747. },
  748. RecvShipPacket::RequestShipList(_) => {
  749. handler::ship::ship_list(id, &self.ship_list).await
  750. },
  751. RecvShipPacket::RequestShipBlockList(_) => {
  752. handler::ship::block_list(id, &self.name, self.blocks.0.len())
  753. },
  754. RecvShipPacket::ItemsToTrade(items_to_trade) => {
  755. let block = self.blocks.get_from_client(id, &self.clients).await?;
  756. handler::trade::items_to_trade(id, items_to_trade, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
  757. },
  758. RecvShipPacket::TradeConfirmed(_) => {
  759. let block = self.blocks.get_from_client(id, &self.clients).await?;
  760. handler::trade::trade_confirmed(id, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await?
  761. },
  762. RecvShipPacket::KeyboardConfig(keyboard_config) => {
  763. handler::settings::keyboard_config(id, keyboard_config, &self.clients, &mut self.entity_gateway).await?
  764. },
  765. RecvShipPacket::GamepadConfig(gamepad_config) => {
  766. handler::settings::gamepad_config(id, gamepad_config, &self.clients, &mut self.entity_gateway).await?
  767. },
  768. })
  769. }
  770. async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
  771. let block = self.blocks.get_from_client(id, &self.clients).await?;
  772. let area_client = block.client_location.get_local_client(id).await?;
  773. let neighbors = block.client_location.get_client_neighbors(id).await?;
  774. let pkt = match block.client_location.get_area(id).await? {
  775. RoomLobby::Room(room) => {
  776. if neighbors.is_empty() {
  777. block.rooms.remove(room).await;
  778. }
  779. let leader = block.client_location.get_room_leader(room).await?;
  780. SendShipPacket::LeaveRoom(LeaveRoom::new(area_client.local_client.id(), leader.local_client.id()))
  781. },
  782. RoomLobby::Lobby(lobby) => {
  783. let leader = block.client_location.get_lobby_leader(lobby).await?;
  784. SendShipPacket::LeaveLobby(LeaveLobby::new(area_client.local_client.id(), leader.local_client.id()))
  785. }
  786. };
  787. if let Some(mut client) = self.clients.remove(&id).await {
  788. client.user.at_ship = false;
  789. self.entity_gateway.save_user(&client.user).await;
  790. if let Some(shipgate_sender) = self.shipgate_sender.as_ref() {
  791. shipgate_sender.send(ShipMessage::RemoveUser(client.user.id)).await;
  792. }
  793. self.item_state.remove_character_from_room(&client.character).await
  794. }
  795. block.client_location.remove_client_from_area(id).await?;
  796. Ok(neighbors.into_iter().map(|n| {
  797. (n.client, pkt.clone())
  798. }).collect())
  799. }
  800. }
  801. #[async_trait::async_trait]
  802. impl<EG: EntityGateway + Clone> InterserverActor for ShipServerState<EG> {
  803. type SendMessage = ShipMessage;
  804. type RecvMessage = LoginMessage;
  805. type Error = ();
  806. async fn on_connect(&mut self, id: ServerId) -> Vec<(ServerId, Self::SendMessage)> {
  807. vec![
  808. (id, ShipMessage::Authenticate(self.auth_token.clone())),
  809. (id, ShipMessage::NewShip(Ship {
  810. name: self.name.clone(),
  811. ip: self.ip,
  812. port: self.port,
  813. block_count: 2,
  814. })),
  815. (id, ShipMessage::RequestShipList)
  816. ]
  817. }
  818. async fn on_action(&mut self, _id: ServerId, msg: Self::RecvMessage) -> Result<Vec<(ServerId, Self::SendMessage)>, Self::Error> {
  819. match msg {
  820. LoginMessage::SendMail{..} => {
  821. Ok(Vec::new())
  822. },
  823. LoginMessage::ShipList{mut ships} => {
  824. let mut ship_list = self.ship_list
  825. .write()
  826. .await;
  827. ship_list.clear();
  828. ship_list.append(&mut ships);
  829. Ok(Vec::new())
  830. },
  831. LoginMessage::RequestUsers => {
  832. /*
  833. Ok(self.clients.iter()
  834. .map(|(_, client)| {
  835. (id, ShipMessage::AddUser(client.user.id))
  836. })
  837. .collect())
  838. */
  839. // TODO
  840. Ok(Vec::new())
  841. }
  842. }
  843. }
  844. async fn on_disconnect(&mut self, _id: ServerId) -> Vec<(ServerId, Self::SendMessage)> {
  845. Vec::new()
  846. }
  847. async fn set_sender(&mut self, _server_id: ServerId, sender: channel::Sender<Self::SendMessage>) {
  848. self.shipgate_sender = Some(sender);
  849. }
  850. }