Browse Source

Merge pull request 'get elseware working with a newer version of rust' (#34) from latestrust into master

Reviewed-on: #34
pull/45/head
jake 3 years ago
parent
commit
d66a90c4cf
  1. 4
      Cargo.toml
  2. 14
      src/common/mainloop/client.rs
  3. 32
      src/common/mainloop/interserver.rs
  4. 3
      src/entity/gateway/inmemory.rs
  5. 2
      src/entity/gateway/postgres/models.rs
  6. 3
      src/entity/gateway/postgres/postgres.rs
  7. 4
      src/lib.rs
  8. 4
      src/ship/ship.rs

4
Cargo.toml

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
libpso = { git = "http://git.sharnoth.com/jake/libpso" } 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" futures = "0.3.5"
rand = "0.7.3" rand = "0.7.3"
rand_chacha = "0.2.2" rand_chacha = "0.2.2"
@ -27,7 +27,7 @@ ages-prs = "0.1"
async-trait = "0.1.41" async-trait = "0.1.41"
lazy_static = "1.4.0" lazy_static = "1.4.0"
barrel = { version = "0.6.5", features = ["pg"] } 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"] } sqlx = { version = "0.4.0", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] }
strum = "0.19.5" strum = "0.19.5"
strum_macros = "0.19" strum_macros = "0.19"

14
src/common/mainloop/client.rs

@ -128,7 +128,7 @@ async fn send_pkt<S: SendServerPacket + Send + std::fmt::Debug>(socket: Arc<asyn
enum ClientAction<S, R> { enum ClientAction<S, R> {
NewClient(ClientId, async_std::sync::Sender<S>),
NewClient(ClientId, async_std::channel::Sender<S>),
Packet(ClientId, R), Packet(ClientId, R),
Disconnect(ClientId), Disconnect(ClientId),
} }
@ -142,8 +142,8 @@ enum ServerStateAction<S> {
fn client_recv_loop<S, R>(client_id: ClientId, fn client_recv_loop<S, R>(client_id: ClientId,
socket: Arc<async_std::net::TcpStream>, socket: Arc<async_std::net::TcpStream>,
cipher: Arc<Mutex<Box<dyn PSOCipher + Send>>>, cipher: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
server_sender: async_std::sync::Sender<ClientAction<ServerStateAction<S>, R>>,
client_sender: async_std::sync::Sender<ServerStateAction<S>>)
server_sender: async_std::channel::Sender<ClientAction<ServerStateAction<S>, R>>,
client_sender: async_std::channel::Sender<ServerStateAction<S>>)
where where
S: SendServerPacket + std::fmt::Debug + Send + 'static, S: SendServerPacket + std::fmt::Debug + Send + 'static,
R: RecvServerPacket + std::fmt::Debug + Send + 'static, R: RecvServerPacket + std::fmt::Debug + Send + 'static,
@ -181,7 +181,7 @@ fn client_send_loop<S>(client_id: ClientId,
socket: Arc<async_std::net::TcpStream>, socket: Arc<async_std::net::TcpStream>,
cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>>, cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>>, cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
client_receiver: async_std::sync::Receiver<ServerStateAction<S>>)
client_receiver: async_std::channel::Receiver<ServerStateAction<S>>)
where where
S: SendServerPacket + std::fmt::Debug + Send + 'static, S: SendServerPacket + std::fmt::Debug + Send + 'static,
{ {
@ -208,7 +208,7 @@ where
} }
fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>, fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
server_state_receiver: async_std::sync::Receiver<ClientAction<ServerStateAction<S>, R>>) where
server_state_receiver: async_std::channel::Receiver<ClientAction<ServerStateAction<S>, R>>) where
STATE: ServerState<SendPacket=S, RecvPacket=R, PacketError=E> + Send + 'static, STATE: ServerState<SendPacket=S, RecvPacket=R, PacketError=E> + Send + 'static,
S: SendServerPacket + std::fmt::Debug + Send + 'static, S: SendServerPacket + std::fmt::Debug + Send + 'static,
R: RecvServerPacket + 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 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 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); state_client_loop(state, server_state_receiver);
loop { loop {
@ -304,7 +304,7 @@ where
info!("new client {:?} {:?} {:?}", client_id, sock, addr); 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 socket = Arc::new(sock);
let cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {}))); let cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {})));
let cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {}))); let cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {})));

32
src/common/mainloop/interserver.rs

@ -49,12 +49,12 @@ impl MessageReceiver {
#[derive(Debug)] #[derive(Debug)]
enum InterserverInputAction<S, R> { enum InterserverInputAction<S, R> {
NewConnection(ServerId, async_std::sync::Sender<S>),
NewConnection(ServerId, async_std::channel::Sender<S>),
Message(ServerId, R), Message(ServerId, R),
Disconnect(ServerId), Disconnect(ServerId),
} }
async fn interserver_state_loop<A, S, R>(state: Arc<Mutex<A>>, action_receiver: async_std::sync::Receiver<InterserverInputAction<S, R>>)
async fn interserver_state_loop<A, S, R>(state: Arc<Mutex<A>>, action_receiver: async_std::channel::Receiver<InterserverInputAction<S, R>>)
where where
A: InterserverActor<SendMessage=S, RecvMessage=R, Error=()> + Send + 'static, A: InterserverActor<SendMessage=S, RecvMessage=R, Error=()> + Send + 'static,
S: Serialize + Send + 'static, S: Serialize + Send + 'static,
@ -114,8 +114,8 @@ where
async fn login_recv_loop<S, R>(server_id: ServerId, async fn login_recv_loop<S, R>(server_id: ServerId,
socket: async_std::net::TcpStream, socket: async_std::net::TcpStream,
state_loop_sender: async_std::sync::Sender<InterserverInputAction<S, R>>,
output_loop_sender: async_std::sync::Sender<S>)
state_loop_sender: async_std::channel::Sender<InterserverInputAction<S, R>>,
output_loop_sender: async_std::channel::Sender<S>)
where where
S: Serialize + std::fmt::Debug + Send + 'static, S: Serialize + std::fmt::Debug + Send + 'static,
R: DeserializeOwned + std::fmt::Debug + Send + 'static, R: DeserializeOwned + std::fmt::Debug + Send + 'static,
@ -129,7 +129,7 @@ where
match msg_receiver.recv().await { match msg_receiver.recv().await {
Ok(msg) => { Ok(msg) => {
info!("[login recv loop msg] {:?}", 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) => { Err(err) => {
if let MessageReceiverError::Disconnected = err { if let MessageReceiverError::Disconnected = err {
@ -146,7 +146,7 @@ where
async fn interserver_send_loop<S>(server_id: ServerId, async fn interserver_send_loop<S>(server_id: ServerId,
mut socket: async_std::net::TcpStream, mut socket: async_std::net::TcpStream,
output_loop_receiver: async_std::sync::Receiver<S>)
output_loop_receiver: async_std::channel::Receiver<S>)
where where
S: Serialize + std::fmt::Debug + Send + 'static, S: Serialize + std::fmt::Debug + Send + 'static,
{ {
@ -159,13 +159,13 @@ where
if let Ok(payload) = payload { if let Ok(payload) = payload {
let len_bytes = u32::to_le_bytes(payload.len() as u32); 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<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
let listener = async_std::net::TcpListener::bind(&std::net::SocketAddr::from((std::net::Ipv4Addr::new(0,0,0,0), port))).await.unwrap(); let listener = async_std::net::TcpListener::bind(&std::net::SocketAddr::from((std::net::Ipv4Addr::new(0,0,0,0), port))).await.unwrap();
let mut id = 0; 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; interserver_state_loop(state.clone(), server_state_receiver).await;
loop { loop {
@ -194,7 +194,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
id += 1; id += 1;
let server_id = crate::common::interserver::ServerId(id); let server_id = crate::common::interserver::ServerId(id);
let (client_sender, client_receiver) = async_std::sync::channel(64);
let (client_sender, client_receiver) = async_std::channel::bounded(64);
{ {
let mut state = state.lock().await; let mut state = state.lock().await;
@ -213,7 +213,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipServerState<EG>>>, ip: std::net::Ipv4Addr, port: u16) -> Pin<Box<dyn Future<Output = ()>>> { pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipServerState<EG>>>, ip: std::net::Ipv4Addr, port: u16) -> Pin<Box<dyn Future<Output = ()>>> {
Box::pin(async_std::task::spawn(async move { Box::pin(async_std::task::spawn(async move {
let mut id = 0; 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; interserver_state_loop(state.clone(), server_state_receiver).await;
@ -230,7 +230,7 @@ pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipS
id += 1; id += 1;
let server_id = crate::common::interserver::ServerId(id); let server_id = crate::common::interserver::ServerId(id);
info!("found loginserv: {:?} {:?}", server_id, socket); info!("found loginserv: {:?} {:?}", server_id, socket);
let (client_sender, client_receiver) = async_std::sync::channel(64);
let (client_sender, client_receiver) = async_std::channel::bounded(64);
{ {
let mut state = state.lock().await; let mut state = state.lock().await;

3
src/entity/gateway/inmemory.rs

@ -168,7 +168,8 @@ impl EntityGateway for InMemoryGateway {
async fn get_characters_by_user(&self, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> { async fn get_characters_by_user(&self, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
let characters = self.characters.lock().unwrap(); let characters = self.characters.lock().unwrap();
let mut chars = [None; 4];
const NONE: Option<CharacterEntity> = None;
let mut chars = [NONE; 4];
characters characters
.iter() .iter()
.filter(|(_, c)| c.user_id == user.id) .filter(|(_, c)| c.user_id == user.id)

2
src/entity/gateway/postgres/models.rs

@ -759,7 +759,7 @@ impl Into<EquippedEntity> for PgEquipped {
impl From<(CharacterEntityId, EquippedEntity)> for PgEquipped { impl From<(CharacterEntityId, EquippedEntity)> for PgEquipped {
fn from(char_equips: (CharacterEntityId, EquippedEntity)) -> PgEquipped { fn from(char_equips: (CharacterEntityId, EquippedEntity)) -> PgEquipped {
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), weapon: char_equips.1.weapon.map(|i| i.0 as i32),
armor: char_equips.1.armor.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), shield: char_equips.1.shield.map(|i| i.0 as i32),

3
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") 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) .bind(user.id.0)
.fetch(&self.pool); .fetch(&self.pool);
let mut result = [None; 4];
const NONE: Option<CharacterEntity> = None;
let mut result = [NONE; 4];
while let Some(character) = stream.try_next().await? { while let Some(character) = stream.try_next().await? {
let index = character.slot as usize; let index = character.slot as usize;
result[index] = Some(character.into()) result[index] = Some(character.into())

4
src/lib.rs

@ -1,9 +1,7 @@
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![feature(const_generics)]
#![feature(maybe_uninit_extra)] #![feature(maybe_uninit_extra)]
#![feature(const_in_array_repeat_expressions)]
#![feature(inline_const)]
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(or_patterns)]

4
src/ship/ship.rs

@ -390,9 +390,11 @@ pub struct Block {
impl Default for Block { impl Default for Block {
fn default() -> Block { fn default() -> Block {
const SNONE: Option<room::RoomState> = None;
const NONE: Rooms = [SNONE; MAX_ROOMS];
Block { Block {
client_location: Box::new(ClientLocation::default()), client_location: Box::new(ClientLocation::default()),
rooms: Box::new([None; MAX_ROOMS]),
rooms: Box::new(NONE),
} }
} }
} }

Loading…
Cancel
Save