2022-02-14 16:06:22 +05:30
|
|
|
"""Custom hooks to pull of the in-game functions."""
|
2021-04-10 16:33:19 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
# ba_meta require api 6
|
|
|
|
|
# (see https://ballistica.net/wiki/meta-tag-system)
|
|
|
|
|
|
|
|
|
|
# pylint: disable=import-error
|
|
|
|
|
# pylint: disable=import-outside-toplevel
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
import _thread
|
|
|
|
|
import importlib
|
2022-05-08 15:22:27 +05:30
|
|
|
import time
|
2022-02-14 16:06:22 +05:30
|
|
|
import os
|
2021-11-10 17:26:07 +05:30
|
|
|
import ba
|
|
|
|
|
import _ba
|
2022-02-14 16:06:22 +05:30
|
|
|
|
|
|
|
|
from ba import _hooks
|
|
|
|
|
from bastd.activity import dualteamscore, multiteamscore, drawscore
|
|
|
|
|
from bastd.activity.coopscore import CoopScoreScreen
|
2021-11-10 17:26:07 +05:30
|
|
|
import setting
|
2021-11-15 21:11:03 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
from chatHandle import handlechat
|
|
|
|
|
from features import team_balancer, afk_check, fire_flies, dual_team_score as newdts
|
|
|
|
|
from stats import mystats
|
2021-11-26 13:18:24 +05:30
|
|
|
from spazmod import modifyspaz
|
2022-02-14 16:06:22 +05:30
|
|
|
from tools import servercheck, ServerUpdate, logger
|
|
|
|
|
from playersData import pdata
|
2022-05-08 15:22:27 +05:30
|
|
|
from features import EndVote
|
2022-01-30 15:46:50 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from typing import Optional, Any
|
2022-01-30 15:46:50 +05:30
|
|
|
|
2021-11-15 21:11:03 +05:30
|
|
|
settings = setting.get_settings_data()
|
|
|
|
|
|
2021-11-10 17:26:07 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def filter_chat_message(msg: str, client_id: int) -> str | None:
|
|
|
|
|
"""Returns all in game messages or None (ignore's message)."""
|
2021-11-10 17:26:07 +05:30
|
|
|
return handlechat.filter_chat_message(msg, client_id)
|
2021-04-02 14:00:25 +05:30
|
|
|
|
2021-04-10 16:33:19 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def on_app_launch() -> None:
|
|
|
|
|
"""Runs when app is launched."""
|
2021-11-10 17:26:07 +05:30
|
|
|
bootstraping()
|
2021-11-14 17:02:13 +05:30
|
|
|
servercheck.checkserver().start()
|
2021-11-26 13:18:24 +05:30
|
|
|
ServerUpdate.check()
|
2022-02-14 16:06:22 +05:30
|
|
|
|
2022-01-09 23:02:35 +05:30
|
|
|
if settings["afk_remover"]['enable']:
|
|
|
|
|
afk_check.checkIdle().start()
|
2021-11-26 13:18:24 +05:30
|
|
|
|
2021-11-14 17:02:13 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def score_screen_on_begin(_stats: ba.Stats) -> None:
|
|
|
|
|
"""Runs when score screen is displayed."""
|
|
|
|
|
team_balancer.balanceTeams()
|
|
|
|
|
mystats.update(_stats)
|
2021-11-10 17:26:07 +05:30
|
|
|
|
|
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def playerspaz_init(playerspaz: ba.Player, node: ba.Node, player: ba.Player):
|
|
|
|
|
"""Runs when player is spawned on map."""
|
|
|
|
|
modifyspaz.main(playerspaz, node, player)
|
2021-11-10 17:26:07 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def bootstraping():
|
2022-02-14 16:06:22 +05:30
|
|
|
"""Bootstarps the server."""
|
|
|
|
|
# server related
|
2021-11-10 17:26:07 +05:30
|
|
|
_ba.set_server_device_name(settings["HostDeviceName"])
|
|
|
|
|
_ba.set_server_name(settings["HostName"])
|
|
|
|
|
_ba.set_transparent_kickvote(settings["ShowKickVoteStarterName"])
|
|
|
|
|
_ba.set_kickvote_msg_type(settings["KickVoteMsgType"])
|
2022-02-14 16:06:22 +05:30
|
|
|
|
|
|
|
|
# check for auto update stats
|
2022-05-08 15:22:27 +05:30
|
|
|
_thread.start_new_thread(mystats.refreshStats, ())
|
2022-05-04 23:30:15 +05:30
|
|
|
pdata.load_cache()
|
2022-05-08 15:22:27 +05:30
|
|
|
_thread.start_new_thread(pdata.dump_cache, ())
|
2022-02-14 16:06:22 +05:30
|
|
|
|
|
|
|
|
# import plugins
|
2022-01-09 23:18:53 +05:30
|
|
|
if settings["elPatronPowerups"]["enable"]:
|
2022-02-14 14:19:13 +05:30
|
|
|
from plugins import elPatronPowerups
|
2021-11-29 18:52:58 +05:30
|
|
|
elPatronPowerups.enable()
|
2022-01-09 23:18:53 +05:30
|
|
|
if settings["mikirogQuickTurn"]["enable"]:
|
2022-02-14 16:06:22 +05:30
|
|
|
from plugins import wavedash # pylint: disable=unused-import
|
2022-03-17 19:28:34 +05:30
|
|
|
if settings["colorful_explosions"]["enable"]:
|
|
|
|
|
from plugins import color_explosion
|
|
|
|
|
color_explosion.enable()
|
2022-03-04 18:32:57 +05:30
|
|
|
if settings["ballistica_web"]["enable"]:
|
2022-03-20 18:39:13 +05:30
|
|
|
from plugins import bcs_plugin
|
2022-03-04 18:32:57 +05:30
|
|
|
bcs_plugin.enable()
|
2022-03-20 19:41:59 +05:30
|
|
|
if settings["character_chooser"]["enable"]:
|
|
|
|
|
from plugins import CharacterChooser
|
|
|
|
|
CharacterChooser.enable()
|
|
|
|
|
if settings["custom_characters"]["enable"]:
|
|
|
|
|
from plugins import importcustomcharacters
|
|
|
|
|
importcustomcharacters.enable()
|
2022-05-18 00:20:39 +05:30
|
|
|
if settings["StumbledScoreScreen"]:
|
|
|
|
|
from features import StumbledScoreScreen
|
2021-12-01 23:52:54 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
# import features
|
2021-12-01 23:52:54 +05:30
|
|
|
if settings["whitelist"]:
|
2022-02-26 16:22:18 +05:30
|
|
|
pdata.load_white_list()
|
2021-12-29 13:23:22 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
import_discord_bot()
|
|
|
|
|
import_games()
|
|
|
|
|
import_dual_team_score()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def import_discord_bot() -> None:
|
|
|
|
|
"""Imports the discord bot."""
|
|
|
|
|
if settings["discordbot"]["enable"]:
|
|
|
|
|
from features import discord_bot
|
2022-05-08 15:22:27 +05:30
|
|
|
discord_bot.token = settings["discordbot"]["token"]
|
|
|
|
|
discord_bot.liveStatsChannelID = settings["discordbot"]["liveStatsChannelID"]
|
|
|
|
|
discord_bot.logsChannelID = settings["discordbot"]["logsChannelID"]
|
|
|
|
|
discord_bot.liveChat = settings["discordbot"]["liveChat"]
|
2022-02-14 16:06:22 +05:30
|
|
|
discord_bot.BsDataThread()
|
|
|
|
|
discord_bot.init()
|
|
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def import_games():
|
|
|
|
|
"""Imports the custom games from games directory."""
|
2022-04-26 21:51:24 +05:30
|
|
|
import sys
|
2022-05-08 15:22:27 +05:30
|
|
|
sys.path.append(_ba.env()['python_directory_user'] + os.sep + "games")
|
|
|
|
|
games = os.listdir("ba_root/mods/games")
|
2022-02-14 16:06:22 +05:30
|
|
|
for game in games:
|
2022-04-26 21:51:24 +05:30
|
|
|
if game.endswith(".so"):
|
2022-05-08 15:22:27 +05:30
|
|
|
importlib.import_module("games." + game.replace(".so", ""))
|
2021-11-15 21:11:03 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
maps = os.listdir("ba_root/mods/maps")
|
2022-02-14 16:06:22 +05:30
|
|
|
for _map in maps:
|
|
|
|
|
if _map.endswith(".py") or _map.endswith(".so"):
|
2022-05-08 15:22:27 +05:30
|
|
|
importlib.import_module("maps." + _map.replace(".so", "").replace(".py", ""))
|
|
|
|
|
|
2021-11-10 17:26:07 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def import_dual_team_score() -> None:
|
|
|
|
|
"""Imports the dual team score."""
|
|
|
|
|
if settings["newResultBoard"]:
|
2022-05-08 15:22:27 +05:30
|
|
|
dualteamscore.TeamVictoryScoreScreenActivity = newdts.TeamVictoryScoreScreenActivity
|
2022-02-14 16:06:22 +05:30
|
|
|
multiteamscore.MultiTeamScoreScreenActivity.show_player_scores = newdts.show_player_scores
|
2022-05-08 15:22:27 +05:30
|
|
|
drawscore.DrawScoreScreenActivity = newdts.DrawScoreScreenActivity
|
2021-11-10 17:26:07 +05:30
|
|
|
|
|
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
org_begin = ba._activity.Activity.on_begin
|
2021-11-10 17:26:07 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
|
2021-11-15 21:11:03 +05:30
|
|
|
def new_begin(self):
|
2022-02-14 16:06:22 +05:30
|
|
|
"""Runs when game is began."""
|
2021-11-15 21:11:03 +05:30
|
|
|
org_begin(self)
|
|
|
|
|
night_mode()
|
2022-05-08 15:22:27 +05:30
|
|
|
EndVote.voters = []
|
|
|
|
|
EndVote.game_started_on = time.time()
|
|
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
|
|
|
|
|
ba._activity.Activity.on_begin = new_begin
|
|
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
org_end = ba._activity.Activity.end
|
2021-11-15 21:11:03 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
def new_end(self, results: Any = None, delay: float = 0.0, force: bool = False):
|
2022-02-14 16:06:22 +05:30
|
|
|
"""Runs when game is ended."""
|
2022-05-08 15:22:27 +05:30
|
|
|
activity = _ba.get_foreground_host_activity()
|
|
|
|
|
if isinstance(activity, CoopScoreScreen):
|
2022-02-14 16:06:22 +05:30
|
|
|
team_balancer.checkToExitCoop()
|
2022-05-08 15:22:27 +05:30
|
|
|
org_end(self, results, delay, force)
|
|
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
ba._activity.Activity.end = new_end
|
2022-02-14 16:06:22 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
org_player_join = ba._activity.Activity.on_player_join
|
2022-02-14 16:06:22 +05:30
|
|
|
|
|
|
|
|
|
2021-11-29 18:52:58 +05:30
|
|
|
def on_player_join(self, player) -> None:
|
2022-02-14 16:06:22 +05:30
|
|
|
"""Runs when player joins the game."""
|
|
|
|
|
team_balancer.on_player_join()
|
2022-05-08 15:22:27 +05:30
|
|
|
org_player_join(self, player)
|
2021-11-29 18:52:58 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
|
|
|
|
|
ba._activity.Activity.on_player_join = on_player_join
|
2021-11-26 13:18:24 +05:30
|
|
|
|
2021-11-15 21:11:03 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def night_mode() -> None:
|
|
|
|
|
"""Checks the time and enables night mode."""
|
2021-11-15 21:11:03 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
if settings['autoNightMode']['enable']:
|
2021-11-15 21:11:03 +05:30
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
start = datetime.strptime(settings['autoNightMode']['startTime'], "%H:%M")
|
|
|
|
|
end = datetime.strptime(settings['autoNightMode']['endTime'], "%H:%M")
|
|
|
|
|
now = datetime.now()
|
2022-02-14 16:06:22 +05:30
|
|
|
|
2021-11-15 21:11:03 +05:30
|
|
|
if now.time() > start.time() or now.time() < end.time():
|
|
|
|
|
activity = _ba.get_foreground_host_activity()
|
2021-11-26 13:18:24 +05:30
|
|
|
|
|
|
|
|
activity.globalsnode.tint = (0.5, 0.7, 1.0)
|
|
|
|
|
|
2022-01-30 15:46:50 +05:30
|
|
|
if settings['autoNightMode']['fireflies']:
|
2022-02-14 16:06:22 +05:30
|
|
|
fire_flies.factory(settings['autoNightMode']["fireflies_random_color"])
|
2021-11-26 13:18:24 +05:30
|
|
|
|
|
|
|
|
|
2022-05-08 15:22:27 +05:30
|
|
|
def kick_vote_started(started_by: str, started_to: str) -> None:
|
2022-02-14 16:06:22 +05:30
|
|
|
"""Logs the kick vote."""
|
|
|
|
|
logger.log(f"{started_by} started kick vote for {started_to}.")
|
2021-11-29 18:52:58 +05:30
|
|
|
|
|
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def on_kicked(account_id: str) -> None:
|
|
|
|
|
"""Runs when someone is kicked by kickvote."""
|
|
|
|
|
logger.log(f"{account_id} kicked by kickvotes.")
|
2021-11-29 18:52:58 +05:30
|
|
|
|
2021-12-01 23:52:54 +05:30
|
|
|
|
2022-02-14 16:06:22 +05:30
|
|
|
def on_kick_vote_end():
|
|
|
|
|
"""Runs when kickvote is ended."""
|
|
|
|
|
logger.log("Kick vote End")
|
2021-12-01 23:52:54 +05:30
|
|
|
|
|
|
|
|
|
2022-06-17 01:58:59 +05:30
|
|
|
def on_join_request(ip):
|
|
|
|
|
servercheck.on_join_request(ip)
|