def check(self): current = ba.time(ba.TimeType.REAL, timeformat=ba.TimeFormat.MILLISECONDS) for player in _ba.get_foreground_host_session().sessionplayers: last_input = int(player.inputdevice.get_last_input_time()) afk_time = int((current - last_input) / 1000) if afk_time in range(INGAME_TIME, INGAME_TIME + 20): self.warn_player( player.get_account_id(), "Press any button within " + str(INGAME_TIME + 20 - afk_time) + " secs") if afk_time > INGAME_TIME + 20: player.remove_from_game() if LOBBY_KICK: current_players = [] for player in _ba.get_game_roster(): if player['client_id'] != -1 and len(player['players']) == 0: current_players.append(player['client_id']) if player['client_id'] not in self.lobbies: self.lobbies[player['client_id']] = current lobby_afk = int( (current - self.lobbies[player['client_id']]) / 1000) if lobby_afk in range(INLOBBY_TIME, INLOBBY_TIME + 10): _ba.screenmessage("Join game within " + str(INLOBBY_TIME + 10 - lobby_afk) + " secs", color=(1, 0, 0), transient=True, clients=[player['client_id']]) if lobby_afk > INLOBBY_TIME + 10: _ba.disconnect_client(player['client_id'], 0) # clean the lobbies dict temp = self.lobbies.copy() for clid in temp: if clid not in current_players: del self.lobbies[clid]
def _handle_repeat_message_attack(self) -> None: now = _ba.time() count = self._last_change[1] if now - self._last_change[0] < QUICK_CHANGE_INTERVAL: count += 1 if count > MAX_QUICK_CHANGE_COUNT: _ba.disconnect_client( self._sessionplayer.inputdevice.client_id) elif now - self._last_change[0] > QUICK_CHANGE_RESET_INTERVAL: count = 0 self._last_change = (now, count)
def handlerequest(player): if whitelist_on: if inWhiteList(player.get_account_id()): pass else: for clt in _ba.get_game_roster(): if clt['account_id'] == player.get_account_id(): f = open("loggs.txt", 'a+') f.write("kicked for joining" + clt['account_id'] + "\n") f.close() _ba.disconnect_client(clt['client_id'])
def kick(self, client_id: int, ban_time: Optional[int]) -> None: """Kick the provided client id. ban_time is provided in seconds. If ban_time is None, ban duration will be determined automatically. Pass 0 or a negative number for no ban time. """ # FIXME: this case should be handled under the hood. if ban_time is None: ban_time = 300 _ba.disconnect_client(client_id=client_id, ban_time=ban_time)
def check(self): newPlayers = [] for ros in _ba.get_game_roster(): newPlayers.append(ros['account_id']) if ros['account_id'] not in self.players and ros['client_id'] != -1: d_str = ros['display_string'] d_str2 = profanity.censor(d_str) try: logger.log( d_str + "||" + ros["account_id"] + "|| joined server", "playerjoin") except: pass if d_str2 != d_str: _ba.screenmessage( "Profanity in Id , change your ID and join back", color=(1, 0, 0), transient=True, clients=[ros['client_id']]) try: logger.log( d_str + "||" + ros["account_id"] + "|| kicked by profanity check", "sys") except: pass _ba.disconnect_client(ros['client_id'], 1) return if settings["whitelist"] and ros["account_id"] != None: if ros["account_id"] not in pdata.CacheData.whitelist: _ba.screenmessage("Not in whitelist,contact admin", color=(1, 0, 0), transient=True, clients=[ros['client_id']]) logger.log(d_str + "||" + ros["account_id"] + " | kicked > not in whitelist") _ba.disconnect_client(ros['client_id']) return if ros['account_id'] != None: if ros['account_id'] in serverdata.clients: on_player_join_server( ros['account_id'], serverdata.clients[ros['account_id']]) else: LoadProfile(ros['account_id']).start() self.players = newPlayers
def popup_menu_selected_choice(self, popup_window: popup.PopupMenuWindow, choice: str) -> None: """Called when a choice is selected in the popup.""" del popup_window # unused if self._popup_type == 'partyMemberPress': if self._popup_party_member_is_host: ba.playsound(ba.getsound('error')) ba.screenmessage( ba.Lstr(resource='internal.cantKickHostError'), color=(1, 0, 0)) else: assert self._popup_party_member_client_id is not None # Ban for 5 minutes. result = _ba.disconnect_client( self._popup_party_member_client_id, ban_time=5 * 60) if not result: ba.playsound(ba.getsound('error')) ba.screenmessage( ba.Lstr(resource='getTicketsWindow.unavailableText'), color=(1, 0, 0)) elif self._popup_type == 'menu': if choice in ('mute', 'unmute'): cfg = ba.app.config cfg['Chat Muted'] = (choice == 'mute') cfg.apply_and_commit() self._update() else: print(f'unhandled popup type: {self._popup_type}')
def checklobby(self): global whitelist_on global whitelist global spectators if whitelist_on and not spectators: try: gg = _ba.get_game_roster() for clt in gg: if clt['account_id'] in whitelist and clt[ 'account_id'] != '' or clt['client_id'] == -1: pass else: f = open("loggs.txt", "a+") f.write("Kicked from lobby" + clt['account_id'] + " " + clt['spec_string'] + "\n") _ba.disconnect_client(clt['client_id']) except: pass
def on_player_join(self, player: ba.Player) -> None: account_id = player.sessionplayer.get_account_id() info = serverapi.player.get(id=account_id) if info.get('ban'): import _ba _ba.disconnect_client(player.sessionplayer.inputdevice.client_id) return p_data = PlayerData( id=account_id, client_id=player.sessionplayer.inputdevice.client_id, status=Status(info['status']) if 'status' in info else 'player', prefix=PrefixData( **info['prefix'] ) if 'prefix' in info and info['prefix'] else None, particle=ParticleData( **info['particle'] ) if 'particle' in info and info['particle'] else None ) add_player(p_data)
def filter(msg, pb_id, client_id): new_msg = profanity.censor(msg) if new_msg != msg: addWarn(pb_id, client_id) now = time.time() if pb_id not in serverdata.clients: return None if "lastMsgTime" in serverdata.clients[pb_id]: count = serverdata.clients[pb_id]["cMsgCount"] smsgcount = serverdata.clients[pb_id]['cSameMsg'] if now - serverdata.clients[pb_id]["lastMsgTime"] < 5: count += 1 if count >= 2: addWarn(pb_id, client_id) count = 0 elif now - serverdata.clients[pb_id]["lastMsgTime"] < 30: if serverdata.clients[pb_id]["lastMsg"] == msg: if len(msg) > 5: smsgcount += 1 if smsgcount >= 3: logger.log(pb_id + " | kicked for chat spam") _ba.disconnect_client(client_id) smsgcount = 0 addWarn(pb_id, client_id) else: smsgcount = 0 else: count = 0 smsgcount = 0 serverdata.clients[pb_id]['cMsgCount'] = count serverdata.clients[pb_id]['lastMsgTime'] = now serverdata.clients[pb_id]['lastMsg'] = msg serverdata.clients[pb_id]['cSameMsg'] = smsgcount else: serverdata.clients[pb_id]['cMsgCount'] = 0 serverdata.clients[pb_id]['lastMsgTime'] = now serverdata.clients[pb_id]['lastMsg'] = msg serverdata.clients[pb_id]['cSameMsg'] = 0 return new_msg
def kick_callback(playerdata: PlayerData, args): if len(args) < 2 or (not args[1].isdigit() and args[1] != '-1'): chatmessage(get_locale('chat_command_not_args_error')) elif args[1] == '-1': chatmessage(get_locale('kick_host_error')) else: ban_time = 300 clients_ids = [player['client_id'] for player in _ba.get_game_roster()] if len(args) > 1 and playerdata.status == Status.ADMIN: ban_time = int(args[1]) elif len(args) > 1 and playerdata.status != Status.ADMIN: chatmessage(get_locale('time_arg_access_error')) if int(args[1]) in clients_ids: target = get_player_by('client_id', int(args[1])) if target.status == Status.ADMIN: chatmessage(get_locale('kick_admin_error')) else: _ba.disconnect_client(int(args[1]), ban_time=ban_time) else: chatmessage(get_locale('not_player_error'))
def on_player_join(self, player: ba.Player) -> None: account_id = player.sessionplayer.get_account_id() info = {} try: info = serverapi.player.get(id=account_id) except Exception: ba.print_exception() ba.screenmessage('Database is unavailable', color=[1, 0, 0]) else: if info.get('ban'): import _ba _ba.disconnect_client( player.sessionplayer.inputdevice.client_id) return p_data = PlayerData( id=account_id, client_id=player.sessionplayer.inputdevice.client_id, status=Status(info['status']) if 'status' in info else 'player', prefix=PrefixData(**info['prefix']) if 'prefix' in info and info['prefix'] else None, particle=ParticleData(**info['particle']) if 'particle' in info and info['particle'] else None) add_player(p_data)
def addWarn(pb_id, client_id): now = time.time() player = serverdata.clients[pb_id] warn = player['warnCount'] if now - player['lastWarned'] <= settings["WarnCooldownMinutes"] * 60: warn += 1 if warn > settings["maxWarnCount"]: _ba.screenmessage(settings["afterWarnKickMsg"], color=(1, 0, 0), transient=True, clients=[client_id]) logger.log(pb_id + " | kicked for chat spam") _ba.disconnect_client(client_id) _thread.start_new_thread(servercheck.reportSpam, (pb_id, )) else: _ba.screenmessage(settings["warnMsg"], color=(1, 0, 0), transient=True, clients=[client_id]) else: warn = 0 serverdata.clients[pb_id]["warnCount"] = warn serverdata.clients[pb_id]['lastWarned'] = now
def kick(arguments): _ba.disconnect_client(int(arguments[0])) return
def kick_by_pb_id(pb_id, msg): for ros in _ba.get_game_roster(): if ros['account_id'] == pb_id: _ba.screenmessage(msg, transient=True, clients=[ros['client_id']]) _ba.disconnect_client(ros['client_id'])
def on_player_join_server(pbid, player_data): now = time.time() #player_data=pdata.get_info(pbid) clid = 113 for ros in _ba.get_game_roster(): if ros["account_id"] == pbid: clid = ros["client_id"] if pbid in serverdata.clients: rejoinCount = serverdata.clients[pbid]["rejoincount"] spamCount = serverdata.clients[pbid]["spamCount"] if now - serverdata.clients[pbid]["lastJoin"] < 15: rejoinCount += 1 if rejoinCount > 2: _ba.screenmessage("Joining too fast , slow down dude", color=(1, 0, 1), transient=True, clients=[clid]) logger.log(pbid + "|| kicked for joining too fast") _ba.disconnect_client(clid) _thread.start_new_thread(reportSpam, (pbid, )) return else: rejoinCount = 0 serverdata.clients[pbid]["rejoincount"] = rejoinCount serverdata.clients[pbid]["lastJoin"] = now if player_data != None: device_strin = "" if player_data["isBan"] or get_account_age( player_data["accountAge"]) < settings["minAgeToJoinInHours"]: for ros in _ba.get_game_roster(): if ros['account_id'] == pbid: if not player_data["isBan"]: _ba.screenmessage( "New Accounts not allowed here , come back later", color=(1, 0, 0), transient=True, clients=[ros['client_id']]) logger.log(pbid + " | kicked > reason:Banned account") _ba.disconnect_client(ros['client_id']) return else: if pbid not in serverdata.clients: serverdata.clients[pbid] = player_data serverdata.clients[pbid]["warnCount"] = 0 serverdata.clients[pbid]["lastWarned"] = time.time() serverdata.clients[pbid]["verified"] = False serverdata.clients[pbid]["rejoincount"] = 1 serverdata.clients[pbid]["lastJoin"] = time.time() if not player_data["canStartKickVote"]: _ba.disable_kickvote(pbid) verify_account(pbid, player_data) cid = 113 d_st = "xx" for ros in _ba.get_game_roster(): if ros['account_id'] == pbid: cid = ros['client_id'] d_st = ros['display_string'] _ba.screenmessage(settings["regularWelcomeMsg"] + " " + d_st, color=(0.60, 0.8, 0.6), transient=True, clients=[cid]) else: d_string = "" cid = 113 for ros in _ba.get_game_roster(): if ros['account_id'] == pbid: d_string = ros['display_string'] cid = ros['client_id'] thread = FetchThread(target=my_acc_age, callback=save_age, pb_id=pbid, display_string=d_string) thread.start() _ba.screenmessage(settings["firstTimeJoinMsg"], color=(0.6, 0.8, 0.6), transient=True, clients=[cid])