pub async fn process_realm_event(
    &mut self,
    server: &std::sync::Arc<crate::Server>,
    db_id: i32,
    mut active_player: Option<(&crate::PlayerKey, &mut crate::player_state::MutablePlayerState)>,
    message: puzzleverse_core::RealmResponse,
  ) {
    match &message {
      puzzleverse_core::RealmResponse::NameChanged(name, in_directory) => {
        if let Err(e) = server.database.realm_rename(db_id, &name, *in_directory) {
          println!("Failed to update realm name: {}", e);
        }
      }
      puzzleverse_core::RealmResponse::SettingChanged(_, _) => {
        if let Err(e) = server.database.realm_push_settings(db_id, &self.settings) {
          println!("Failed to update realm settings: {}", e);
        }
      }
      puzzleverse_core::RealmResponse::MessagePosted { body, sender, timestamp } => {
        if let Err(e) = server.database.realm_chat_write(db_id, sender, body, timestamp) {
          println!("Failed to update realm name: {}", e);
        }
      }
      _ => (),
    }
    for player in self.active_players.keys() {
      if active_player.as_ref().map(|(id, _)| *id == player).unwrap_or(false) {
        active_player.as_mut().unwrap().1.connection.send(server, player, message.clone()).await;
      } else if let Some(state) = server.player_states.read("process_realm_event").await.get(player.clone()) {
        state.mutable.lock().await.connection.send(server, player, message.clone()).await
      }
    }
  }
/// Process an event sent by a client
Process an event sent by a client
Process an event sent by a client
pub async fn process_realm_event(
    &mut self,
    server: &std::sync::Arc<crate::Server>,
    db_id: i32,
    mut active_player: Option<(&crate::PlayerKey, &mut crate::player_state::MutablePlayerState)>,
    message: puzzleverse_core::RealmResponse,
  ) {
    match &message {
      puzzleverse_core::RealmResponse::NameChanged(name, in_directory) => {
        if let Err(e) = server.database.realm_rename(db_id, &name, *in_directory) {
          println!("Failed to update realm name: {}", e);
        }
      }
      puzzleverse_core::RealmResponse::SettingChanged(_, _) => {
        if let Err(e) = server.database.realm_push_settings(db_id, &self.settings) {
          println!("Failed to update realm settings: {}", e);
        }
      }
      puzzleverse_core::RealmResponse::MessagePosted { body, sender, timestamp } => {
        if let Err(e) = server.database.realm_chat_write(db_id, sender, body, timestamp) {
          println!("Failed to update realm name: {}", e);
        }
      }
      _ => (),
    }
    for player in self.active_players.keys() {
      if active_player.as_ref().map(|(id, _)| *id == player).unwrap_or(false) {
        active_player.as_mut().unwrap().1.connection.send(server, player, message.clone()).await;
      } else if let Some(state) = server.player_states.read("process_realm_event").await.get(player.clone()) {
        state.mutable.lock().await.connection.send(server, player, message.clone()).await
      }
    }
  }
pub async fn process_realm_event ( & mut self , server : & std :: sync :: Arc < crate :: Server > , db_id : i32 , mut active_player : Option < ( & crate :: PlayerKey , & mut crate :: player_state :: MutablePlayerState ) > , message : puzzleverse_core :: RealmResponse , ) { match & message { puzzleverse_core :: RealmResponse :: NameChanged ( name , in_directory ) => { if let Err ( e ) = server . database . realm_rename ( db_id , & name , * in_directory ) { println ! ( " " e ) ; } } puzzleverse_core :: RealmResponse :: SettingChanged ( _ , _ ) => { if let Err ( e ) = server . database . realm_push_settings ( db_id , & self . settings ) { println ! ( " " e ) ; } } puzzleverse_core :: RealmResponse :: MessagePosted { body , sender , timestamp } => { if let Err ( e ) = server . database . realm_chat_write ( db_id , sender , body , timestamp ) { println ! ( " " e ) ; } } _ => ( ) , } for player in self . active_players . keys ( ) { if active_player . as_ref ( ) . map ( | ( id , _ ) | * id == player ) . unwrap_or ( false ) { active_player . as_mut ( ) . unwrap ( ) . 1 . connection . send ( server , player , message . clone ( ) ) . await ; } else if let Some ( state ) = server . player_states . read ( " " ) . await . get ( player . clone ( ) ) { state . mutable . lock ( ) . await . connection . send ( server , player , message . clone ( ) ) . await } } }
Process an event sent by a client
Process an event sent by a client
&mut self
server
&std::sync::Arc<crate::Server>
db_id
i32
active_player
Option<(&crate::PlayerKey, &mut crate::player_state::MutablePlayerState)>
message
puzzleverse_core::RealmResponse
&mut self
server
&std::sync::Arc<crate::Server>
db_id
i32
active_player
Option<(&crate::PlayerKey, &mut crate::player_state::MutablePlayerState)>
message
puzzleverse_core::RealmResponse