Skip to content

Commit

Permalink
Merge branch 'master' into feat/autosettings_all_rcon_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cemathey committed May 28, 2024
2 parents 2f5d6da + edac694 commit a5e6cac
Show file tree
Hide file tree
Showing 11 changed files with 617 additions and 317 deletions.
859 changes: 568 additions & 291 deletions README.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion rcon/auto_kick.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def auto_kick(rcon, struct_log, name: str, player_id: str):

if re.match(r, name):
logger.info("%s matched player %s", r, name)
rcon.kick(player=name, reason=config.kick_reason, by="NAME_KICK")
rcon.do_kick(
player=name,
reason=config.kick_reason,
by="NAME_KICK",
player_id=player_id,
)
try:
webhookurls: list[HttpUrl | None] | None
if config.discord_webhook_url is None:
Expand Down
5 changes: 4 additions & 1 deletion rcon/automods/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def _do_punitions(
if method == ActionMethod.KICK:
if not aplayer.details.dry_run:
rcon.kick(
aplayer.name, aplayer.details.message, by=aplayer.details.author
player_name=aplayer.name,
reason=aplayer.details.message,
by=aplayer.details.author,
player_id=aplayer.player_id,
)
audit(
discord_webhook_url=aplayer.details.discord_audit_url,
Expand Down
6 changes: 3 additions & 3 deletions rcon/automods/seeding_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def punitions_to_apply(
drc = self.config.disallowed_roles
if (
server_player_count < drc.min_players
or server_player_count > drc.max_players
or server_player_count >= drc.max_players
):
self._disable_for_round("disallowed_roles")
else:
Expand All @@ -279,7 +279,7 @@ def punitions_to_apply(
dwc = self.config.disallowed_weapons
if (
server_player_count < dwc.min_players
or server_player_count > dwc.max_players
or server_player_count >= dwc.max_players
):
self._disable_for_round("disallowed_weapons")
else:
Expand All @@ -288,7 +288,7 @@ def punitions_to_apply(
ecf = self.config.enforce_cap_fight
if (
server_player_count < ecf.min_players
or server_player_count > ecf.max_players
or server_player_count >= ecf.max_players
):
self._disable_for_round("enforce_cap_fight")
else:
Expand Down
19 changes: 14 additions & 5 deletions rcon/game_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ def logs_since(
"""Return a list of logs more recent than the last_seen ID"""
try:
if last_seen is None:
logs: list[tuple[StreamID, StructuredLogLineWithMetaData]] = [
self.log_stream.tail()
]
logs: list[tuple[StreamID, StructuredLogLineWithMetaData]] = []
tail_log: tuple[
StreamID, StructuredLogLineWithMetaData
] = self.log_stream.tail()
if tail_log:
logs.append(tail_log)
else:
logs: list[
tuple[StreamID, StructuredLogLineWithMetaData]
Expand Down Expand Up @@ -415,14 +418,20 @@ def record_player_stats(self, players: dict[str, GetDetailedPlayer]):
player_id,
PlayerStat(
combat=player["combat"],
p_combat=0,
offense=player["offense"],
p_offense=0,
defense=player["defense"],
p_defense=0,
support=player["support"],
p_support=0,
),
)
for stat in ["combat", "offense", "defense", "support"]:
if player[stat] > p[stat]:
p[stat] = player[stat]
if player[stat] < p[stat]:
p["p_" + stat] = p["p_" + stat] + p[stat]

p[stat] = player[stat]
map_players[player_id] = p
maps.update(0, m)

Expand Down
2 changes: 2 additions & 0 deletions rcon/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ def windows_store_player_check(rcon: Rcon, _, name: str, player_id: str):
name,
reason=config.player_message,
by=config.audit_message_author,
player_id=player_id,
)
elif action == WindowsStoreIdActionType.temp_ban:
rcon.temp_ban(
Expand Down Expand Up @@ -605,6 +606,7 @@ def notify_whitespace_player(action: RconInvalidNameActionType):
name,
reason=config.whitespace_name_player_message,
by=config.audit_message_author,
player_id=player_id,
)
except Exception as e:
logger.error(
Expand Down
8 changes: 4 additions & 4 deletions rcon/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,10 @@ def current_game_stats():
if map_stat is None:
logger.info("No stats for: " + stat[PLAYER_ID])
continue
stat["combat"] = map_stat["combat"]
stat["offense"] = map_stat["offense"]
stat["defense"] = map_stat["defense"]
stat["support"] = map_stat["support"]
stat["combat"] = map_stat["combat"] + map_stat["p_combat"]
stat["offense"] = map_stat["offense"] + map_stat["p_offense"]
stat["defense"] = map_stat["defense"] + map_stat["p_defense"]
stat["support"] = map_stat["support"] + map_stat["p_support"]
return stats


Expand Down
4 changes: 4 additions & 0 deletions rcon/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,13 @@ class PlayerStatsType(TypedDict):

class PlayerStat(TypedDict):
combat: int
p_combat: int
offense: int
p_offense: int
defense: int
p_defense: int
support: int
p_support: int


class CachedLiveGameStats(TypedDict):
Expand Down
10 changes: 5 additions & 5 deletions rcon/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def record_stats_from_map(
defense=existing.defense,
support=existing.support,
)
map_stats = ps.get(player_id, default_stat)
map_stats: PlayerStat = ps.get(player_id, default_stat)
player_stat = dict(
player_id_id=player_record.id,
map_id=map_.id,
Expand All @@ -200,10 +200,10 @@ def record_stats_from_map(
most_killed=stats.get("most_killed"),
death_by=stats.get("death_by"),
death_by_weapons=stats.get("death_by_weapons"),
combat=map_stats.get("combat"),
offense=map_stats.get("offense"),
defense=map_stats.get("defense"),
support=map_stats.get("support"),
combat=map_stats.get("combat") + map_stats.get("p_combat"),
offense=map_stats.get("offense") + map_stats.get("p_offense"),
defense=map_stats.get("defense") + map_stats.get("p_defense"),
support=map_stats.get("support") + map_stats.get("p_support"),
)
if existing is not None and force != True:
continue
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==24.4.0
black==24.4.2
isort==5.13.2
pytest==8.1.1
pytest==8.2.1
cachetools==5.3.3
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Click==8.1.7
Django==4.2.10
django-cors-headers==4.3.1
redis==5.0.3
sqlalchemy==2.0.29
redis==5.0.4
sqlalchemy==2.0.30
channels==4.1.0
orjson==3.10.1
simplejson==3.19.2
psycopg2-binary
sentry-sdk[django]==1.45.0
python-dateutil==2.9.0.post0
discord-webhook[async]
requests==2.31.0
requests==2.32.2
steam==1.4.4
# Alembic does not use semantic versioning, so be careful with the version numbers https://alembic.sqlalchemy.org/en/latest/front.html#versioning-scheme
alembic==1.13.1
rq==1.16.1
rq==1.16.2
rq-scheduler==0.13.1
paramiko==3.4.0
ftpretty==0.4.0
pytz>=2023.3
pandas>=1.4.1,<2.0.0
pydantic==2.7.0
pydantic==2.7.1
discord.py==2.3.2
# django-directory
# django-dirctory is currently incompatible with Django 4.0+, PR is pending to fix django-directory upstream
Expand Down

0 comments on commit a5e6cac

Please sign in to comment.