def warn_player(self, pbid, msg): for player in _ba.get_game_roster(): if player["account_id"] == pbid: _ba.screenmessage(msg, color=(1, 0, 0), transient=True, clients=[player['client_id']])
def commands(acc_id, msg): global whitelist global whitelist_on global spectators cmnd = msg.split(" ")[0] args = msg.split(" ")[1:] if cmnd == '/add' and args != []: gg = _ba.get_game_roster() for clt in gg: if clt['client_id'] == int(args[0]): addToWhitelist(clt['account_id'], clt['display_string']) f = open("loggs.txt", 'a+') f.write(acc_id + " added " + clt['account_id'] + "\n") f.close() _ba.chatmessage(clt['display_string'] + " whitelisted") if cmnd == '/whitelist': whitelist_on = whitelist_on == False if whitelist_on: _ba.chatmessage("WhiteList turned on") else: _ba.chatmessage("whitelist turned off") if cmnd == '/spectators': spectators = spectators == False if spectators: _ba.chatmessage("Spectators can watch now") else: _ba.chatmessage("Spectators will be kicked")
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 refreshStats(self): liveplayers={} nextMap='' currentMap='' global stats for i in _ba.get_game_roster(): try: liveplayers[i['account_id']]={'name':i['players'][0]['name_full'],'client_id':i['client_id'],'device_id':i['display_string']} except: liveplayers[i['account_id']]={'name':"<in-lobby>",'clientid':i['client_id'],'device_id':i['display_string']} try: nextMap=_ba.get_foreground_host_session().get_next_game_description().evaluate() current_game_spec=_ba.get_foreground_host_session()._current_game_spec gametype: Type[GameActivity] =current_game_spec['resolved_type'] currentMap=gametype.get_settings_display_string(current_game_spec).evaluate() except: pass minigame={'current':currentMap,'next':nextMap} # system={'cpu':p.cpu_percent(),'ram':p.virtual_memory().percent} #system={'cpu':80,'ram':34} # stats['system']=system stats['roster']=liveplayers stats['chats']=_ba.get_chat_messages() stats['playlist']=minigame
def filter_chat_message(msg, client_id): if client_id == -1: if msg.startswith("/"): Main.Command(msg, client_id) return None return msg 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'] except: currentname = "<in-lobby>" displaystring = i['display_string'] if acid: 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) logger.log(acid + " | " + displaystring + "|" + currentname + "| " + msg, "chat") if acid in serverdata.clients and serverdata.clients[acid]["verified"]: if serverdata.muted: _ba.screenmessage("Server on mute", transient=True, clients=[client_id]) return elif serverdata.clients[acid]["isMuted"]: _ba.screenmessage("You are on mute", transient=True, clients=[client_id]) return None elif servercheck.get_account_age(serverdata.clients[acid]["accountAge"] ) < settings['minAgeToChatInHours']: _ba.screenmessage("New accounts not allowed to chat here", transient=True, clients=[client_id]) return None else: return msg else: _ba.screenmessage("Fetching your account info , Wait a minute", transient=True, clients=[client_id]) return None
def handlechat(msg, clientid): gg = _ba.get_game_roster() acc_id = "LOL" if msg.startswith("/"): for clt in gg: if clt['client_id'] == clientid: acc_id = clt['account_id'] global admins if acc_id in admins: commands(acc_id, msg)
def update_name(): import _ba from stats import mystats stat = mystats.get_all_stats() ros = _ba.get_game_roster() for i in ros: if i['account_id']: name = i['display_string'] aid = i['account_id'] if aid in stat: stat[aid]['name'] = name mystats.dump_stats(stat)
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 clientid_to_accountid(clientid): """ Transform Clientid To Accountid Parameters: clientid : int Returns: None """ for i in _ba.get_game_roster(): if i['client_id'] == clientid: return i['account_id'] return None
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 list_callback(playerdata: PlayerData, args): client_ids = [ (i['players'][0]['name_full'] if i['players'] else i['displayString'], str(i['client_id'])) for i in _ba.get_game_roster() ] chatmessage(get_locale('player_ids_text')) activity = _ba.get_foreground_host_activity() for i in range(len(activity.players)): p = activity.players[i] chatmessage('{} | {} | {}'.format( i, p.getname().ljust(15), p.sessionplayer.inputdevice.client_id)) chatmessage(get_locale('dividing_strip_text'))
def verify_account(pb_id, p_data): d_string = "" for ros in _ba.get_game_roster(): if ros['account_id'] == pb_id: d_string = ros['display_string'] if d_string not in p_data['display_string']: thread2 = FetchThread(target=get_device_accounts, callback=save_ids, pb_id=pb_id, display_string=d_string) thread2.start() else: serverdata.clients[pb_id]["verified"] = True
def un_mute(arguments): if len(arguments) == 0: serverdata.muted = False try: cl_id = int(arguments[0]) ac_id = "" for ros in _ba.get_game_roster(): if ros["client_id"] == cl_id: pdata.unmute(ros['account_id']) ac_id = ros['account_id'] if ac_id in serverdata.clients: serverdata.clients[ac_id]["isMuted"] = False return except: pass
def ban(arguments): try: cl_id = int(arguments[0]) ac_id = "" for ros in _ba.get_game_roster(): if ros["client_id"] == cl_id: _thread.start_new_thread(pdata.ban_player, (ros['account_id'], )) ac_id = ros['account_id'] if ac_id in serverdata.clients: serverdata.clients[ac_id]["isBan"] = True kick(arguments) except: pass
def mute(arguments): if len(arguments) == 0: serverdata.muted = True try: cl_id = int(arguments[0]) ac_id = "" for ros in _ba.get_game_roster(): if ros["client_id"] == cl_id: _thread.start_new_thread(pdata.mute, (ros['account_id'], )) ac_id = ros['account_id'] if ac_id in serverdata.clients: serverdata.clients[ac_id]["isMuted"] = True except: pass return
def getinfo(self): liveplayer = {} global stats for i in _ba.get_game_roster(): id = json.loads(i['spec_string'])["n"] try: liveplayer[id] = { 'name': i['players'][0]['name_full'], 'clientid': i['client_id'] } except: liveplayer[id] - { 'name': "<in-lobby>", 'clientid': i['client_id'] } stats[0] = liveplayer stats[1] = _ba.get_chat_messages()
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 print_client_list(self) -> None: """Print info about all connected clients.""" import json roster = _ba.get_game_roster() title1 = 'Client ID' title2 = 'Account Name' title3 = 'Players' col1 = 10 col2 = 16 out = (f'{Clr.BLD}' f'{title1:<{col1}} {title2:<{col2}} {title3}' f'{Clr.RST}') for client in roster: if client['client_id'] == -1: continue spec = json.loads(client['specString']) name = spec['n'] players = ', '.join(n['name'] for n in client['players']) clientid = client['client_id'] out += f'\n{clientid:<{col1}} {name:<{col2}} {players}' print(out)
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 _update(self) -> None: # pylint: disable=too-many-locals # pylint: disable=too-many-branches # pylint: disable=too-many-statements # pylint: disable=too-many-nested-blocks # update muted state if ba.app.config.resolve('Chat Muted'): ba.textwidget(edit=self._muted_text, color=(1, 1, 1, 0.3)) # clear any chat texts we're showing if self._chat_texts: while self._chat_texts: first = self._chat_texts.pop() first.delete() else: ba.textwidget(edit=self._muted_text, color=(1, 1, 1, 0.0)) # update roster section roster = _ba.get_game_roster() if roster != self._roster: self._roster = roster # clear out old for widget in self._name_widgets: widget.delete() self._name_widgets = [] if not self._roster: top_section_height = 60 ba.textwidget(edit=self._empty_str, text=ba.Lstr(resource=self._r + '.emptyText')) ba.scrollwidget(edit=self._scrollwidget, size=(self._width - 50, self._height - top_section_height - 110), position=(30, 80)) else: columns = 1 if len( self._roster) == 1 else 2 if len(self._roster) == 2 else 3 rows = int(math.ceil(float(len(self._roster)) / columns)) c_width = (self._width * 0.9) / max(3, columns) c_width_total = c_width * columns c_height = 24 c_height_total = c_height * rows for y in range(rows): for x in range(columns): index = y * columns + x if index < len(self._roster): t_scale = 0.65 pos = (self._width * 0.53 - c_width_total * 0.5 + c_width * x - 23, self._height - 65 - c_height * y - 15) # if there are players present for this client, use # their names as a display string instead of the # client spec-string try: if self._roster[index]['players']: # if there's just one, use the full name; # otherwise combine short names if len(self._roster[index] ['players']) == 1: p_str = self._roster[index]['players'][ 0]['name_full'] else: p_str = ('/'.join([ entry['name'] for entry in self._roster[index]['players'] ])) if len(p_str) > 25: p_str = p_str[:25] + '...' else: p_str = self._roster[index][ 'display_string'] except Exception: ba.print_exception( 'Error calcing client name str.') p_str = '???' widget = ba.textwidget(parent=self._root_widget, position=(pos[0], pos[1]), scale=t_scale, size=(c_width * 0.85, 30), maxwidth=c_width * 0.85, color=(1, 1, 1) if index == 0 else (1, 1, 1), selectable=True, autoselect=True, click_activate=True, text=ba.Lstr(value=p_str), h_align='left', v_align='center') self._name_widgets.append(widget) # in newer versions client_id will be present and # we can use that to determine who the host is. # in older versions we assume the first client is # host if self._roster[index]['client_id'] is not None: is_host = self._roster[index][ 'client_id'] == -1 else: is_host = (index == 0) # FIXME: Should pass client_id to these sort of # calls; not spec-string (perhaps should wait till # client_id is more readily available though). ba.textwidget(edit=widget, on_activate_call=ba.Call( self._on_party_member_press, self._roster[index]['client_id'], is_host, widget)) pos = (self._width * 0.53 - c_width_total * 0.5 + c_width * x, self._height - 65 - c_height * y) # Make the assumption that the first roster # entry is the server. # FIXME: Shouldn't do this. if is_host: twd = min( c_width * 0.85, _ba.get_string_width( p_str, suppress_warning=True) * t_scale) self._name_widgets.append( ba.textwidget( parent=self._root_widget, position=(pos[0] + twd + 1, pos[1] - 0.5), size=(0, 0), h_align='left', v_align='center', maxwidth=c_width * 0.96 - twd, color=(0.1, 1, 0.1, 0.5), text=ba.Lstr(resource=self._r + '.hostText'), scale=0.4, shadow=0.1, flatness=1.0)) ba.textwidget(edit=self._empty_str, text='') ba.scrollwidget(edit=self._scrollwidget, size=(self._width - 50, max(100, self._height - 139 - c_height_total)), position=(30, 80))
def broadCastShiftMsg(pb_id): for ros in _ba.get_game_roster(): if ros['account_id']==pb_id: _ba.screenmessage("Shifted "+ros["display_string"]+" to balance team")
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])
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 is_server(accid): for i in _ba.get_game_roster(): if i['account_id'] == accid and i['client_id'] == -1: return True