mirror of
https://github.com/imayushsaini/Bombsquad-Ballistica-Modded-Server.git
synced 2025-11-14 17:46:03 +00:00
End Vote system
This commit is contained in:
parent
db6bad9f59
commit
a2c7b303d0
4 changed files with 154 additions and 72 deletions
29
dist/ba_root/mods/chatHandle/handlechat.py
vendored
29
dist/ba_root/mods/chatHandle/handlechat.py
vendored
|
|
@ -5,40 +5,44 @@ from serverData import serverdata
|
|||
from chatHandle.ChatCommands import Main
|
||||
from tools import logger, servercheck
|
||||
from chatHandle.chatFilter import ChatFilter
|
||||
from features import EndVote
|
||||
import ba, _ba
|
||||
import setting
|
||||
|
||||
settings = setting.get_settings_data()
|
||||
|
||||
def filter_chat_message(msg, client_id):
|
||||
|
||||
if client_id ==-1:
|
||||
def filter_chat_message(msg, client_id):
|
||||
if client_id == -1:
|
||||
if msg.startswith("/"):
|
||||
Main.Command(msg,client_id)
|
||||
Main.Command(msg, client_id)
|
||||
return None
|
||||
return msg
|
||||
acid=""
|
||||
displaystring=""
|
||||
currentname=""
|
||||
acid = ""
|
||||
displaystring = ""
|
||||
currentname = ""
|
||||
|
||||
for i in _ba.get_game_roster():
|
||||
if i['client_id'] == client_id:
|
||||
acid = i['account_id']
|
||||
try:
|
||||
currentname=i['players'][0]['name_full']
|
||||
currentname = i['players'][0]['name_full']
|
||||
except:
|
||||
currentname="<in-lobby>"
|
||||
displaystring=i['display_string']
|
||||
currentname = "<in-lobby>"
|
||||
displaystring = i['display_string']
|
||||
if acid:
|
||||
msg=ChatFilter.filter(msg,acid,client_id)
|
||||
msg = ChatFilter.filter(msg, acid, client_id)
|
||||
|
||||
if msg.startswith("/"):
|
||||
return Main.Command(msg, client_id)
|
||||
|
||||
if msg.startswith(",") and settings["allowTeamChat"]:
|
||||
return Main.QuickAccess(msg,client_id)
|
||||
return Main.QuickAccess(msg, client_id)
|
||||
|
||||
logger.log(acid+" | "+displaystring+"|"+currentname+"| " +msg,"chat")
|
||||
if msg == "end" and settings["allowEndVote"]:
|
||||
EndVote.vote_end(acid, client_id)
|
||||
|
||||
logger.log(acid + " | " + displaystring + "|" + currentname + "| " + msg, "chat")
|
||||
|
||||
if acid in serverdata.clients and serverdata.clients[acid]["verified"]:
|
||||
|
||||
|
|
@ -59,4 +63,3 @@ def filter_chat_message(msg, client_id):
|
|||
else:
|
||||
_ba.screenmessage("Fetching your account info , Wait a minute", transient=True, clients=[client_id])
|
||||
return None
|
||||
|
||||
|
|
|
|||
70
dist/ba_root/mods/custom_hooks.py
vendored
70
dist/ba_root/mods/custom_hooks.py
vendored
|
|
@ -14,6 +14,7 @@ from datetime import datetime
|
|||
|
||||
import _thread
|
||||
import importlib
|
||||
import time
|
||||
import os
|
||||
import ba
|
||||
import _ba
|
||||
|
|
@ -29,11 +30,11 @@ from stats import mystats
|
|||
from spazmod import modifyspaz
|
||||
from tools import servercheck, ServerUpdate, logger
|
||||
from playersData import pdata
|
||||
from features import EndVote
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Optional, Any
|
||||
|
||||
|
||||
settings = setting.get_settings_data()
|
||||
|
||||
|
||||
|
|
@ -72,9 +73,9 @@ def bootstraping():
|
|||
_ba.set_kickvote_msg_type(settings["KickVoteMsgType"])
|
||||
|
||||
# check for auto update stats
|
||||
_thread.start_new_thread(mystats.refreshStats,())
|
||||
_thread.start_new_thread(mystats.refreshStats, ())
|
||||
pdata.load_cache()
|
||||
_thread.start_new_thread(pdata.dump_cache,())
|
||||
_thread.start_new_thread(pdata.dump_cache, ())
|
||||
|
||||
# import plugins
|
||||
if settings["elPatronPowerups"]["enable"]:
|
||||
|
|
@ -108,65 +109,73 @@ def import_discord_bot() -> None:
|
|||
"""Imports the discord bot."""
|
||||
if settings["discordbot"]["enable"]:
|
||||
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.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."""
|
||||
import sys
|
||||
sys.path.append(_ba.env()['python_directory_user']+os.sep+"games")
|
||||
games=os.listdir("ba_root/mods/games")
|
||||
sys.path.append(_ba.env()['python_directory_user'] + os.sep + "games")
|
||||
games = os.listdir("ba_root/mods/games")
|
||||
for game in games:
|
||||
if game.endswith(".so"):
|
||||
importlib.import_module("games."+game.replace(".so",""))
|
||||
importlib.import_module("games." + game.replace(".so", ""))
|
||||
|
||||
maps=os.listdir("ba_root/mods/maps")
|
||||
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",""))
|
||||
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
|
||||
dualteamscore.TeamVictoryScoreScreenActivity = newdts.TeamVictoryScoreScreenActivity
|
||||
multiteamscore.MultiTeamScoreScreenActivity.show_player_scores = newdts.show_player_scores
|
||||
drawscore.DrawScoreScreenActivity=newdts.DrawScoreScreenActivity
|
||||
drawscore.DrawScoreScreenActivity = newdts.DrawScoreScreenActivity
|
||||
|
||||
|
||||
org_begin = ba._activity.Activity.on_begin
|
||||
|
||||
|
||||
def new_begin(self):
|
||||
"""Runs when game is began."""
|
||||
org_begin(self)
|
||||
night_mode()
|
||||
EndVote.voters = []
|
||||
EndVote.game_started_on = time.time()
|
||||
|
||||
|
||||
ba._activity.Activity.on_begin = new_begin
|
||||
|
||||
org_end = ba._activity.Activity.end
|
||||
|
||||
org_end=ba._activity.Activity.end
|
||||
|
||||
def new_end(self,results:Any=None,delay:float=0.0,force:bool=False):
|
||||
def new_end(self, results: Any = None, delay: float = 0.0, force: bool = False):
|
||||
"""Runs when game is ended."""
|
||||
activity=_ba.get_foreground_host_activity()
|
||||
if isinstance(activity,CoopScoreScreen):
|
||||
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_end(self, results, delay, force)
|
||||
|
||||
|
||||
org_player_join=ba._activity.Activity.on_player_join
|
||||
ba._activity.Activity.end = new_end
|
||||
|
||||
org_player_join = ba._activity.Activity.on_player_join
|
||||
|
||||
|
||||
def on_player_join(self, player) -> None:
|
||||
"""Runs when player joins the game."""
|
||||
team_balancer.on_player_join()
|
||||
org_player_join(self,player)
|
||||
org_player_join(self, player)
|
||||
|
||||
ba._activity.Activity.on_player_join=on_player_join
|
||||
|
||||
ba._activity.Activity.on_player_join = on_player_join
|
||||
|
||||
|
||||
def night_mode() -> None:
|
||||
|
|
@ -174,9 +183,9 @@ def night_mode() -> None:
|
|||
|
||||
if settings['autoNightMode']['enable']:
|
||||
|
||||
start=datetime.strptime(settings['autoNightMode']['startTime'],"%H:%M")
|
||||
end=datetime.strptime(settings['autoNightMode']['endTime'],"%H:%M")
|
||||
now=datetime.now()
|
||||
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()
|
||||
|
|
@ -187,8 +196,7 @@ def night_mode() -> None:
|
|||
fire_flies.factory(settings['autoNightMode']["fireflies_random_color"])
|
||||
|
||||
|
||||
|
||||
def kick_vote_started(started_by: str,started_to: str) -> None:
|
||||
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}.")
|
||||
|
||||
|
|
@ -203,5 +211,5 @@ def on_kick_vote_end():
|
|||
logger.log("Kick vote End")
|
||||
|
||||
|
||||
_hooks.kick_vote_started=kick_vote_started
|
||||
_hooks.on_kicked=on_kicked
|
||||
_hooks.kick_vote_started = kick_vote_started
|
||||
_hooks.on_kicked = on_kicked
|
||||
|
|
|
|||
70
dist/ba_root/mods/features/EndVote.py
vendored
Normal file
70
dist/ba_root/mods/features/EndVote.py
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import _ba, ba
|
||||
import time
|
||||
"""
|
||||
End Vote by mr.smoothy
|
||||
with no timer and minimum message
|
||||
for BCS scripts only
|
||||
"""
|
||||
last_end_vote_start_time = 0
|
||||
end_vote_duration = 30
|
||||
game_started_on = 0
|
||||
min_game_duration_to_start_end_vote = 60
|
||||
|
||||
voters = []
|
||||
|
||||
|
||||
def vote_end(pb_id, client_id):
|
||||
global voters
|
||||
global last_end_vote_start_time
|
||||
now = time.time()
|
||||
if now > last_end_vote_start_time + end_vote_duration:
|
||||
voters = []
|
||||
last_end_vote_start_time = now
|
||||
if now < game_started_on + min_game_duration_to_start_end_vote:
|
||||
_ba.screenmessage("Seems game just started, Try again after some time", transient=True,
|
||||
clients=[client_id])
|
||||
if len(voters) == 0:
|
||||
_ba.chatmessage("end vote started")
|
||||
|
||||
# clean up voters list
|
||||
active_players = []
|
||||
for player in _ba.get_game_roster():
|
||||
active_players.append(player['account_id'])
|
||||
for voter in voters:
|
||||
if voter not in active_players:
|
||||
voters.remove(voter)
|
||||
if pb_id not in voters:
|
||||
voters.append(pb_id)
|
||||
_ba.screenmessage("Thanks for vote , encourage other players to type 'end' too.", transient=True,
|
||||
clients=[client_id])
|
||||
|
||||
if len(voters) >= required_votes(len(active_players)):
|
||||
_ba.chatmessage("end vote succeed")
|
||||
try:
|
||||
with _ba.Context(_ba.get_foreground_host_activity()):
|
||||
_ba.get_foreground_host_activity().end_game()
|
||||
except:
|
||||
pass
|
||||
|
||||
elif required_votes(len(active_players)) - len(
|
||||
voters) == 3: # lets dont spam chat/screen message with votes required , only give message when only 3 votes left
|
||||
_ba.chatmessage("3 more end votes required")
|
||||
|
||||
|
||||
def required_votes(players):
|
||||
if players == 2:
|
||||
return 2
|
||||
elif players == 3:
|
||||
return 3
|
||||
elif players == 4:
|
||||
return 2
|
||||
elif players == 5:
|
||||
return 3
|
||||
elif players == 6:
|
||||
return 3
|
||||
elif players == 7:
|
||||
return 4
|
||||
elif players == 8:
|
||||
return 4
|
||||
else:
|
||||
return players - 3
|
||||
1
dist/ba_root/mods/setting.json
vendored
1
dist/ba_root/mods/setting.json
vendored
|
|
@ -87,6 +87,7 @@
|
|||
"lobby_idle_time_in_secs":10
|
||||
},
|
||||
"allowTeamChat":true,
|
||||
"allowEndVote":true,
|
||||
"sameCharacterForTeam":false,
|
||||
"newResultBoard":true,
|
||||
"HostDeviceName":"v1.4",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue