mirror of
https://github.com/imayushsaini/Bombsquad-Ballistica-Modded-Server.git
synced 2025-10-20 00:00:39 +00:00
Linted custom_hooks.
Now every game script related things are now hooked to custom_hooks.
This commit is contained in:
parent
2676c4ef99
commit
569e9bc968
4 changed files with 117 additions and 108 deletions
217
dist/ba_root/mods/custom_hooks.py
vendored
217
dist/ba_root/mods/custom_hooks.py
vendored
|
|
@ -1,182 +1,191 @@
|
|||
"""Custom hooks to pull of the in-game functions."""
|
||||
|
||||
# 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
|
||||
import os
|
||||
import ba
|
||||
import _ba
|
||||
from chatHandle import handlechat
|
||||
import setting
|
||||
from tools import servercheck
|
||||
from tools import ServerUpdate
|
||||
import _thread
|
||||
from stats import mystats
|
||||
from datetime import datetime
|
||||
from ba import _activity
|
||||
|
||||
from typing import Optional, Any
|
||||
from spazmod import modifyspaz
|
||||
from bastd.activity import dualteamscore
|
||||
from bastd.activity import multiteamscore
|
||||
from bastd.activity import drawscore
|
||||
from bastd.actor.zoomtext import ZoomText
|
||||
from tools import TeamBalancer
|
||||
from bastd.activity.coopscore import CoopScoreScreen
|
||||
from ba import _hooks
|
||||
from tools import Logger
|
||||
|
||||
from bastd.activity import dualteamscore, multiteamscore, drawscore
|
||||
from bastd.activity.coopscore import CoopScoreScreen
|
||||
import setting
|
||||
|
||||
from chatHandle import handlechat
|
||||
from features import team_balancer, afk_check, fire_flies, dual_team_score as newdts
|
||||
from stats import mystats
|
||||
from spazmod import modifyspaz
|
||||
from tools import servercheck, ServerUpdate, logger
|
||||
from playersData import pdata
|
||||
|
||||
from tools import afk_check
|
||||
# from bastd.activity.multiteamvictory import
|
||||
from tools import fireflies
|
||||
if TYPE_CHECKING:
|
||||
from typing import Optional, Any
|
||||
|
||||
|
||||
settings = setting.get_settings_data()
|
||||
|
||||
def filter_chat_message(msg, client_id):
|
||||
|
||||
def filter_chat_message(msg: str, client_id: int) -> str | None:
|
||||
"""Returns all in game messages or None (ignore's message)."""
|
||||
return handlechat.filter_chat_message(msg, client_id)
|
||||
|
||||
|
||||
def on_app_launch():
|
||||
def on_app_launch() -> None:
|
||||
"""Runs when app is launched."""
|
||||
bootstraping()
|
||||
servercheck.checkserver().start()
|
||||
ServerUpdate.check()
|
||||
|
||||
if settings["afk_remover"]['enable']:
|
||||
afk_check.checkIdle().start()
|
||||
|
||||
|
||||
|
||||
#something
|
||||
|
||||
def score_screen_on_begin(_stats):
|
||||
pass
|
||||
#stats
|
||||
|
||||
def playerspaz_init(player):
|
||||
pass
|
||||
#add tag,rank,effect
|
||||
|
||||
def score_screen_on_begin(_stats: ba.Stats) -> None:
|
||||
"""Runs when score screen is displayed."""
|
||||
team_balancer.balanceTeams()
|
||||
mystats.update(_stats)
|
||||
|
||||
|
||||
def playerspaz_init(playerspaz: ba.Player, node: ba.Node, player: ba.Player):
|
||||
"""Runs when player is spawned on map."""
|
||||
modifyspaz.main(playerspaz, node, player)
|
||||
|
||||
|
||||
def bootstraping():
|
||||
|
||||
#_ba.disconnect_client=new_disconnect
|
||||
|
||||
"""Bootstarps the server."""
|
||||
# server related
|
||||
_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"])
|
||||
|
||||
# check for auto update stats
|
||||
_thread.start_new_thread(mystats.refreshStats,())
|
||||
|
||||
# import plugins
|
||||
if settings["elPatronPowerups"]["enable"]:
|
||||
from plugins import elPatronPowerups
|
||||
elPatronPowerups.enable()
|
||||
if settings["mikirogQuickTurn"]["enable"]:
|
||||
from plugins import wavedash
|
||||
from plugins import wavedash # pylint: disable=unused-import
|
||||
|
||||
# import features
|
||||
if settings["whitelist"]:
|
||||
pdata.loadWhitelist()
|
||||
|
||||
import_discord_bot()
|
||||
import_games()
|
||||
import_dual_team_score()
|
||||
|
||||
|
||||
def import_discord_bot() -> None:
|
||||
"""Imports the discord bot."""
|
||||
if settings["discordbot"]["enable"]:
|
||||
from tools import discordbot
|
||||
discordbot.token=settings["discordbot"]["token"]
|
||||
discordbot.liveStatsChannelID=settings["discordbot"]["liveStatsChannelID"]
|
||||
discordbot.logsChannelID=settings["discordbot"]["logsChannelID"]
|
||||
discordbot.liveChat=settings["discordbot"]["liveChat"]
|
||||
discordbot.BsDataThread()
|
||||
discordbot.init()
|
||||
importgames()
|
||||
from features import discord_bot
|
||||
discord_bot.token=settings["discordbot"]["token"]
|
||||
discord_bot.liveStatsChannelID=settings["discordbot"]["liveStatsChannelID"]
|
||||
discord_bot.logsChannelID=settings["discordbot"]["logsChannelID"]
|
||||
discord_bot.liveChat=settings["discordbot"]["liveChat"]
|
||||
discord_bot.BsDataThread()
|
||||
discord_bot.init()
|
||||
|
||||
|
||||
def import_games():
|
||||
"""Imports the custom games from games directory."""
|
||||
games=os.listdir("ba_root/mods/games")
|
||||
for game in games:
|
||||
if game.endswith(".py") or game.endswith(".so"):
|
||||
importlib.import_module("games."+game.replace(".so","").replace(".py",""))
|
||||
|
||||
maps=os.listdir("ba_root/mods/maps")
|
||||
for _map in maps:
|
||||
if _map.endswith(".py") or _map.endswith(".so"):
|
||||
importlib.import_module("maps."+_map.replace(".so","").replace(".py",""))
|
||||
|
||||
def import_dual_team_score() -> None:
|
||||
"""Imports the dual team score."""
|
||||
if settings["newResultBoard"]:
|
||||
dualteamscore.TeamVictoryScoreScreenActivity= newdts.TeamVictoryScoreScreenActivity
|
||||
multiteamscore.MultiTeamScoreScreenActivity.show_player_scores = newdts.show_player_scores
|
||||
drawscore.DrawScoreScreenActivity=newdts.DrawScoreScreenActivity
|
||||
|
||||
|
||||
org_begin = ba._activity.Activity.on_begin
|
||||
|
||||
|
||||
def new_disconnect(clid,duration=120):
|
||||
print("new new_disconnect")
|
||||
_ba.ban_client(clid,duration)
|
||||
|
||||
org_begin=ba._activity.Activity.on_begin
|
||||
def new_begin(self):
|
||||
"""Runs when game is began."""
|
||||
org_begin(self)
|
||||
night_mode()
|
||||
|
||||
ba._activity.Activity.on_begin=new_begin
|
||||
|
||||
ba._activity.Activity.on_begin = new_begin
|
||||
|
||||
|
||||
org_end=ba._activity.Activity.end
|
||||
|
||||
def new_end(self,results:Any=None,delay:float=0.0,force:bool=False):
|
||||
act=_ba.get_foreground_host_activity()
|
||||
if isinstance(act,CoopScoreScreen):
|
||||
TeamBalancer.checkToExitCoop()
|
||||
|
||||
"""Runs when game is ended."""
|
||||
activity=_ba.get_foreground_host_activity()
|
||||
if isinstance(activity,CoopScoreScreen):
|
||||
team_balancer.checkToExitCoop()
|
||||
org_end(self,results,delay,force)
|
||||
|
||||
|
||||
ba._activity.Activity.end=new_end
|
||||
|
||||
|
||||
org_player_join=ba._activity.Activity.on_player_join
|
||||
|
||||
def on_player_join(self, player) -> None:
|
||||
TeamBalancer.on_player_join()
|
||||
"""Runs when player joins the game."""
|
||||
team_balancer.on_player_join()
|
||||
org_player_join(self,player)
|
||||
|
||||
ba._activity.Activity.on_player_join=on_player_join
|
||||
|
||||
|
||||
def night_mode() -> None:
|
||||
"""Checks the time and enables night mode."""
|
||||
|
||||
def night_mode():
|
||||
|
||||
if(settings['autoNightMode']['enable']):
|
||||
if settings['autoNightMode']['enable']:
|
||||
|
||||
start=datetime.strptime(settings['autoNightMode']['startTime'],"%H:%M")
|
||||
end=datetime.strptime(settings['autoNightMode']['endTime'],"%H:%M")
|
||||
now=datetime.now()
|
||||
|
||||
|
||||
if now.time() > start.time() or now.time() < end.time():
|
||||
activity = _ba.get_foreground_host_activity()
|
||||
|
||||
activity.globalsnode.tint = (0.5, 0.7, 1.0)
|
||||
|
||||
if settings['autoNightMode']['fireflies']:
|
||||
fireflies.factory(settings['autoNightMode']["fireflies_random_color"])
|
||||
fire_flies.factory(settings['autoNightMode']["fireflies_random_color"])
|
||||
|
||||
|
||||
|
||||
from tools import dualteamscore as newdts
|
||||
|
||||
if settings["newResultBoard"]:
|
||||
def kick_vote_started(started_by: str,started_to: str) -> None:
|
||||
"""Logs the kick vote."""
|
||||
logger.log(f"{started_by} started kick vote for {started_to}.")
|
||||
|
||||
|
||||
dualteamscore.TeamVictoryScoreScreenActivity= newdts.TeamVictoryScoreScreenActivity
|
||||
def on_kicked(account_id: str) -> None:
|
||||
"""Runs when someone is kicked by kickvote."""
|
||||
logger.log(f"{account_id} kicked by kickvotes.")
|
||||
|
||||
multiteamscore.MultiTeamScoreScreenActivity.show_player_scores = newdts.show_player_scores
|
||||
|
||||
drawscore.DrawScoreScreenActivity=newdts.DrawScoreScreenActivity
|
||||
|
||||
def scoreScreenBegin():
|
||||
TeamBalancer.balanceTeams()
|
||||
|
||||
|
||||
def kick_vote_started(by,to):
|
||||
Logger.log(by+" started kick vote for "+to)
|
||||
|
||||
_hooks.kick_vote_started=kick_vote_started
|
||||
|
||||
def on_kicked(id):
|
||||
Logger.log(id+" kicked by kickvotes")
|
||||
|
||||
_hooks.on_kicked=on_kicked
|
||||
|
||||
def on_kick_vote_end():
|
||||
Logger.log("Kick vote End")
|
||||
"""Runs when kickvote is ended."""
|
||||
logger.log("Kick vote End")
|
||||
|
||||
|
||||
|
||||
import os
|
||||
import importlib
|
||||
def importgames():
|
||||
games=os.listdir("ba_root/mods/games")
|
||||
for game in games:
|
||||
if game.endswith(".py") or game.endswith(".so"):
|
||||
importlib.import_module("games."+game.replace(".so","").replace(".py",""))
|
||||
maps=os.listdir("ba_root/mods/maps")
|
||||
for map in maps:
|
||||
if map.endswith(".py") or map.endswith(".so"):
|
||||
importlib.import_module("maps."+map.replace(".so","").replace(".py",""))
|
||||
|
||||
|
||||
|
||||
|
||||
_hooks.kick_vote_started=kick_vote_started
|
||||
_hooks.on_kicked=on_kicked
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue