diff --git a/Cargo.toml b/Cargo.toml index d9c1bff..368c23a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] libpso = { git = "http://git.sharnoth.com/jake/libpso" } -async-std = { version = "1.7.0", features = ["unstable", "attributes"] } +async-std = { version = "1.9.0", features = ["unstable", "attributes"] } futures = "0.3.5" rand = "0.7.3" rand_chacha = "0.2.2" @@ -27,7 +27,7 @@ ages-prs = "0.1" async-trait = "0.1.41" lazy_static = "1.4.0" barrel = { version = "0.6.5", features = ["pg"] } -refinery = { version = "0.3.0", features = ["postgres"] } +refinery = { version = "0.5.0", features = ["postgres"] } sqlx = { version = "0.4.0", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } strum = "0.19.5" strum_macros = "0.19" diff --git a/src/common/mainloop/client.rs b/src/common/mainloop/client.rs index fff2a4f..31c736c 100644 --- a/src/common/mainloop/client.rs +++ b/src/common/mainloop/client.rs @@ -128,7 +128,7 @@ async fn send_pkt(socket: Arc { - NewClient(ClientId, async_std::sync::Sender), + NewClient(ClientId, async_std::channel::Sender), Packet(ClientId, R), Disconnect(ClientId), } @@ -142,8 +142,8 @@ enum ServerStateAction { fn client_recv_loop(client_id: ClientId, socket: Arc, cipher: Arc>>, - server_sender: async_std::sync::Sender, R>>, - client_sender: async_std::sync::Sender>) + server_sender: async_std::channel::Sender, R>>, + client_sender: async_std::channel::Sender>) where S: SendServerPacket + std::fmt::Debug + Send + 'static, R: RecvServerPacket + std::fmt::Debug + Send + 'static, @@ -181,7 +181,7 @@ fn client_send_loop(client_id: ClientId, socket: Arc, cipher_in: Arc>>, cipher_out: Arc>>, - client_receiver: async_std::sync::Receiver>) + client_receiver: async_std::channel::Receiver>) where S: SendServerPacket + std::fmt::Debug + Send + 'static, { @@ -208,7 +208,7 @@ where } fn state_client_loop(state: Arc>, - server_state_receiver: async_std::sync::Receiver, R>>) where + server_state_receiver: async_std::channel::Receiver, R>>) where STATE: ServerState + Send + 'static, S: SendServerPacket + std::fmt::Debug + Send + 'static, R: RecvServerPacket + std::fmt::Debug + Send + 'static, @@ -294,7 +294,7 @@ where let listener = async_std::net::TcpListener::bind(&std::net::SocketAddr::from((std::net::Ipv4Addr::new(0,0,0,0), client_port))).await.unwrap(); let mut id = 0; - let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024); + let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024); state_client_loop(state, server_state_receiver); loop { @@ -304,7 +304,7 @@ where info!("new client {:?} {:?} {:?}", client_id, sock, addr); - let (client_sender, client_receiver) = async_std::sync::channel(64); + let (client_sender, client_receiver) = async_std::channel::bounded(64); let socket = Arc::new(sock); let cipher_in: Arc>> = Arc::new(Mutex::new(Box::new(NullCipher {}))); let cipher_out: Arc>> = Arc::new(Mutex::new(Box::new(NullCipher {}))); diff --git a/src/common/mainloop/interserver.rs b/src/common/mainloop/interserver.rs index 7e4b95d..526e51d 100644 --- a/src/common/mainloop/interserver.rs +++ b/src/common/mainloop/interserver.rs @@ -49,12 +49,12 @@ impl MessageReceiver { #[derive(Debug)] enum InterserverInputAction { - NewConnection(ServerId, async_std::sync::Sender), + NewConnection(ServerId, async_std::channel::Sender), Message(ServerId, R), Disconnect(ServerId), } -async fn interserver_state_loop(state: Arc>, action_receiver: async_std::sync::Receiver>) +async fn interserver_state_loop(state: Arc>, action_receiver: async_std::channel::Receiver>) where A: InterserverActor + Send + 'static, S: Serialize + Send + 'static, @@ -114,8 +114,8 @@ where async fn login_recv_loop(server_id: ServerId, socket: async_std::net::TcpStream, - state_loop_sender: async_std::sync::Sender>, - output_loop_sender: async_std::sync::Sender) + state_loop_sender: async_std::channel::Sender>, + output_loop_sender: async_std::channel::Sender) where S: Serialize + std::fmt::Debug + Send + 'static, R: DeserializeOwned + std::fmt::Debug + Send + 'static, @@ -129,7 +129,7 @@ where match msg_receiver.recv().await { Ok(msg) => { info!("[login recv loop msg] {:?}", msg); - state_loop_sender.send(InterserverInputAction::Message(server_id, msg)).await + state_loop_sender.send(InterserverInputAction::Message(server_id, msg)).await; }, Err(err) => { if let MessageReceiverError::Disconnected = err { @@ -146,7 +146,7 @@ where async fn interserver_send_loop(server_id: ServerId, mut socket: async_std::net::TcpStream, - output_loop_receiver: async_std::sync::Receiver) + output_loop_receiver: async_std::channel::Receiver) where S: Serialize + std::fmt::Debug + Send + 'static, { @@ -159,13 +159,13 @@ where if let Ok(payload) = payload { let len_bytes = u32::to_le_bytes(payload.len() as u32); - match socket.write_all(&len_bytes).await { - Ok(_) => {}, - Err(err) => warn!("send failed: {:?}", err), + if let Err(err) = socket.write_all(&len_bytes).await { + warn!("interserver send failed: {:?}", err); + break; } - match socket.write_all(&payload.as_bytes()).await { - Ok(_) => {}, - Err(err) => warn!("send failed: {:?}", err), + if let Err(err) = socket.write_all(&payload.as_bytes()).await { + warn!("intserserver send failed: {:?}", err); + break; } } }, @@ -185,7 +185,7 @@ pub fn login_listen_mainloop(state: Arc(state: Arc(state: Arc(state: Arc>>, ip: std::net::Ipv4Addr, port: u16) -> Pin>> { Box::pin(async_std::task::spawn(async move { let mut id = 0; - let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024); + let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024); interserver_state_loop(state.clone(), server_state_receiver).await; @@ -230,7 +230,7 @@ pub fn ship_connect_mainloop(state: Arc Result<[Option; 4], GatewayError> { let characters = self.characters.lock().unwrap(); - let mut chars = [None; 4]; + const NONE: Option = None; + let mut chars = [NONE; 4]; characters .iter() .filter(|(_, c)| c.user_id == user.id) diff --git a/src/entity/gateway/postgres/models.rs b/src/entity/gateway/postgres/models.rs index 892fa24..d6a0c14 100644 --- a/src/entity/gateway/postgres/models.rs +++ b/src/entity/gateway/postgres/models.rs @@ -759,7 +759,7 @@ impl Into for PgEquipped { impl From<(CharacterEntityId, EquippedEntity)> for PgEquipped { fn from(char_equips: (CharacterEntityId, EquippedEntity)) -> PgEquipped { PgEquipped { - pchar: char_equips.0.0 as i32, + pchar: (char_equips.0).0 as i32, weapon: char_equips.1.weapon.map(|i| i.0 as i32), armor: char_equips.1.armor.map(|i| i.0 as i32), shield: char_equips.1.shield.map(|i| i.0 as i32), diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 45aee91..4d7a36e 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -229,7 +229,8 @@ impl EntityGateway for PostgresGateway { let mut stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by slot") .bind(user.id.0) .fetch(&self.pool); - let mut result = [None; 4]; + const NONE: Option = None; + let mut result = [NONE; 4]; while let Some(character) = stream.try_next().await? { let index = character.slot as usize; result[index] = Some(character.into()) diff --git a/src/lib.rs b/src/lib.rs index abd1d14..dbf3afa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,7 @@ #![allow(incomplete_features)] -#![feature(const_generics)] #![feature(maybe_uninit_extra)] -#![feature(const_in_array_repeat_expressions)] +#![feature(inline_const)] #![feature(drain_filter)] -#![feature(or_patterns)] diff --git a/src/ship/ship.rs b/src/ship/ship.rs index f8f08a6..b986648 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -390,9 +390,11 @@ pub struct Block { impl Default for Block { fn default() -> Block { + const SNONE: Option = None; + const NONE: Rooms = [SNONE; MAX_ROOMS]; Block { client_location: Box::new(ClientLocation::default()), - rooms: Box::new([None; MAX_ROOMS]), + rooms: Box::new(NONE), } } }