logging fix , playlist fallback

This commit is contained in:
Ayush Saini 2023-01-06 01:55:43 +05:30
parent 436ee54ba2
commit 0dfe2de8e5
6 changed files with 109 additions and 110 deletions

View file

@ -105,9 +105,16 @@ class MultiTeamSession(Session):
add_resolved_type=True,
name='default teams' if self.use_teams else 'default ffa',
)
default_playlist_resolved = _playlist.filter_playlist(
_playlist.get_default_teams_playlist(),
sessiontype=type(self),
add_resolved_type=True,
name='default teams' if self.use_teams else 'default ffa',
)
if not playlist_resolved:
raise RuntimeError('Playlist contains no valid games.')
print("PLAYLIST CONTAINS NO VALID GAMES , FALLING BACK TO DEFAULT TEAM PLAYLIST")
playlist_resolved = default_playlist_resolved
# raise RuntimeError('Playlist contains no valid games.')
self._playlist = ShuffleList(
playlist_resolved, shuffle=self._playlist_randomize

View file

@ -1,58 +1,58 @@
# Released under the MIT License. See LICENSE for details.
from playersData import pdata
import ba
import ba.internal
def clientid_to_accountid(clientid):
"""
Transform Clientid To Accountid
Parameters:
clientid : int
Returns:
None
"""
for i in ba.internal.get_game_roster():
if i['client_id'] == clientid:
return i['account_id']
return None
def check_permissions(accountid, command):
"""
Checks The Permission To Player To Executive Command
Parameters:
accountid : str
command : str
Returns:
Boolean
"""
roles = pdata.get_roles()
if is_server(accountid):
return True
for role in roles:
if accountid in roles[role]["ids"] and "ALL" in roles[role]["commands"]:
return True
elif accountid in roles[role]["ids"] and command in roles[role]["commands"]:
return True
return False
def is_server(accid):
for i in ba.internal.get_game_roster():
if i['account_id']==accid and i['client_id']==-1:
return True
# Released under the MIT License. See LICENSE for details.
from playersData import pdata
import ba
import ba.internal
def clientid_to_accountid(clientid):
"""
Transform Clientid To Accountid
Parameters:
clientid : int
Returns:
None
"""
for i in ba.internal.get_game_roster():
if i['client_id'] == clientid:
return i['account_id']
return None
def check_permissions(accountid, command):
"""
Checks The Permission To Player To Executive Command
Parameters:
accountid : str
command : str
Returns:
Boolean
"""
roles = pdata.get_roles()
if is_server(accountid):
return True
for role in roles:
if accountid in roles[role]["ids"] and "ALL" in roles[role]["commands"]:
return True
elif accountid in roles[role]["ids"] and command in roles[role]["commands"]:
return True
return False
def is_server(accid):
for i in ba.internal.get_game_roster():
if i['account_id']==accid and i['client_id']==-1:
return True

View file

@ -5,43 +5,30 @@ import ba.internal
def send(msg, clientid):
"""Shortcut To Send Private Msg To Client"""
ba.internal.chatmessage(str(msg), clients=[clientid])
_ba.screenmessage(str(msg), transient=True, clients=[clientid])
"""Shortcut To Send Private Msg To Client"""
for m in msg.split("\n"):
ba.internal.chatmessage(str(m), clients=[clientid])
_ba.screenmessage(str(msg), transient=True, clients=[clientid])
def clientid_to_myself(clientid):
"""Return Player Index Of Self Player"""
for i , player in enumerate(_ba.get_foreground_host_activity().players):
if player.sessionplayer.inputdevice.client_id == clientid:
return i
"""Return Player Index Of Self Player"""
for i , player in enumerate(_ba.get_foreground_host_activity().players):
if player.sessionplayer.inputdevice.client_id == clientid:
return i
def handlemsg(client, msg):
"""Handles Spaz Msg For Single Player"""
activity = _ba.get_foreground_host_activity()
activity.players[client].actor.node.handlemessage(msg)
"""Handles Spaz Msg For Single Player"""
activity = _ba.get_foreground_host_activity()
activity.players[client].actor.node.handlemessage(msg)
def handlemsg_all(msg):
"""Handle Spaz message for all players in activity"""
"""Handle Spaz message for all players in activity"""
activity = _ba.get_foreground_host_activity()
activity = _ba.get_foreground_host_activity()
for i in activity.players:
i.actor.node.handlemessage(msg)
for i in activity.players:
i.actor.node.handlemessage(msg)

View file

@ -18,6 +18,7 @@ def filter_chat_message(msg, client_id):
if msg.startswith("/"):
Main.Command(msg, client_id)
return None
logger.log("Host msg: |" + msg , "chat")
return msg
acid = ""
displaystring = ""
@ -35,6 +36,7 @@ def filter_chat_message(msg, client_id):
msg = ChatFilter.filter(msg, acid, client_id)
if msg == None:
return
logger.log(acid + " | " + displaystring + " | " + currentname + " | " + msg, "chat")
if msg.startswith("/"):
return Main.Command(msg, client_id)
@ -46,8 +48,6 @@ def filter_chat_message(msg, client_id):
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"]:
if serverdata.muted:

View file

@ -12,7 +12,10 @@ import os
import _thread
import logging
logging.getLogger('asyncio').setLevel(logging.WARNING)
client = Bot(command_prefix='!')
intents = discord.Intents().all()
client = Bot(command_prefix='!', intents=intents)
# client = discord.Client()
@ -31,12 +34,10 @@ def push_log(msg):
logs.append(msg)
def init():
loop = asyncio.get_event_loop()
loop.create_task(client.start(token))
Thread(target=loop.run_forever).start()
channel=None
@ -46,7 +47,7 @@ async def on_message(message):
if message.author == client.user:
return
channel=message.channel
if message.channel.id==logsChannelID:
_ba.pushcall(Call(ba.internal.chatmessage,message.content),from_other_thread=True)
@ -54,7 +55,7 @@ async def on_message(message):
@client.event
async def on_ready():
print("Discord bot logged in as: %s, %s" % (client.user.name, client.user.id))
await verify_channel()
async def verify_channel():
@ -81,10 +82,10 @@ async def refresh_stats():
await client.wait_until_ready()
while not client.is_closed():
await livestatsmsgs[0].edit(content=get_live_players_msg())
await livestatsmsgs[1].edit(content=get_chats())
await asyncio.sleep(5)
await asyncio.sleep(10)
async def send_logs():
global logs
@ -101,7 +102,7 @@ async def send_logs():
if msg:
await channel.send(msg)
await asyncio.sleep(5)
await asyncio.sleep(10)
@ -143,7 +144,7 @@ class BsDataThread(object):
self.refreshStats()
self.Timer = ba.Timer( 8,ba.Call(self.refreshStats),repeat = True)
# self.Timerr = ba.Timer( 10,ba.Call(self.refreshLeaderboard),timetype = ba.TimeType.REAL,repeat = True)
# def refreshLeaderboard(self):
# global leaderboard
# global top200
@ -152,7 +153,7 @@ class BsDataThread(object):
# lboard=json.loads(f.read())
# leaderboard=lboard
# entries = [(a['scores'], a['kills'], a['deaths'], a['games'], a['name_html'], a['aid'],a['last_seen']) for a in lboard.values()]
# entries.sort(reverse=True)
# rank=0
# for entry in entries:
@ -161,25 +162,25 @@ class BsDataThread(object):
# break
# _t200[entry[5]]={"rank":rank,"scores":int(entry[0]),"games":int(entry[3]),"kills":int(entry[1]),"deaths":int(entry[2]),"name_html":entry[4],"last_seen":entry[6]}
# top200=_t200
def refreshStats(self):
liveplayers={}
nextMap=''
currentMap=''
global stats
for i in ba.internal.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:
try:
nextMap=ba.internal.get_foreground_host_session().get_next_game_description().evaluate()
current_game_spec=ba.internal.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
@ -191,6 +192,6 @@ class BsDataThread(object):
stats['chats']=ba.internal.get_chat_messages()
stats['playlist']=minigame
# stats['teamInfo']=self.getTeamInfo()

View file

@ -1,8 +1,6 @@
# Released under the MIT License. See LICENSE for details.
# NOT COMPLETED YET
from serverData import serverdata
from playersData import pdata
import _ba
@ -123,6 +121,10 @@ def on_player_join_server(pbid, player_data):
color=(1, 0, 0), transient=True,
clients=[ros['client_id']])
logger.log(pbid + " | kicked > reason:Banned account")
_ba.screenmessage(
"Contact server owner, your account not allowed here",
color=(1, 0, 0), transient=True,
clients=[ros['client_id']])
ba.internal.disconnect_client(ros['client_id'])
return
@ -152,7 +154,7 @@ def on_player_join_server(pbid, player_data):
if(device_id==None):
device_id = _ba.get_client_device_uuid(cid)
serverdata.clients[pbid]["deviceUUID"] = device_id
logger.log("ip:"+serverdata.clients[pbid]["lastIP"]+",Device id"+device_id)
logger.log(pbid+" ip: "+serverdata.clients[pbid]["lastIP"]+", Device id: "+device_id)
_ba.screenmessage(settings["regularWelcomeMsg"] + " " + d_st,
color=(0.60, 0.8, 0.6), transient=True,
clients=[cid])
@ -187,6 +189,7 @@ def check_ban(clid,pbid):
device_id = _ba.get_client_device_uuid(clid)
if (ip in blacklist["ban"]['ips'] or device_id in blacklist['ban']['deviceids'] or pbid in blacklist["ban"]["ids"]):
_ba.chatmessage('sad ,your account is flagged contact server owner for unban',clients=[clid])
logger.log(pbid + " | kicked > reason: Banned account")
ba.internal.disconnect_client(clid)
return True
return False
@ -348,6 +351,7 @@ def reportSpam(id):
if now - profiles[id]["lastSpam"] < 2 * 24 * 60 * 60:
count += 1
if count > 3:
logger.log(id+" auto banned for spamming")
profiles[id]["isBan"] = True
else:
count = 0