limited max players per IP, account

This commit is contained in:
Ayush Saini 2023-03-05 22:06:59 +05:30
parent 8dd18890f5
commit 9d2d44109c
5 changed files with 38 additions and 5 deletions

View file

@ -38,6 +38,10 @@
"75": { "75": {
"log": "bug fixes, BS 1.7.19 , season end notfication, server restart notification, more maps and games", "log": "bug fixes, BS 1.7.19 , season end notfication, server restart notification, more maps and games",
"time": "4 March 2023" "time": "4 March 2023"
},
"76": {
"log": "added limit for max players per IP address , account at a time.",
"time": "5 March 2023"
} }
} }

View file

@ -25,7 +25,7 @@ from bastd.activity.coopscore import CoopScoreScreen
import setting import setting
from chatHandle import handlechat from chatHandle import handlechat
from features import team_balancer, afk_check, fire_flies, dual_team_score as newdts from features import team_balancer, afk_check, fire_flies, hearts, dual_team_score as newdts
from stats import mystats from stats import mystats
from spazmod import modifyspaz from spazmod import modifyspaz
from tools import servercheck, ServerUpdate, logger, playlist from tools import servercheck, ServerUpdate, logger, playlist
@ -78,6 +78,7 @@ def score_screen_on_begin(_stats: ba.Stats) -> None:
"""Runs when score screen is displayed.""" """Runs when score screen is displayed."""
team_balancer.balanceTeams() team_balancer.balanceTeams()
mystats.update(_stats) mystats.update(_stats)
announcement.showScoreScreenAnnouncement()
def playerspaz_init(playerspaz: ba.Player, node: ba.Node, player: ba.Player): def playerspaz_init(playerspaz: ba.Player, node: ba.Node, player: ba.Player):
@ -194,7 +195,6 @@ def new_end(self, results: Any = None, delay: float = 0.0, force: bool = False):
_ba.prop_axis(1, 0, 0) _ba.prop_axis(1, 0, 0)
if isinstance(activity, CoopScoreScreen): if isinstance(activity, CoopScoreScreen):
team_balancer.checkToExitCoop() team_balancer.checkToExitCoop()
announcement.showScoreScreenAnnouncement()
org_end(self, results, delay, force) org_end(self, results, delay, force)
ba._activity.Activity.end = new_end ba._activity.Activity.end = new_end
@ -251,7 +251,6 @@ def on_map_init():
from ba._servermode import ServerController from ba._servermode import ServerController
def shutdown(func) -> None: def shutdown(func) -> None:
"""Set the app to quit either now or at the next clean opportunity.""" """Set the app to quit either now or at the next clean opportunity."""
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
@ -272,3 +271,18 @@ def shutdown(func) -> None:
func(*args, **kwargs) func(*args, **kwargs)
return wrapper return wrapper
ServerController.shutdown = shutdown(ServerController.shutdown) ServerController.shutdown = shutdown(ServerController.shutdown)
from ba._session import Session
def on_player_request(func) -> bool:
def wrapper(*args, **kwargs):
player = args[1]
count = 0
for current_player in args[0].sessionplayers:
if current_player.get_v1_account_id() == player.get_v1_account_id():
count +=1
if count >= settings["maxPlayersPerDevice"]:
_ba.screenmessage("Reached max players limit per device",clients=[player.inputdevice.client_id],transient=True,)
return False
return func(*args, **kwargs)
return wrapper
Session.on_player_request = on_player_request(Session.on_player_request)

View file

@ -109,6 +109,8 @@
"minAgeToJoinInHours":24, "minAgeToJoinInHours":24,
"maxWarnCount":2, "maxWarnCount":2,
"WarnCooldownMinutes":30, "WarnCooldownMinutes":30,
"maxAccountPerIP":1,
"maxPlayersPerDevice":1,
"warnMsg":"WARNING !!!", "warnMsg":"WARNING !!!",
"afterWarnKickMsg":"Enough warnings, Goodbye have a nice day :)", "afterWarnKickMsg":"Enough warnings, Goodbye have a nice day :)",
"firstTimeJoinMsg":"Welcome to the server,we r saving all your account details and chats", "firstTimeJoinMsg":"Welcome to the server,we r saving all your account details and chats",

View file

@ -6,7 +6,7 @@ from efro.terminal import Clr
import json import json
import requests import requests
import _ba import _ba
VERSION=75 VERSION=76
def check(): def check():

View file

@ -31,11 +31,24 @@ class checkserver(object):
def check(self): def check(self):
newPlayers = [] newPlayers = []
ipClientMap = {}
for ros in ba.internal.get_game_roster(): for ros in ba.internal.get_game_roster():
ip = _ba.get_client_ip(ros["client_id"])
if ip not in ipClientMap:
ipClientMap[ip] = [ros["client_id"]]
else:
ipClientMap[ip].append(ros["client_id"])
if len(ipClientMap[ip]) >= settings['maxAccountPerIP']:
_ba.chatmessage(f"Only {settings['maxAccountPerIP']} player per IP allowed, disconnecting this device.", clients=[ros["client_id"]])
ba.internal.disconnect_client(ros["client_id"])
logger.log(" Player disconnected, reached max players per IP address ||"+ ros["account_id"] ,
"playerjoin")
continue
newPlayers.append(ros['account_id']) newPlayers.append(ros['account_id'])
if ros['account_id'] not in self.players and ros[ if ros['account_id'] not in self.players and ros[
'client_id'] != -1: 'client_id'] != -1:
# new player joined lobby
d_str = ros['display_string'] d_str = ros['display_string']
d_str2 = profanity.censor(d_str) d_str2 = profanity.censor(d_str)
try: try: