1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::types::{Game, Region};
use super::constants::UID_RANGE;

pub(crate) fn recognize_genshin_server(uid: &u32) -> anyhow::Result<String> {
    let server = match uid.to_string().char_indices().nth(0).unwrap().1.to_string().as_str() {
        "1" => "cn_gf01",
        "2" => "cn_gf01",
        "5" => "cn_qd01",
        "6" => "os_usa",
        "7" => "os_euro",
        "8" => "os_asia",
        "9" => "os_cht",
        _ => anyhow::bail!("uid doesn't much the server number like smthing"),
    };
    Ok(server.to_string())
}


pub(crate) fn recognize_honkai_server(uid: &u32) -> anyhow::Result<String> {
    let uid = uid.clone();
    let server = if 10000000 < uid && uid < 100000000 {
        "overseas01"
    } else if 100000000 < uid && uid < 200000000 {
        "usa01"
    } else if 200000000 < uid && uid < 300000000 {
        "eur01"
    } else {
        anyhow::bail!("uid doesn't much the server number like smthing")
    };
    Ok(server.to_string())
}


pub(crate) fn recognize_starrail_server(uid: &u32) -> anyhow::Result<String> {
    let server = match uid.to_string().char_indices().nth(0).unwrap().1.to_string().as_str() {
        "1" => "prod_gf_cn",
        "2" => "prod_gf_cn",
        "5" => "prod_qd_cn",
        "6" => "prod_official_usa",
        "7" => "prod_official_eur",
        "8" => "prod_official_asia",
        "9" => "prod_official_cht",
        _ => anyhow::bail!("uid doesn't much the server number like smthing"),
    };
    Ok(server.to_string())
}


pub(crate) fn recognize_server(uid: &u32, game: Game) -> anyhow::Result<String> {
    match game {
        Game::GENSHIN => {
            recognize_genshin_server(uid)
        }
        Game::HONKAI => {
            recognize_honkai_server(uid)
        }
        Game::STARRAIL => {
            recognize_starrail_server(uid)
        }
    }
}



pub(crate) fn recognize_region(uid: &mut u32, game: Game) -> Option<Region> {
    let first = &uid.to_string()[0..1].parse::<u8>().unwrap();
    for (region, dict) in UID_RANGE.get(&game).unwrap() {
        if dict.contains(first) {
            return Some(region.clone())
        }
    }
    None
}