Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Fixed wrong team announcement bug, improved new player handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Bash-09 committed Aug 7, 2022
1 parent 111258e commit 266e925
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 55 deletions.
2 changes: 1 addition & 1 deletion cfg/playerlist.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cfg/regx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ b\-bot
dsc\.gg/crab\-bot
sniper bot
b\-bot
cum2
Skilight<3
\[g0tb0t\]Church\-of\-myg0t
1 change: 1 addition & 0 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub fn render(
ui.checkbox(&mut state.settings.announce_bots, "Announce Bots").on_hover_text("Send a chat message indicating Bots joining the server.");
ui.checkbox(&mut state.settings.announce_cheaters, "Announce Cheaters").on_hover_text("Send a chat message indicating cheaters joining the server.");
ui.checkbox(&mut state.settings.announce_namesteal, "Announce Name-stealing").on_hover_text("Send a chat message when an account's name is changed to imitate another player (This is not affected by the chat message period).");
ui.checkbox(&mut state.settings.dont_announce_common_names, "Ignore Bots with common names").on_hover_text("Don't announce bots who's name matches saved regexes, to avoid announcing well-known bots (e.g. DoesHotter, m4gic).");

ui.horizontal(|ui| {
ui.add_enabled(state.settings.announce_bots || state.settings.announce_cheaters,
Expand Down
1 change: 1 addition & 0 deletions src/player_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl PlayerChecker {
for regx in self.bots_regx.iter() {
if regx.captures(&player.name).is_some() {
player.player_type = PlayerType::Bot;
player.common_name = true;

let note = format!("Matched bot regex: {}", regx.as_str());
if !player.notes.is_empty() {
Expand Down
8 changes: 6 additions & 2 deletions src/regexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ pub fn fn_status(

accounted: true,
stolen_name,
common_name: false,
};

if player_checker.check_player_steamid(&mut p) {
log::info!("Known {:?} joining: {}", p.player_type, p.name);
} else if player_checker.check_player_name(&mut p) {
}
if player_checker.check_player_name(&mut p) {
log::info!("Unknown {:?} joining: {}", p.player_type, p.name);
}

Expand All @@ -149,7 +151,9 @@ pub fn fn_status(
player_checker.update_player(&p);
}

server.new_connections.push(p.steamid.clone());
if p.time <= (settings.refresh_period * 1.5) as u32{
server.new_connections.push(p.steamid.clone());
}
server.players.insert(p.steamid.clone(), p);
}
}
Expand Down
94 changes: 43 additions & 51 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,66 +118,48 @@ impl Server {
}

pub fn send_chat_messages(&mut self, settings: &Settings, cmd: &mut CommandManager) {
// Remove unwanted accounts from the list to announce
self.new_connections.retain(|steamid| {
if let Some(p) = self.players.get(steamid) {
if !(settings.announce_bots && p.player_type == PlayerType::Bot)
&& !(settings.announce_cheaters && p.player_type == PlayerType::Cheater)
{
return false;
}

if p.time > settings.alert_period.ceil() as u32 {
return false;
}

return true;
}
false
});

if !settings.announce_bots && !settings.announce_cheaters {
return;
}

let mut message = String::new();

let mut bots = false;
let mut cheaters = false;
let mut names: Vec<&str> = Vec::new();

let mut invaders = false;
let mut defenders = false;

// Get all newly connected illegitimate accounts
for steamid in &self.new_connections {
if let Some(p) = self.players.get(steamid) {
if p.time as u32 > settings.alert_period as u32 {
continue;
// Remove accounts we don't want to announce, record the details of accounts we want to
// announce now, and leave the rest for later
self.new_connections.retain(|p| {
if let Some(p) = self.players.get(p) {
// Make sure it's a bot or cheater
if !(settings.announce_bots && p.player_type == PlayerType::Bot
|| settings.announce_cheaters && p.player_type == PlayerType::Cheater)
{
return false;
}

match p.player_type {
PlayerType::Bot => {
if !settings.announce_bots {
continue;
}
bots = true;
invaders |= p.team == Team::Invaders;
defenders |= p.team == Team::Defenders;
}
PlayerType::Cheater => {
if !settings.announce_cheaters {
continue;
}
cheaters = true;
invaders |= p.team == Team::Invaders;
defenders |= p.team == Team::Defenders;
}
_ => {}
// Don't announce common names
if settings.dont_announce_common_names && p.common_name {
return false;
}

// Ignore accounts that haven't been assigned a team yet
if p.team == Team::None {
return true;
}

// Record details of account for announcement
bots |= p.player_type == PlayerType::Bot;
cheaters |= p.player_type == PlayerType::Cheater;
invaders |= p.team == Team::Invaders;
defenders |= p.team == Team::Defenders;
names.push(&p.name);
}
}
false
});

if self.new_connections.is_empty() {
if names.is_empty() {
return;
}

Expand All @@ -199,8 +181,13 @@ impl Server {
|| (defenders && user.team == Team::Defenders)
{
message.push_str("our team: ");
} else {
} else if (invaders && user.team == Team::Defenders)
|| (defenders && user.team == Team::Invaders)
{
message.push_str("the enemy team: ");
} else {
message.push_str("the server: ");
log::error!("Announcing bot that doesn't have a team.");
}
}
None => {
Expand All @@ -209,10 +196,9 @@ impl Server {
}

// Player names
let mut account_peekable = self.new_connections.iter().peekable();
while let Some(steamid) = account_peekable.next() {
let account = self.players.get(steamid).unwrap();
message.push_str(&account.name);
let mut account_peekable = names.iter().peekable();
while let Some(name) = account_peekable.next() {
message.push_str(name);

if account_peekable.peek().is_some() {
message.push_str(", ");
Expand All @@ -226,3 +212,9 @@ impl Server {
self.new_connections.clear();
}
}

impl Default for Server {
fn default() -> Self {
Self::new()
}
}
1 change: 1 addition & 0 deletions src/server/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct Player {

pub accounted: bool,
pub stolen_name: bool,
pub common_name: bool,
}

impl std::fmt::Display for Player {
Expand Down
11 changes: 11 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Settings {
pub announce_bots: bool,
pub announce_cheaters: bool,
pub announce_namesteal: bool,
pub dont_announce_common_names: bool,

pub kick_bots: bool,
pub kick_cheaters: bool,
Expand Down Expand Up @@ -49,6 +50,7 @@ impl Settings {
announce_bots: false,
announce_cheaters: false,
announce_namesteal: true,
dont_announce_common_names: true,

kick_bots: true,
kick_cheaters: false,
Expand Down Expand Up @@ -97,6 +99,9 @@ impl Settings {
set.announce_namesteal = json["announce_namesteal"]
.as_bool()
.unwrap_or(set.announce_namesteal);
set.dont_announce_common_names = json["dont_announce_common_names"]
.as_bool()
.unwrap_or(set.dont_announce_common_names);

set.kick_bots = json["kick_bots"].as_bool().unwrap_or(set.kick_bots);
set.kick_cheaters = json["kick_cheaters"].as_bool().unwrap_or(set.kick_cheaters);
Expand Down Expand Up @@ -137,3 +142,9 @@ impl Settings {
}
}
}

impl Default for Settings {
fn default() -> Self {
Self::new()
}
}

0 comments on commit 266e925

Please sign in to comment.