forked from lavina/lavina
fix some warnings
This commit is contained in:
parent
7dfe6e0295
commit
23898038e1
|
@ -220,7 +220,7 @@ impl PlayerRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_to_player(&mut self, id: PlayerId) -> PlayerConnection {
|
pub async fn connect_to_player(&mut self, id: PlayerId) -> PlayerConnection {
|
||||||
let mut player_handle = self.get_or_create_player(id).await;
|
let player_handle = self.get_or_create_player(id).await;
|
||||||
player_handle.subscribe().await
|
player_handle.subscribe().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ struct Player {
|
||||||
}
|
}
|
||||||
impl Player {
|
impl Player {
|
||||||
fn launch(player_id: PlayerId, rooms: RoomRegistry) -> (PlayerHandle, JoinHandle<Player>) {
|
fn launch(player_id: PlayerId, rooms: RoomRegistry) -> (PlayerHandle, JoinHandle<Player>) {
|
||||||
let (tx, mut rx) = channel(32);
|
let (tx, rx) = channel(32);
|
||||||
let handle = PlayerHandle { tx };
|
let handle = PlayerHandle { tx };
|
||||||
let handle_clone = handle.clone();
|
let handle_clone = handle.clone();
|
||||||
let player = Player {
|
let player = Player {
|
||||||
|
@ -290,7 +290,7 @@ impl Player {
|
||||||
async fn handle_cmd(&mut self, cmd: Cmd, connection_id: ConnectionId) {
|
async fn handle_cmd(&mut self, cmd: Cmd, connection_id: ConnectionId) {
|
||||||
match cmd {
|
match cmd {
|
||||||
Cmd::JoinRoom { room_id, promise } => {
|
Cmd::JoinRoom { room_id, promise } => {
|
||||||
let mut room = self.rooms.get_or_create_room(room_id.clone());
|
let room = self.rooms.get_or_create_room(room_id.clone());
|
||||||
room.subscribe(self.player_id.clone(), self.handle.clone())
|
room.subscribe(self.player_id.clone(), self.handle.clone())
|
||||||
.await;
|
.await;
|
||||||
self.my_rooms.insert(room_id.clone(), room.clone());
|
self.my_rooms.insert(room_id.clone(), room.clone());
|
||||||
|
|
|
@ -35,7 +35,7 @@ async fn handle_socket(
|
||||||
config: ServerConfig,
|
config: ServerConfig,
|
||||||
mut stream: TcpStream,
|
mut stream: TcpStream,
|
||||||
socket_addr: SocketAddr,
|
socket_addr: SocketAddr,
|
||||||
mut players: PlayerRegistry,
|
players: PlayerRegistry,
|
||||||
rooms: RoomRegistry,
|
rooms: RoomRegistry,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (reader, writer) = stream.split();
|
let (reader, writer) = stream.split();
|
||||||
|
@ -59,16 +59,8 @@ async fn handle_socket(
|
||||||
handle_registration(&mut reader, &mut writer).await;
|
handle_registration(&mut reader, &mut writer).await;
|
||||||
match registered_user {
|
match registered_user {
|
||||||
Ok(user) => {
|
Ok(user) => {
|
||||||
handle_registered_socket(
|
handle_registered_socket(config, players, rooms, &mut reader, &mut writer, user)
|
||||||
config,
|
.await?;
|
||||||
socket_addr,
|
|
||||||
players,
|
|
||||||
rooms,
|
|
||||||
&mut reader,
|
|
||||||
&mut writer,
|
|
||||||
user,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +94,7 @@ async fn handle_registration<'a>(
|
||||||
}
|
}
|
||||||
let parsed = client_message(&buffer[..]);
|
let parsed = client_message(&buffer[..]);
|
||||||
match parsed {
|
match parsed {
|
||||||
Ok((rest, msg)) => {
|
Ok((_, msg)) => {
|
||||||
log::info!("Incoming IRC message: {msg:?}");
|
log::info!("Incoming IRC message: {msg:?}");
|
||||||
match msg {
|
match msg {
|
||||||
ClientMessage::Nick { nickname } => {
|
ClientMessage::Nick { nickname } => {
|
||||||
|
@ -140,7 +132,6 @@ async fn handle_registration<'a>(
|
||||||
|
|
||||||
async fn handle_registered_socket<'a>(
|
async fn handle_registered_socket<'a>(
|
||||||
config: ServerConfig,
|
config: ServerConfig,
|
||||||
socket_addr: SocketAddr,
|
|
||||||
mut players: PlayerRegistry,
|
mut players: PlayerRegistry,
|
||||||
rooms: RoomRegistry,
|
rooms: RoomRegistry,
|
||||||
reader: &mut BufReader<ReadHalf<'a>>,
|
reader: &mut BufReader<ReadHalf<'a>>,
|
||||||
|
@ -232,7 +223,7 @@ async fn handle_registered_socket<'a>(
|
||||||
} else {
|
} else {
|
||||||
len
|
len
|
||||||
};
|
};
|
||||||
handle_incoming_message(&buffer[0..len], &config, &user, &rooms, &mut connection, &player_id, writer).await?;
|
handle_incoming_message(&buffer[0..len], &config, &user, &mut connection, &player_id, writer).await?;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
},
|
},
|
||||||
update = connection.receiver.recv() => {
|
update = connection.receiver.recv() => {
|
||||||
|
@ -287,14 +278,13 @@ async fn handle_incoming_message(
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
config: &ServerConfig,
|
config: &ServerConfig,
|
||||||
user: &RegisteredUser,
|
user: &RegisteredUser,
|
||||||
rooms: &RoomRegistry,
|
|
||||||
user_handle: &mut PlayerConnection,
|
user_handle: &mut PlayerConnection,
|
||||||
player_id: &PlayerId,
|
player_id: &PlayerId,
|
||||||
writer: &mut (impl AsyncWrite + Unpin),
|
writer: &mut (impl AsyncWrite + Unpin),
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let parsed = client_message(buffer);
|
let parsed = client_message(buffer);
|
||||||
match parsed {
|
match parsed {
|
||||||
Ok((rest, msg)) => match msg {
|
Ok((_, msg)) => match msg {
|
||||||
ClientMessage::Ping { token } => {
|
ClientMessage::Ping { token } => {
|
||||||
ServerMessage {
|
ServerMessage {
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
use futures_util::FutureExt;
|
|
||||||
use tokio::sync::oneshot::{channel, Sender};
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub mod http;
|
pub mod http;
|
||||||
|
@ -10,19 +7,14 @@ pub mod telemetry;
|
||||||
pub mod testkit;
|
pub mod testkit;
|
||||||
|
|
||||||
pub struct Terminator {
|
pub struct Terminator {
|
||||||
signal: Sender<()>,
|
signal: Promise<()>,
|
||||||
completion: JoinHandle<Result<()>>,
|
completion: JoinHandle<Result<()>>,
|
||||||
}
|
}
|
||||||
impl Terminator {
|
impl Terminator {
|
||||||
pub fn from_raw(signal: Sender<()>, completion: JoinHandle<Result<()>>) -> Terminator {
|
pub fn from_raw(signal: Promise<()>, completion: JoinHandle<Result<()>>) -> Terminator {
|
||||||
Terminator { signal, completion }
|
Terminator { signal, completion }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(completion: JoinHandle<Result<()>>) -> (Terminator, impl Future<Output = ()>) {
|
|
||||||
let (signal, rx) = channel();
|
|
||||||
(Terminator { signal, completion }, rx.map(|_| ()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn terminate(self) -> Result<()> {
|
pub async fn terminate(self) -> Result<()> {
|
||||||
match self.signal.send(()) {
|
match self.signal.send(()) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
|
|
Loading…
Reference in New Issue