Skip to content

Commit 4e4222d

Browse files
committed
support other platforms and add serverid stuff for bf2042
1 parent 4cac1b7 commit 4e4222d

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ENV guild default_guild_value
1616
ENV lang 'en-us'
1717
ENV guid 'none'
1818
ENV ownerId 'none'
19+
ENV platform 'pc'
1920

2021
HEALTHCHECK --interval=5m --timeout=3s --start-period=5s \
2122
CMD curl -f http://127.0.0.1:3030/ || exit 1

Readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ game: game name (tunguska, casablanca, kingston, bf4)
1010
ownerId: server owner playerid (optional for casablanca and kingston)
1111
fakeplayers: removes bots on bf4's playercount if set to yes (optional, default no)
1212
name: servername
13-
lang: language (en-us)
13+
lang: language (default en-us)
14+
platform: from which platform is the server (default pc)
1415

1516
for status in discord:
1617
minplayeramount: amount of change needed to count
@@ -30,6 +31,7 @@ export prevrequestcount=5
3031
export channel=0
3132
export startedamount=50
3233
export game=tunguska
34+
export platform=pc
3335
cargo run
3436
```
3537

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl EventHandler for Handler {
3636
server_id: env::var("guid").unwrap_or_else(|_| "none".to_string()),
3737
game: env::var("game").unwrap_or_else(|_| "tunguska".to_string()),
3838
owner_id: env::var("ownerId").unwrap_or_else(|_| "none".to_string()),
39+
platform: env::var("platform").unwrap_or_else(|_| "pc".to_string()),
3940
fake_players: env::var("fakeplayers").unwrap_or_else(|_| "no".to_string()),
4041
server_name: env::var("name")
4142
.expect("name wasn't given an argument!")

src/message.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use serenity::{client::Context, model::id::ChannelId};
42
use anyhow::Result;
53
use super::server_info;
@@ -17,6 +15,7 @@ pub struct Global {
1715
pub struct Static {
1816
pub server_id: String,
1917
pub game: String,
18+
pub platform: String,
2019
pub owner_id: String,
2120
pub fake_players: String,
2221
pub server_name: String,
@@ -91,14 +90,27 @@ pub async fn check(ctx: Context, status: server_info::ServerInfo, mut globals: G
9190
pub async fn send(ctx: Context, statics: Static, image_url: &str, status: server_info::ServerInfo, title: &str,
9291
description: &str) -> Result<serenity::model::channel::Message, serenity::Error> {
9392
let paths = vec![image_url];
94-
let games = HashMap::from([
93+
let games = std::collections::HashMap::from([
9594
("tunguska", "bf1"),
9695
("casablanca", "bfv"),
9796
("kingston", "bf2042"),
9897
]);
98+
let mut gather_type = "gameid";
99+
if statics.game == "kingston" {
100+
gather_type = "serverid";
101+
} else if status.game_id.clone().unwrap_or_default().contains(":") {
102+
gather_type = "serverip";
103+
}
104+
let server_link = format!(
105+
"https://gametools.network/servers/{}/{}/{}/{}",
106+
games.get(&statics.game[..]).unwrap_or(&&statics.game[..]),
107+
gather_type,
108+
status.game_id.clone().unwrap_or_default(),
109+
statics.platform
110+
);
99111
ChannelId(statics.message_channel).send_files(&ctx.http, paths, |m| {
100112
m.embed(|e| {
101-
e.url(format!("https://gametools.network/servers/{}/gameid/{}/pc", games.get(&statics.game[..]).unwrap_or(&&statics.game[..]), status.game_id.unwrap_or_default()));
113+
e.url(server_link);
102114
e.title(title);
103115
e.description(description);
104116
e.footer(|f| {

src/server_info.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct MainInfo {
3838
pub owner_id: Option<String>,
3939
#[serde(rename = "serverId")]
4040
pub server_id: Option<String>,
41+
pub ip: Option<String>,
42+
pub port: Option<String>,
4143
}
4244
#[derive(Serialize, Deserialize, Debug, Clone)]
4345
pub struct DetailedInfo {
@@ -180,9 +182,21 @@ async fn get(statics: message::Static, game_id: &String) -> Result<ServerInfo> {
180182
// update game_id if it can be gathered
181183
let mut game_id = game_id.to_string();
182184
if !info.is_null() {
183-
game_id = serde_json::from_value::<MainInfo>(info.clone())?
184-
.game_id
185-
.unwrap_or_default();
185+
let server_info = serde_json::from_value::<MainInfo>(info.clone())?;
186+
if game == "bf2042" {
187+
game_id = server_info.server_id.unwrap_or_default();
188+
} else if server_info.game_id.is_none()
189+
&& server_info.ip.is_some()
190+
&& server_info.port.is_some()
191+
{
192+
game_id = format!(
193+
"{}:{}",
194+
server_info.ip.unwrap_or_default(),
195+
server_info.port.unwrap_or_default()
196+
);
197+
} else {
198+
game_id = server_info.game_id.unwrap_or_default();
199+
}
186200
}
187201

188202
// get detailed via old or new game_id

0 commit comments

Comments
 (0)