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
7
dist/ba_root/mods/chatHandle/handlechat.py
vendored
7
dist/ba_root/mods/chatHandle/handlechat.py
vendored
|
|
@ -5,13 +5,14 @@ from serverData import serverdata
|
||||||
from chatHandle.ChatCommands import Main
|
from chatHandle.ChatCommands import Main
|
||||||
from tools import logger, servercheck
|
from tools import logger, servercheck
|
||||||
from chatHandle.chatFilter import ChatFilter
|
from chatHandle.chatFilter import ChatFilter
|
||||||
|
from features import EndVote
|
||||||
import ba, _ba
|
import ba, _ba
|
||||||
import setting
|
import setting
|
||||||
|
|
||||||
settings = setting.get_settings_data()
|
settings = setting.get_settings_data()
|
||||||
|
|
||||||
def filter_chat_message(msg, client_id):
|
|
||||||
|
|
||||||
|
def filter_chat_message(msg, client_id):
|
||||||
if client_id == -1:
|
if client_id == -1:
|
||||||
if msg.startswith("/"):
|
if msg.startswith("/"):
|
||||||
Main.Command(msg, client_id)
|
Main.Command(msg, client_id)
|
||||||
|
|
@ -38,6 +39,9 @@ def filter_chat_message(msg, client_id):
|
||||||
if msg.startswith(",") and settings["allowTeamChat"]:
|
if msg.startswith(",") and settings["allowTeamChat"]:
|
||||||
return Main.QuickAccess(msg, client_id)
|
return Main.QuickAccess(msg, client_id)
|
||||||
|
|
||||||
|
if msg == "end" and settings["allowEndVote"]:
|
||||||
|
EndVote.vote_end(acid, client_id)
|
||||||
|
|
||||||
logger.log(acid + " | " + displaystring + "|" + currentname + "| " + msg, "chat")
|
logger.log(acid + " | " + displaystring + "|" + currentname + "| " + msg, "chat")
|
||||||
|
|
||||||
if acid in serverdata.clients and serverdata.clients[acid]["verified"]:
|
if acid in serverdata.clients and serverdata.clients[acid]["verified"]:
|
||||||
|
|
@ -59,4 +63,3 @@ def filter_chat_message(msg, client_id):
|
||||||
else:
|
else:
|
||||||
_ba.screenmessage("Fetching your account info , Wait a minute", transient=True, clients=[client_id])
|
_ba.screenmessage("Fetching your account info , Wait a minute", transient=True, clients=[client_id])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
16
dist/ba_root/mods/custom_hooks.py
vendored
16
dist/ba_root/mods/custom_hooks.py
vendored
|
|
@ -14,6 +14,7 @@ from datetime import datetime
|
||||||
|
|
||||||
import _thread
|
import _thread
|
||||||
import importlib
|
import importlib
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
import ba
|
import ba
|
||||||
import _ba
|
import _ba
|
||||||
|
|
@ -29,11 +30,11 @@ from stats import mystats
|
||||||
from spazmod import modifyspaz
|
from spazmod import modifyspaz
|
||||||
from tools import servercheck, ServerUpdate, logger
|
from tools import servercheck, ServerUpdate, logger
|
||||||
from playersData import pdata
|
from playersData import pdata
|
||||||
|
from features import EndVote
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
|
|
||||||
|
|
||||||
settings = setting.get_settings_data()
|
settings = setting.get_settings_data()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,6 +116,7 @@ def import_discord_bot() -> None:
|
||||||
discord_bot.BsDataThread()
|
discord_bot.BsDataThread()
|
||||||
discord_bot.init()
|
discord_bot.init()
|
||||||
|
|
||||||
|
|
||||||
def import_games():
|
def import_games():
|
||||||
"""Imports the custom games from games directory."""
|
"""Imports the custom games from games directory."""
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -129,6 +131,7 @@ def import_games():
|
||||||
if _map.endswith(".py") or _map.endswith(".so"):
|
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:
|
def import_dual_team_score() -> None:
|
||||||
"""Imports the dual team score."""
|
"""Imports the dual team score."""
|
||||||
if settings["newResultBoard"]:
|
if settings["newResultBoard"]:
|
||||||
|
|
@ -139,16 +142,20 @@ def import_dual_team_score() -> None:
|
||||||
|
|
||||||
org_begin = ba._activity.Activity.on_begin
|
org_begin = ba._activity.Activity.on_begin
|
||||||
|
|
||||||
|
|
||||||
def new_begin(self):
|
def new_begin(self):
|
||||||
"""Runs when game is began."""
|
"""Runs when game is began."""
|
||||||
org_begin(self)
|
org_begin(self)
|
||||||
night_mode()
|
night_mode()
|
||||||
|
EndVote.voters = []
|
||||||
|
EndVote.game_started_on = time.time()
|
||||||
|
|
||||||
|
|
||||||
ba._activity.Activity.on_begin = new_begin
|
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."""
|
"""Runs when game is ended."""
|
||||||
activity = _ba.get_foreground_host_activity()
|
activity = _ba.get_foreground_host_activity()
|
||||||
|
|
@ -156,16 +163,18 @@ def new_end(self,results:Any=None,delay:float=0.0,force:bool=False):
|
||||||
team_balancer.checkToExitCoop()
|
team_balancer.checkToExitCoop()
|
||||||
org_end(self, results, delay, force)
|
org_end(self, results, delay, force)
|
||||||
|
|
||||||
|
|
||||||
ba._activity.Activity.end = new_end
|
ba._activity.Activity.end = new_end
|
||||||
|
|
||||||
|
|
||||||
org_player_join = ba._activity.Activity.on_player_join
|
org_player_join = ba._activity.Activity.on_player_join
|
||||||
|
|
||||||
|
|
||||||
def on_player_join(self, player) -> None:
|
def on_player_join(self, player) -> None:
|
||||||
"""Runs when player joins the game."""
|
"""Runs when player joins the game."""
|
||||||
team_balancer.on_player_join()
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -187,7 +196,6 @@ def night_mode() -> None:
|
||||||
fire_flies.factory(settings['autoNightMode']["fireflies_random_color"])
|
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."""
|
"""Logs the kick vote."""
|
||||||
logger.log(f"{started_by} started kick vote for {started_to}.")
|
logger.log(f"{started_by} started kick vote for {started_to}.")
|
||||||
|
|
|
||||||
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
|
"lobby_idle_time_in_secs":10
|
||||||
},
|
},
|
||||||
"allowTeamChat":true,
|
"allowTeamChat":true,
|
||||||
|
"allowEndVote":true,
|
||||||
"sameCharacterForTeam":false,
|
"sameCharacterForTeam":false,
|
||||||
"newResultBoard":true,
|
"newResultBoard":true,
|
||||||
"HostDeviceName":"v1.4",
|
"HostDeviceName":"v1.4",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue