fix some warnings

This commit is contained in:
Nikita Vilunov 2023-02-14 23:49:56 +01:00
parent 7dfe6e0295
commit 23898038e1
3 changed files with 11 additions and 29 deletions

View File

@ -220,7 +220,7 @@ impl PlayerRegistry {
}
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
}
}
@ -243,7 +243,7 @@ struct Player {
}
impl 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_clone = handle.clone();
let player = Player {
@ -290,7 +290,7 @@ impl Player {
async fn handle_cmd(&mut self, cmd: Cmd, connection_id: ConnectionId) {
match cmd {
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())
.await;
self.my_rooms.insert(room_id.clone(), room.clone());

View File

@ -35,7 +35,7 @@ async fn handle_socket(
config: ServerConfig,
mut stream: TcpStream,
socket_addr: SocketAddr,
mut players: PlayerRegistry,
players: PlayerRegistry,
rooms: RoomRegistry,
) -> Result<()> {
let (reader, writer) = stream.split();
@ -59,15 +59,7 @@ async fn handle_socket(
handle_registration(&mut reader, &mut writer).await;
match registered_user {
Ok(user) => {
handle_registered_socket(
config,
socket_addr,
players,
rooms,
&mut reader,
&mut writer,
user,
)
handle_registered_socket(config, players, rooms, &mut reader, &mut writer, user)
.await?;
}
Err(_) => {}
@ -102,7 +94,7 @@ async fn handle_registration<'a>(
}
let parsed = client_message(&buffer[..]);
match parsed {
Ok((rest, msg)) => {
Ok((_, msg)) => {
log::info!("Incoming IRC message: {msg:?}");
match msg {
ClientMessage::Nick { nickname } => {
@ -140,7 +132,6 @@ async fn handle_registration<'a>(
async fn handle_registered_socket<'a>(
config: ServerConfig,
socket_addr: SocketAddr,
mut players: PlayerRegistry,
rooms: RoomRegistry,
reader: &mut BufReader<ReadHalf<'a>>,
@ -232,7 +223,7 @@ async fn handle_registered_socket<'a>(
} else {
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();
},
update = connection.receiver.recv() => {
@ -287,14 +278,13 @@ async fn handle_incoming_message(
buffer: &[u8],
config: &ServerConfig,
user: &RegisteredUser,
rooms: &RoomRegistry,
user_handle: &mut PlayerConnection,
player_id: &PlayerId,
writer: &mut (impl AsyncWrite + Unpin),
) -> Result<()> {
let parsed = client_message(buffer);
match parsed {
Ok((rest, msg)) => match msg {
Ok((_, msg)) => match msg {
ClientMessage::Ping { token } => {
ServerMessage {
tags: vec![],

View File

@ -1,6 +1,3 @@
use futures_util::FutureExt;
use tokio::sync::oneshot::{channel, Sender};
use crate::prelude::*;
pub mod http;
@ -10,19 +7,14 @@ pub mod telemetry;
pub mod testkit;
pub struct Terminator {
signal: Sender<()>,
signal: Promise<()>,
completion: JoinHandle<Result<()>>,
}
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 }
}
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<()> {
match self.signal.send(()) {
Ok(()) => {}