You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: system.rs
    path of file: ./repos/mk48/engine/game_server/src
    
    the code of the file until where you have to start completion: // SPDX-FileCopyrightText: 2021 Softbear, Inc.
// SPDX-License-Identifier: AGPL-3.0-or-later

use crate::game_service::GameArenaService;
use crate::infrastructure::Infrastructure;
use crate::status::StatusRepo;
use crate::util::diff_small_n;
use actix::fut::wrap_future;
use actix::{
    ActorFutureExt, ActorStreamExt, Context as ActorContext, ContextFutureSpawner, Handler,
    Message, WrapFuture, WrapStream,
};
use core_protocol::dto::ServerDto;
use core_protocol::id::{InvitationId, RegionId, ServerId};
use core_protocol::rpc::{StatusResponse, SystemResponse, SystemUpdate};
use db_ip::{include_region_database, DbIpDatabase, Region};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use log::{error, info, warn};
use rand::prelude::IteratorRandom;
use rand::{threa
    
    fn handle(&mut self, request: SystemRequest, _: &mut Self::Context) -> Self::Result {
        let invitation_server_id = request.invitation_id.and_then(|id| id.server_id());
        let ideal_region_id = request
            .region_id
            .or_else(|| SystemRepo::<G>::ip_to_region_id(request.ip));

        let ideal_server_id = SystemRepo::iter_server_priorities(
            &self.system,
            request.server_id,
            invitation_server_id,
            ideal_region_id,
        )
        .min_by_key(|&(_, priority, player_count)| {
            (
                priority,
                if self.admin.distribute_load {
                    player_count
                } else {
                    0
                },
            )
        })
        .map(
            |(ideal_server_id, ideal_server_priority, ideal_server_player_count)| {
                if self.admin.distribute_load {
                    let mut rng = thread_rng();

                    // Prime the RNG a bit.
                    let use_player_count = rng.gen::<bool>();
                    rng.gen::<u64>();

                    let result = SystemRepo::iter_server_priorities(
                        &self.system,
                        request.server_id,
                        invitation_server_id,
                        ideal_region_id,
                    )
                    .filter(|&(_, priority, player_count)| {
                        priority == ideal_server_priority
                            && (!use_player_count || player_count == ideal_server_player_count)
                    })
                    .map(|(server_id, _, _)| server_id)
                    .choose(&mut rng);

                    if let Some(result) = result {
                        result
                    } else {
                        debug_assert!(false, "server id rug pull");
                        ideal_server_id
                    }
                } else {
                    ideal_server_id
                }
            },
        );

        SystemResponse {
            server_id: ideal_server_id.or(self.server_id),
            //servers: self.system.as_ref().map(|system| Arc::clone(system.previous)).unwrap_or_else(|| Vec::new().into())
        }
    }