Skip to content

Commit 0041a0a

Browse files
authored
Merge pull request #28 from Kiiyya/yeet-diesel
Yeet-diesel
2 parents 3b3473e + e9a1e25 commit 0041a0a

File tree

19 files changed

+426
-547
lines changed

19 files changed

+426
-547
lines changed

.github/workflows/build-and-deploy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ jobs:
4545
OS: ubuntu-latest
4646
# - TARGET: x86_64-unknown-linux-musl # test in an alpine container on a mac
4747
# OS: ubuntu-latest
48-
# - TARGET: aarch64-unknown-linux-gnu # tested on aws t4g.nano
49-
# OS: ubuntu-latest
50-
# - TARGET: aarch64-unknown-linux-musl # tested on aws t4g.nano in alpine container
51-
# OS: ubuntu-latest
48+
- TARGET: aarch64-unknown-linux-gnu # tested on aws t4g.nano
49+
OS: ubuntu-latest
50+
- TARGET: aarch64-unknown-linux-musl # tested on aws t4g.nano in alpine container
51+
OS: ubuntu-latest
5252
# - TARGET: armv7-unknown-linux-gnueabihf # raspberry pi 2-3-4, not tested
5353
# OS: ubuntu-latest
5454
# - TARGET: armv7-unknown-linux-musleabihf # raspberry pi 2-3-4, not tested

Cargo.lock

Lines changed: 13 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

battlefield_rcon/src/bf4/map_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn parse_map_list(words: &[AsciiString]) -> RconResult<Vec<MapListEntry>> {
3939
words.len() - offset
4040
)));
4141
}
42-
let mut ret = Vec::with_capacity(n_maps as usize);
42+
let mut ret = Vec::with_capacity(n_maps);
4343

4444
for _ in 0..n_maps {
4545
ret.push(MapListEntry {

battlefox/src/ban_enforcer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use async_trait::async_trait;
55
use battlefield_rcon::bf4::ban_list::{Ban, BanTimeout};
66
use battlefield_rcon::bf4::{Bf4Client, Event, BanListError, PlayerKickError};
77
use battlefield_rcon::rcon::RconResult;
8-
use battlefox_database::better::{BfoxDb, OffsetDateTime, BanStatus};
8+
use battlefox_database::{BfoxContext, DateTime};
9+
use battlefox_database::adkats::bans::BanStatus;
910
use serde::{Deserialize, Serialize};
1011

1112
use crate::Plugin;
@@ -18,11 +19,11 @@ pub struct Config {
1819

1920
pub struct BanEnforcer {
2021
config: Config,
21-
db: BfoxDb,
22+
db: BfoxContext,
2223
}
2324

2425
impl BanEnforcer {
25-
pub fn new(config: Config, _players: Arc<Players>, db: BfoxDb) -> Self {
26+
pub fn new(config: Config, _players: Arc<Players>, db: BfoxContext) -> Self {
2627
Self { config, db }
2728
}
2829

@@ -33,7 +34,7 @@ impl BanEnforcer {
3334
match self.db.get_ban(format!("{}", player.eaid)).await {
3435
Ok(Some(ban)) => {
3536
let banned = if ban.status == BanStatus::Active {
36-
let now = OffsetDateTime::now_utc();
37+
let now = DateTime::now_utc();
3738
let is_banned_time = now < ban.end;
3839

3940
if !is_banned_time {

battlefox/src/main.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
#[macro_use] extern crate multimap;
77
extern crate battlelog;
88

9-
use anyhow::Context;
109
use ascii::{IntoAsciiString};
1110
use async_trait::async_trait;
1211
use battlefield_rcon::bf4::Event;
1312
use battlefield_rcon::bf4::error::Bf4Error;
1413
use battlefield_rcon::rcon::RconResult;
15-
use battlefox_database::better::BfoxDb;
14+
use battlefox_database::BfoxContext;
1615
use dotenv::dotenv;
1716
use futures::StreamExt;
1817
use itertools::Itertools;
@@ -85,12 +84,6 @@ fn get_rcon_coninfo() -> anyhow::Result<RconConnectionInfo> {
8584
})
8685
}
8786

88-
fn get_db_coninfo() -> anyhow::Result<String> {
89-
let uri = var("DATABASE_URL")
90-
.context("Need to specify AdKats db URI via env var, for example DATABASE_URL=\"mysql://username:password@host/database\"")?;
91-
Ok(uri)
92-
}
93-
9487
#[derive(Error, Debug)]
9588
enum ConfigError {
9689
#[error("Failed to deserialize config.")]
@@ -190,12 +183,12 @@ impl App {
190183
}
191184

192185
fn has_plugin<P: Plugin, C: DeserializeOwned>(&mut self, f: impl FnOnce(C) -> P) -> Result<Arc<P>, ConfigError> {
193-
let config: C = load_config(&format!("configs/{}.yaml", P::NAME))?;
186+
let config: C = load_config(format!("configs/{}.yaml", P::NAME))?;
194187
self.has_plugin_noconfig(f(config))
195188
}
196189

197190
fn has_plugin_arc<P: Plugin, C: DeserializeOwned>(&mut self, f: impl FnOnce(C) -> Arc<P>) -> Result<Arc<P>, ConfigError> {
198-
let config: C = load_config(&format!("configs/{}.yaml", P::NAME))?;
191+
let config: C = load_config(format!("configs/{}.yaml", P::NAME))?;
199192
let p = f(config);
200193
let exists = self.plugins.insert(P::NAME.to_string(), p.clone());
201194
if exists.is_some() {
@@ -245,9 +238,9 @@ async fn main() -> anyhow::Result<()> {
245238
let _ = UPTIME.elapsed(); // get it, so that it initializes with `Instant::now()`.
246239

247240
let rconinfo = get_rcon_coninfo()?;
248-
let adkatsinfo = get_db_coninfo()?;
249241

250-
let db = BfoxDb::new(&adkatsinfo).await?;
242+
// TODO: Disable DB potentially.
243+
let db = BfoxContext::new_env();
251244

252245
// Initialize plugins and their dependencies.
253246
let mut app = App::new();
@@ -257,7 +250,7 @@ async fn main() -> anyhow::Result<()> {
257250
let _weaponforcer = app.has_plugin(WeaponEnforcer::new)?;
258251
let _loadoutenforcer = app.has_plugin(LoadoutEnforcer::new)?;
259252
// let _playerreport = app.has_plugin(|c| PlayerReport::new(players.clone(), rabbitmq, c))?;
260-
let _playermute = app.has_plugin(|c| PlayerMute::new(players.clone(), c))?;
253+
let _playermute = app.has_plugin(|c| PlayerMute::new(db.clone(), players.clone(), c))?;
261254
let mapman = app.has_plugin(MapManager::new)?;
262255
let _mapvote = app.has_plugin_arc(|c: MapVoteConfigJson|
263256
Mapvote::new(mapman, vips, players.clone(), admins.clone(), MapVoteConfig::from_json(c))

0 commit comments

Comments
 (0)