Skip to content

Commit

Permalink
closes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Razer2015 committed Dec 6, 2022
1 parent 7b525cf commit 0ba710c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions battlefox/configs/mapvote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ enabled: true
n_options: 4
max_options: 6
max_noms_per_vip: 1
vote_start_interval: 30
spammer_interval: 180
endscreen_votetime: 15
endscreen_post_votetime: 5
Expand Down
32 changes: 26 additions & 6 deletions battlefox/src/mapvote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ impl Plugin for Mapvote {
async fn event(self: Arc<Self>, bf4: Arc<Bf4Client>, event: Event) -> RconResult<()> {
match event {
Event::Chat { vis, player, msg } => {
if msg.as_str().starts_with("/bfox endvote") && self.admins.is_admin(&player.name) {
self.handle_round_over(&bf4).await;
} else {
let _ = self.handle_chat_msg(bf4, vis, player, msg).await;
}
let _ = self.handle_chat_msg(bf4, vis, player, msg).await;
}
Event::LevelLoaded { level_name, game_mode, rounds_played, rounds_total } => {
tokio::spawn(async move {
tokio::time::sleep(self.config.vote_start_interval).await;
self.start_new_vote().await;
});
}
Event::RoundOver { .. } => {
self.handle_round_over(&bf4).await;
Expand Down Expand Up @@ -909,6 +911,14 @@ impl Mapvote {
let _ = bf4.say("You are not admin (according to bfox config).", player).await;
}
},
"startvote" => {
if self.admins.is_admin(&player.name) {
let _ = bf4.say("Starting new vote.", player).await;
self.start_new_vote().await;
} else {
let _ = bf4.say("You are not admin (according to bfox config).", player).await;
}
},
_ => (),
}
}
Expand Down Expand Up @@ -1007,6 +1017,16 @@ impl Mapvote {
Ok(())
}

async fn start_new_vote(&self) {
let recent_maps = self.mapman.recent_maps();

let mut lock = self.inner.lock().await;
if let Some(inner) = &mut *lock {
info!("Starting a new vote: {:#?}", &inner.votes);
inner.set_up_new_vote(self.config.n_options, Some(recent_maps));
}
}

async fn handle_round_over(&self, bf4: &Arc<Bf4Client>) {
let recent_maps = self.mapman.recent_maps();
self.broadcast_status(bf4).await; // send everyone the voting options.
Expand All @@ -1028,7 +1048,7 @@ impl Mapvote {
// get each player's votes, so we can simulate how the votes go later.
let assignment = inner.to_assignment();

inner.set_up_new_vote(self.config.n_options, Some(recent_maps));
// inner.set_up_new_vote(self.config.n_options, Some(recent_maps));
Some((profile, assignment, inner.anim_override_override.clone()))
} else {
None
Expand Down
5 changes: 5 additions & 0 deletions battlefox/src/mapvote/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub struct MapVoteConfig {

pub max_noms_per_vip: usize,

pub vote_start_interval: Duration,

pub spammer_interval: Duration,

pub endscreen_votetime: Duration,
Expand Down Expand Up @@ -42,6 +44,8 @@ pub struct MapVoteConfigJson {

pub max_noms_per_vip: usize,

pub vote_start_interval: u64,

pub spammer_interval: u64,

pub endscreen_votetime: u64,
Expand All @@ -68,6 +72,7 @@ impl MapVoteConfig {
n_options: other.n_options,
max_options: other.max_options,
max_noms_per_vip: other.max_noms_per_vip,
vote_start_interval: Duration::from_secs(other.vote_start_interval),
spammer_interval: Duration::from_secs(other.spammer_interval),
endscreen_votetime: Duration::from_secs(other.endscreen_votetime),
endscreen_post_votetime: Duration::from_secs(other.endscreen_post_votetime),
Expand Down

0 comments on commit 0ba710c

Please sign in to comment.