Skip to content

Commit

Permalink
allow bfv marne gathering
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Feb 17, 2024
1 parent 6c5a8d3 commit bdd2209
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 29 deletions.
66 changes: 54 additions & 12 deletions src/gatherer/bf1_marne.rs → src/gatherer/marne.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use crate::{
connectors::{influx_db, timescale_db::push_server},
structs::{
bf1_marne::{MarneServerInfo, MarneServerList},
marne::{MarneServerInfo, MarneServerList},
results, server_info,
},
};
use chrono::Utc;
use sqlx::PgPool;
use std::collections::HashMap;

async fn gather_servers() -> Vec<crate::structs::bf1_marne::MarneServerInfo> {
async fn gather_servers(game: &str) -> Vec<crate::structs::marne::MarneServerInfo> {
let client = reqwest::Client::new();
let url = "https://marne.io/api/srvlst/";
let url = match game {
"bfv" => "https://marne.io/api/v/srvlst/",
_ => "https://marne.io/api/srvlst/",
};
match client.get(url).send().await {
Ok(resp) => {
let json_string = resp.text().await.unwrap_or_default();
Expand All @@ -20,13 +23,13 @@ async fn gather_servers() -> Vec<crate::structs::bf1_marne::MarneServerInfo> {
return json_res.servers;
}
Err(e) => {
log::error!("Bf1 marne public json is incorrect: {:#?}", e);
log::error!("{} marne public json is incorrect: {:#?}", game, e);
return vec![];
}
}
}
Err(e) => {
log::error!("Bf1 marne public url failed: {:#?}", e);
log::error!("{} marne public url failed: {:#?}", game, e);
return vec![];
}
}
Expand Down Expand Up @@ -77,6 +80,41 @@ async fn server_list_to_sum(
),
("Xpack4/Levels/MP/MP_Offensive/MP_Offensive", "River Somme"),
("Xpack4/Levels/MP/MP_River/MP_River", "Caporetto"),
// BFV
// MP_ArcticFjell: "Fjell 652",
// MP_ArcticFjord: "Narvik",
("Levels/MP/MP_Arras/MP_Arras", "Arras"),
// MP_Devastation: "Devastation",
// MP_Escaut: "twisted steel",
// MP_Foxhunt: "Aerodrome",
// MP_Halfaya: "Hamada",
// MP_Rotterdam: "Rotterdam",
// MP_Hannut: "Panzerstorm",
// MP_Crete: "Mercury",
(
"Live/Greece/Kalamas/Levels/MP/MP_Kalamas/MP_Kalamas",
"Marita",
),
// MP_Provence: "Provence",
// MP_SandAndSea: "Al sudan",
// MP_Bunker: "Operation Underground",
("Live/Pacific/Levels/MP/MP_IwoJima/MP_IwoJima", "Iwo jima"),
// MP_TropicIslands: "Pacific storm",
// MP_WakeIsland: "Wake island",
// MP_Jungle: "Solomon islands",
// MP_Libya: "Al marj encampment",
// MP_Norway: "lofoten islands",
// bfv special maps
// DK_Norway: "Halvoy",
// MP_Escaut_US: "Twisted Steel US",
// MP_Hannut_US: "Panzerstorm US",
// MP_GOps_Chapter2_Arras: "Arras (Chapter 2)",
// MP_WE_Fortress_Devastation: "Devastation (Fortress)",
// MP_WE_Fortress_Halfaya: "Hamada (Fortress)",
// MP_WE_Grind_ArcticFjord: "Narvik (Grind)",
// MP_WE_Grind_Devastation: "Devastation (Grind)",
// MP_WE_Grind_Escaut: "Twisted Steel (Grind)",
// MP_WE_Grind_Rotterdam: "Rotterdam (Grind)",
]);

let modes = HashMap::from([
Expand Down Expand Up @@ -239,30 +277,34 @@ async fn server_list_to_sum(
(regions, server_stats)
}

pub async fn push_bf1_marne(
pub async fn push_marne(
game: &str,
pool: &PgPool,
influx_client: &influxdb2::Client,
) -> anyhow::Result<results::RegionResult> {
let found_servers = gather_servers().await;
let found_servers = gather_servers(game).await;
let (regions, server_stats) = server_list_to_sum(found_servers).await;
for (region, server_stat) in server_stats {
match push_server(pool, "bf1_marne", &region, "pc", server_stat).await {
match push_server(pool, &format!("{}_marne", game), &region, "pc", server_stat).await {
Ok(_) => {}
Err(e) => log::error!(
"BF1 Marne region {} failed to push specific serverinfo: {:#?}",
"{} Marne region {} failed to push specific serverinfo: {:#?}",
game,
region,
e
),
};
}
match influx_db::push_to_database(influx_client, "bf1_marne", "pc", &regions).await {
match influx_db::push_to_database(influx_client, &format!("{}_marne", game), "pc", &regions)
.await
{
Ok(_) => {}
Err(e) => log::error!("BF1 Marne failed to push to influxdb: {:#?}", e),
Err(e) => log::error!("{} Marne failed to push to influxdb: {:#?}", game, e),
};

let result = match regions.get("ALL") {
Some(result) => result,
None => anyhow::bail!("BF1 Marne has no ALL region!"),
None => anyhow::bail!("{} Marne has no ALL region!", game),
};
Ok(result.to_owned())
}
2 changes: 1 addition & 1 deletion src/gatherer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod battlebit;
pub mod battlefield_grpc;
pub mod battlelog;
pub mod bf1_marne;
pub mod companion;
pub mod marne;
pub mod old_games;
pub mod server_manager;
23 changes: 12 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod structs;
use crate::connectors::influx_db;
use bf_sparta::{cookie_request, sparta_api};
use connectors::mongo::MongoClient;
use gatherer::{battlebit, battlefield_grpc, battlelog, bf1_marne, companion, old_games};
use gatherer::{battlebit, battlefield_grpc, battlelog, companion, marne, old_games};
use influxdb2::Client;
use sqlx::postgres::PgPool;
use std::{
Expand Down Expand Up @@ -233,16 +233,17 @@ async fn main() -> anyhow::Result<()> {
}
};
log::info!("grpc done");

match bf1_marne::push_bf1_marne(&pool, &influx_client).await {
Ok(game_result) => {
game_results.insert("bf1_marne".to_string(), game_result);
}
Err(e) => {
log::error!("BF1 Marne failed with reason: {:#?}", e);
}
};
log::info!("BF1 Marne done");
for game in vec!["bf1", "bfv"] {
match marne::push_marne(game, &pool, &influx_client).await {
Ok(game_result) => {
game_results.insert(format!("{}_marne", game), game_result);
}
Err(e) => {
log::error!("{} Marne failed with reason: {:#?}", game, e);
}
};
}
log::info!("Marne done");

// if no games failed, make global array
if failed_games.iter().any(|&value| {
Expand Down
4 changes: 0 additions & 4 deletions src/structs/bf1_marne.rs → src/structs/marne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ pub struct MarneServerInfo {
pub need_same_mods: i64,
#[serde(rename = "allowMoreMods")]
pub allow_more_mods: i64,
#[serde(rename = "modList")]
pub mod_list: ModType,
#[serde(rename = "playerList")]
pub player_list: PlayerType,
#[serde(rename = "currentPlayers")]
pub current_players: i64,
pub region: String,
Expand Down
2 changes: 1 addition & 1 deletion src/structs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod battlebit;
pub mod battlelog;
pub mod bf1_marne;
pub mod companion;
pub mod game_players;
pub mod marne;
pub mod old_games;
pub mod results;
pub mod server_info;

0 comments on commit bdd2209

Please sign in to comment.