fn process_commands(&mut self) {
        while let Ok(Event::Client(id, event)) = self.rx.try_recv() {
            tracing::trace!("Processing command: {:?}", event);

            match event {
                ClientEvent::Connect(mut player, _) => {
                    self.send_event(
                        id,
                        GameEvent::Accepted(Response::Client(format!(
                            "\n{}{}{}\n",
                            "Welcome back, ".foreground(YELLOW),
                            player.name.foreground(CYAN),
                            "!".foreground(YELLOW),
                        ))),
                    );

                    player._entityid = self.next_id();

                    self.players.insert(player);
                    self.timer.last_action = Instant::now()
                        .duration_since(self.timer.start_time)
                        .as_secs();
                }
                ClientEvent::Disconnect => {
                    if let Ok(player) = self.get_player(id) {
                        // Sends a Save event to the broker which will handle the actual database
                        // update. We only send this if the player is marked for saving; same
                        // as global save.
                        if player.dirty {
                            self.send_event(id, GameEvent::Save(player.clone()));
                        }

                        self.active_entities -= 1;

                        // Remove the player from the world
                        self.players.remove(&id);
                        self.timer.last_action = Instant::now()
                            .duration_since(self.timer.start_time)
                            .as_secs();
                    }
                }
                ClientEvent::Ping => self.send_prompt(id),
                ClientEvent::Command(tokens) => {
                    let result = match self.command_map.get(&tokens.command) {
                        Some(i) => {
                            let mut commands = std::mem::take(&mut self.commands);
                            let func = &mut commands[*i].func;
                            let result = (func)(Context::new(id, tokens, self));
                            self.commands = commands;

                            result
                        }
                        None => self.unknown(id),
                    };

                    if let Ok(response) = result {
                        self.send_command(id, response);
                    }

                    self.send_prompt(id);

                    self.timer.last_action = Instant::now()
                        .duration_since(self.timer.start_time)
                        .as_secs();
                }
            }
        }
    }
/// Loops through commands received from the broker and processes them. Note that this is not
/// ONLY for game-specific commands, but all peer-sent messages that are valid and parsed as
/// an Input struct. This includes connecting and disconnecting.
Loops through commands received from the broker and processes them. Note that this is not
ONLY for game-specific commands, but all peer-sent messages that are valid and parsed as
an Input struct. This includes connecting and disconnecting.
Loops through commands received from the broker and processes them . Note that this is not ONLY for game - specific commands but all peer - sent messages that are valid and parsed as an Input struct . This includes connecting and disconnecting .
fn process_commands(&mut self) {
        while let Ok(Event::Client(id, event)) = self.rx.try_recv() {
            tracing::trace!("Processing command: {:?}", event);
            match event {
                ClientEvent::Connect(mut player, _) => {
                    self.send_event(
                        id,
                        GameEvent::Accepted(Response::Client(format!(
                            "\n{}{}{}\n",
                            "Welcome back, ".foreground(YELLOW),
                            player.name.foreground(CYAN),
                            "!".foreground(YELLOW),
                        ))),
                    );
                    player._entityid = self.next_id();
                    self.players.insert(player);
                    self.timer.last_action = Instant::now()
                        .duration_since(self.timer.start_time)
                        .as_secs();
                }
                ClientEvent::Disconnect => {
                    if let Ok(player) = self.get_player(id) {
                        // Sends a Save event to the broker which will handle the actual database
                        // update. We only send this if the player is marked for saving; same
                        // as global save.
                        if player.dirty {
                            self.send_event(id, GameEvent::Save(player.clone()));
                        }
                        self.active_entities -= 1;
                        // Remove the player from the world
                        self.players.remove(&id);
                        self.timer.last_action = Instant::now()
                            .duration_since(self.timer.start_time)
                            .as_secs();
                    }
                }
                ClientEvent::Ping => self.send_prompt(id),
                ClientEvent::Command(tokens) => {
                    let result = match self.command_map.get(&tokens.command) {
                        Some(i) => {
                            let mut commands = std::mem::take(&mut self.commands);
                            let func = &mut commands[*i].func;
                            let result = (func)(Context::new(id, tokens, self));
                            self.commands = commands;
                            result
                        }
                        None => self.unknown(id),
                    };
                    if let Ok(response) = result {
                        self.send_command(id, response);
                    }
                    self.send_prompt(id);
                    self.timer.last_action = Instant::now()
                        .duration_since(self.timer.start_time)
                        .as_secs();
                }
            }
        }
    }
fn process_commands ( & mut self ) { while let Ok ( Event :: Client ( id , event ) ) = self . rx . try_recv ( ) { tracing :: trace ! ( " " event ) ; match event { ClientEvent :: Connect ( mut player , _ ) => { self . send_event ( id , GameEvent :: Accepted ( Response :: Client ( format ! ( " \n \n " " " foreground ( YELLOW ) player name foreground ( CYAN ) " " foreground ( YELLOW ) ) ) ) , ) ; player . _entityid = self . next_id ( ) ; self . players . insert ( player ) ; self . timer . last_action = Instant :: now ( ) . duration_since ( self . timer . start_time ) . as_secs ( ) ; } ClientEvent :: Disconnect => { if let Ok ( player ) = self . get_player ( id ) { // Sends a Save event to the broker which will handle the actual database // update. We only send this if the player is marked for saving; same // as global save. if player . dirty { self . send_event ( id , GameEvent :: Save ( player . clone ( ) ) ) ; } self . active_entities -= 1 ; // Remove the player from the world self . players . remove ( & id ) ; self . timer . last_action = Instant :: now ( ) . duration_since ( self . timer . start_time ) . as_secs ( ) ; } } ClientEvent :: Ping => self . send_prompt ( id ) , ClientEvent :: Command ( tokens ) => { let result = match self . command_map . get ( & tokens . command ) { Some ( i ) => { let mut commands = std :: mem :: take ( & mut self . commands ) ; let func = & mut commands [ * i ] . func ; let result = ( func ) ( Context :: new ( id , tokens , self ) ) ; self . commands = commands ; result } None => self . unknown ( id ) , } ; if let Ok ( response ) = result { self . send_command ( id , response ) ; } self . send_prompt ( id ) ; self . timer . last_action = Instant :: now ( ) . duration_since ( self . timer . start_time ) . as_secs ( ) ; } } } }
Loops through commands received from the broker and processes them.
Loops through commands received from the broker and processes them .
&mut self
&mut self