forked from lavina/lavina
Compare commits
2 Commits
43ea27b655
...
53f218c58f
Author | SHA1 | Date |
---|---|---|
JustTestingV | 53f218c58f | |
Nikita Vilunov | 377d9c32d2 |
|
@ -78,7 +78,7 @@ impl Storage {
|
|||
|
||||
pub async fn insert_message(&mut self, room_id: u32, id: u32, content: &str) -> Result<()> {
|
||||
let mut executor = self.conn.lock().await;
|
||||
let (_,): (u32,) = sqlx::query_as(
|
||||
sqlx::query(
|
||||
"insert into messages(room_id, id, content)
|
||||
values (?, ?, ?);
|
||||
update rooms set message_count = message_count + 1 where id = ?;",
|
||||
|
@ -87,7 +87,7 @@ impl Storage {
|
|||
.bind(id)
|
||||
.bind(content)
|
||||
.bind(room_id)
|
||||
.fetch_one(&mut *executor)
|
||||
.execute(&mut *executor)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -140,7 +140,10 @@ impl RoomHandle {
|
|||
|
||||
pub async fn send_message(&self, player_id: PlayerId, body: Str) {
|
||||
let mut lock = self.0.write().await;
|
||||
lock.send_message(player_id, body).await;
|
||||
let res = lock.send_message(player_id, body).await;
|
||||
if let Err(err) = res {
|
||||
log::warn!("Failed to send message: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_room_info(&self) -> RoomInfo {
|
||||
|
@ -200,6 +203,7 @@ impl Room {
|
|||
}
|
||||
|
||||
async fn broadcast_update(&self, update: Updates, except: &PlayerId) {
|
||||
tracing::debug!("Broadcasting an update to {} subs", self.subscriptions.len());
|
||||
for (player_id, sub) in &self.subscriptions {
|
||||
if player_id == except {
|
||||
continue;
|
||||
|
|
|
@ -528,7 +528,17 @@ async fn handle_incoming_message(
|
|||
.await?;
|
||||
writer.flush().await?;
|
||||
} else {
|
||||
// TODO send 502 (not 401) if the user is not the sender
|
||||
ServerMessage {
|
||||
tags: vec![],
|
||||
sender: Some(config.server_name.clone()),
|
||||
body: ServerMessageBody::N502UsersDontMatch {
|
||||
client: user.nickname.clone(),
|
||||
message: "Cant change mode for other users".into(),
|
||||
},
|
||||
}
|
||||
.write_async(writer)
|
||||
.await?;
|
||||
writer.flush().await?;
|
||||
}
|
||||
}
|
||||
Recipient::Chan(_) => {
|
||||
|
|
|
@ -132,6 +132,10 @@ pub enum ServerMessageBody {
|
|||
chan: Chan,
|
||||
message: Str,
|
||||
},
|
||||
N502UsersDontMatch {
|
||||
client: Str,
|
||||
message: Str,
|
||||
},
|
||||
}
|
||||
|
||||
impl ServerMessageBody {
|
||||
|
@ -301,6 +305,13 @@ impl ServerMessageBody {
|
|||
writer.write_all(b" :").await?;
|
||||
writer.write_all(message.as_bytes()).await?;
|
||||
}
|
||||
ServerMessageBody::N502UsersDontMatch { client, message } => {
|
||||
writer.write_all(b"502 ").await?;
|
||||
writer.write_all(client.as_bytes()).await?;
|
||||
writer.write_all(b" ").await?;
|
||||
writer.write_all(b" :").await?;
|
||||
writer.write_all(message.as_bytes()).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue