Commands clean up, whitelist

This commit is contained in:
snowman1711 2021-04-17 22:34:48 +05:30
parent ed973afd38
commit 0a7cf38197
54 changed files with 2212 additions and 1144 deletions

View file

@ -0,0 +1,46 @@
# Released under the MIT License. See LICENSE for details.
from PlayersData import pdata
import ba, _ba
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 cheak_permissions(accountid, command):
"""
Checks The Permission To Player To Executive Command
Parameters:
accountid : str
command : str
Returns:
Boolean
"""
roles = pdata.get_roles()
for role in roles:
if accountid in roles[role]["ids"] and command in roles[role]["commands"]:
return True
return False

View file

@ -0,0 +1,84 @@
# Released under the MIT License. See LICENSE for details.
from .Handlers import clientid_to_accountid, cheak_permissions
from .Objects import NormalCommands
from .Objects import Management
from .Objects import Fun
from .Objects import Cheats
import ba, _ba
import setting
def command_type(command):
"""
Checks The Command Type
Parameters:
command : str
Returns:
any
"""
if command in NormalCommands.Commands or command in NormalCommands.CommandAliases:
return "Normal"
if command in Management.Commands or command in Management.CommandAliases:
return "Manage"
if command in Fun.Commands or command in Fun.CommandAliases:
return "Fun"
if command in Cheats.Commands or command in Cheats.CommandAliases:
return "Cheats"
def Command(msg, clientid):
"""
Command Execution
Parameters:
msg : str
clientid : int
Returns:
any
"""
command = msg.lower().split(" ")[0].split("/")[1]
arguments = msg.lower().split(" ")[1:]
accountid = clientid_to_accountid(clientid)
if command_type(command) == "Normal":
NormalCommands.ExcelCommand(command, arguments, clientid, accountid)
elif command_type(command) == "Manage":
if cheak_permissions(accountid, command):
Management.ExcelCommand(command, arguments, clientid, accountid)
elif command_type(command) == "Fun":
if cheak_permissions(accountid, command):
Fun.ExcelCommand(command, arguments, clientid, accountid)
elif command_type(command) == "Cheats":
if cheak_permissions(accountid, command):
Cheats.ExcelCommand(command, arguments, clientid, accountid)
settings = setting.get_settings_data()
if settings["ChatCommands"]["BrodcastCommand"]:
return msg
return None

View file

@ -0,0 +1,310 @@
from .Handlers import handlemsg, handlemsg_all, clientid_to_myself
import ba, _ba
Commands = ['kill', 'heal', 'curse', 'sleep', 'superpunch', 'gloves', 'shield', 'freeze', 'unfreeze', 'godmode']
CommandAliases = ['die', 'heath', 'cur', 'sp', 'punch', 'protect', 'ice', 'thaw', 'gm']
def ExcelCommand(command, arguments, clientid, accountid):
"""
Checks The Command And Run Function
Parameters:
command : str
arguments : str
clientid : int
accountid : int
Returns:
None
"""
if command in ['kill', 'die']:
kill(arguments, clientid)
elif command in ['heal', 'heath']:
heal(arguments, clientid)
elif command in ['curse', 'cur']:
curse(arguments, clientid)
elif command == 'sleep':
sleep(arguments, clientid)
elif command in ['sp', 'superpunch']:
super_punch(arguments, clientid)
elif command in ['gloves', 'punch']:
gloves(arguments, clientid)
elif command in ['shield', 'protect']:
shield(arguments, clientid)
elif command in ['freeze', 'ice']:
freeze(arguments, clientid)
elif command in ['unfreeze', 'thaw']:
un_freeze(arguments, clientid)
elif command in ['gm', 'godmode']:
god_mode(arguments, clientid)
def kill(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.DieMessage())
elif arguments[0] == 'all':
handlemsg_all(ba.DieMessage())
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.DieMessage())
except:
return
def heal(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.PowerupMessage(poweruptype='health'))
elif arguments[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='health'))
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='health'))
except:
return
def curse(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.PowerupMessage(poweruptype='curse'))
elif arguments[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='curse'))
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='curse'))
except:
return
def sleep(arguments, clientid):
activity = _ba.get_foreground_host_activity()
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
activity.players[myself].actor.node.handlemessage('knockout', 8000)
elif arguments[0] == 'all':
for i in activity.players:
i.actor.node.handlemessage('knockout', 8000)
else:
try:
req_player = int(arguments[0])
activity.players[req_player].actor.node.handlemessage('knockout', 8000)
except:
return
def super_punch(arguments, clientid):
activity = _ba.get_foreground_host_activity()
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
if activity.players[myself].actor._punch_power_scale != 15:
activity.players[myself].actor._punch_power_scale = 15
activity.players[myself].actor._punch_cooldown = 0
else:
activity.players[myself].actor._punch_power_scale = 1.2
activity.players[myself].actor._punch_cooldown = 400
elif arguments[0] == 'all':
activity = _ba.get_foreground_host_activity()
for i in activity.players:
if i.actor._punch_power_scale != 15:
i.actor._punch_power_scale = 15
i.actor._punch_cooldown = 0
else:
i.actor._punch_power_scale = 1.2
i.actor._punch_cooldown = 400
else:
try:
activity = _ba.get_foreground_host_activity()
req_player = int(arguments[0])
if activity.players[req_player].actor._punch_power_scale != 15:
activity.players[req_player].actor._punch_power_scale = 15
activity.players[req_player].actor._punch_cooldown = 0
else:
activity.players[req_player].actor._punch_power_scale = 1.2
activity.players[req_player].actor._punch_cooldown = 400
except:
return
def gloves(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.PowerupMessage(poweruptype='punch'))
elif arguments[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='punch'))
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='punch'))
except:
return
def shield(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.PowerupMessage(poweruptype='shield'))
elif arguments[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='shield'))
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='shield'))
except:
return
def freeze(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.FreezeMessage())
elif arguments[0] == 'all':
handlemsg_all(ba.FreezeMessage())
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.FreezeMessage())
except:
return
def un_freeze(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
handlemsg(myself, ba.ThawMessage())
elif arguments[0] == 'all':
handlemsg_all(ba.ThawMessage())
else:
try:
req_player = int(arguments[0])
handlemsg(req_player, ba.ThawMessage())
except:
return
def god_mode(arguments, clientid):
if arguments == [] or arguments == ['']:
myself = clientid_to_myself(clientid)
activity = _ba.get_foreground_host_activity()
player = activity.players[myself].actor
if player._punch_power_scale != 7:
player._punch_power_scale = 7
player.node.hockey = True
player.node.invincible = True
else:
player._punch_power_scale = 1.2
player.node.hockey = False
player.node.invincible = False
elif arguments[0] == 'all':
activity = _ba.get_foreground_host_activity()
for i in activity.players:
if i.actor._punch_power_scale != 7:
i.actor._punch_power_scale = 7
i.actor.node.hockey = True
i.actor.node.invincible = True
else:
i.actor._punch_power_scale = 1.2
i.actor.node.hockey = False
i.actor.node.invincible = False
else:
activity = _ba.get_foreground_host_activity()
req_player = int(arguments[0])
player = activity.players[req_player].actor
if player._punch_power_scale != 7:
player._punch_power_scale = 7
player.node.hockey = True
player.node.invincible = True
else:
player._punch_power_scale = 1.2
player.node.hockey = False
player.node.invincible = False

View file

@ -0,0 +1,209 @@
from .Handlers import handlemsg, handlemsg_all
import ba, _ba
Commands = ['fly', 'invisible', 'headless', 'creepy', 'celebrate', 'spaz']
CommandAliases = ['inv', 'hl', 'creep', 'celeb']
def ExcelCommand(command, arguments, clientid, accountid):
"""
Checks The Command And Run Function
Parameters:
command : str
arguments : str
clientid : int
accountid : int
Returns:
None
"""
if command == 'fly':
fly(arguments)
elif command in ['inv', 'invisible']:
invi(arguments)
elif command in ['hl', 'headless']:
headless(arguments)
elif command in ['creepy', 'creep']:
creep(arguments)
elif command in ['celebrate', 'celeb']:
celeb(arguments)
elif command == 'spaz':
spaz(arguments)
def fly(arguments):
if arguments == [] or arguments == ['']:
return
elif arguments[0] == 'all':
activity = _ba.get_foreground_host_activity()
for players in activity.players:
if players.actor.node.fly != True:
players.actor.node.fly = True
else:
players.actor.node.fly = False
else:
try:
activity = _ba.get_foreground_host_activity()
player = int(arguments[0])
if activity.players[player].actor.node.fly != True:
activity.players[player].actor.node.fly = True
else:
activity.players[player].actor.node.fly = False
except:
return
def invi(arguments):
if arguments == [] or arguments == ['']:
return
elif arguments[0] == 'all':
activity = _ba.get_foreground_host_activity()
for i in activity.players:
body = i.actor.node
if body.torso_model != None:
body.head_model = None
body.torso_model = None
body.upper_arm_model = None
body.forearm_model = None
body.pelvis_model = None
body.hand_model = None
body.toes_model = None
body.upper_leg_model = None
body.lower_leg_model = None
body.style = 'cyborg'
else:
player = int(arguments[0])
activity = _ba.get_foreground_host_activity()
body = activity.players[player].actor.node
if body.torso_model != None:
body.head_model = None
body.torso_model = None
body.upper_arm_model = None
body.forearm_model = None
body.pelvis_model = None
body.hand_model = None
body.toes_model = None
body.upper_leg_model = None
body.lower_leg_model = None
body.style = 'cyborg'
def headless(arguments):
if arguments == [] or arguments == ['']:
return
elif arguments[0] == 'all':
activity = _ba.get_foreground_host_activity()
for players in activity.players:
node = players.actor.node
if node.head_model != None:
node.head_model = None
node.style='cyborg'
else:
try:
player = int(arguments[0])
activity = _ba.get_foreground_host_activity()
node = activity.players[player].actor.node
if node.head_model != None:
node.head_model = None
node.style='cyborg'
except:
return
def creep(arguments):
if arguments == [] or arguments == ['']:
return
elif arguments[0] == 'all':
activity = _ba.get_foreground_host_activity()
for players in activity.players:
node = players.actor.node
if node.head_model != None:
node.head_model = None
node.handlemessage(ba.PowerupMessage(poweruptype='punch'))
node.handlemessage(ba.PowerupMessage(poweruptype='shield'))
else:
try:
player = int(arguments[0])
activity = _ba.get_foreground_host_activity()
node = activity.players[player].actor.node
if node.head_model != None:
node.head_model = None
node.handlemessage(ba.PowerupMessage(poweruptype='punch'))
node.handlemessage(ba.PowerupMessage(poweruptype='shield'))
except:
return
def celeb(arguments):
if arguments == [] or arguments == ['']:
return
elif arguments[0] == 'all':
handlemsg_all(ba.CelebrateMessage())
else:
try:
player = int(arguments[0])
handlemsg(player, ba.CelebrateMessage())
except:
return
def spaz(arguments):
if arguments == [] or arguments == ['']:
return
return

View file

@ -0,0 +1,48 @@
""" Some useful handlers to reduce lot of code """
import _ba, ba
def send(msg, clientid):
"""Shortcut To Send Private Msg To Client"""
_ba.chatmessage(str(msg), clients=[clientid])
_ba.screenmessage(str(msg), transient=True, clients=[clientid])
def clientid_to_myself(clientid):
"""Return Player Index Of Self Player"""
session = _ba.get_foreground_host_session()
for i in range(len(session.sessionplayers)):
if session.sessionplayers[i].inputdevice.client_id == clientid:
return int(session.sessionplayers[i].id)
def handlemsg(client, 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"""
activity = _ba.get_foreground_host_activity()
for i in activity.players:
i.actor.node.handlemessage(msg)

View file

@ -0,0 +1,332 @@
from .Handlers import handlemsg, handlemsg_all
from PlayersData import pdata
from tools.whitelist import add_to_white_list, add_commit_to_logs
import ba, _ba, time, setting
Commands = ['kick', 'remove', 'end', 'quit', 'mute', 'unmute', 'slowmo', 'nv', 'dv', 'pause', 'cameramode', 'createrole', 'addrole', 'removerole', 'addcommand', 'addcmd', 'removecommand', 'removecmd', 'changetag', 'add', 'spectators', 'lobbytime']
CommandAliases = ['rm', 'next', 'restart', 'mutechat', 'unmutechat', 'sm', 'slow', 'night', 'day', 'pausegame', 'camera_mode', 'rotate_camera', 'whitelist']
def ExcelCommand(command, arguments, clientid, accountid):
"""
Checks The Command And Run Function
Parameters:
command : str
arguments : str
clientid : int
accountid : int
Returns:
None
"""
if command == 'kick':
kick(arguments)
elif command in ['end', 'next']:
end(arguments)
elif command in ['quit', 'restart']:
quit(arguments)
elif command in ['mute', 'mutechat']:
mute()
elif command in ['unmute', 'unmutechat']:
un_mute()
elif command in ['remove', 'rm']:
remove(arguments)
elif command in ['sm', 'slow', 'slowmo']:
slow_motion()
elif command in ['nv', 'night']:
nv(arguments)
elif command in ['dv', 'day']:
dv(arguments)
elif command in ['pause', 'pausegame']:
pause()
elif command in ['cameraMode', 'camera_mode', 'rotate_camera']:
rotate_camera()
elif command == 'createrole':
create_role_call(arguments)
elif command == 'addrole':
add_role_to_player(arguments)
elif command == 'removerole':
remove_role_from_player(arguments)
elif command in ['addcommand', 'addcmd']:
add_command_to_role(arguments)
elif command in ['removecommand', 'removecmd']:
remove_command_to_role(arguments)
elif command == 'changetag':
change_role_tag_call(arguments)
elif command in ['add', 'whitelist']:
whitelst_it(accountid, arguments)
elif command == 'spectators':
spectators(arguments)
elif command == 'lobbytime':
change_lobby_check_time(arguments)
def kick(arguments):
return
def end(arguments):
if arguments == [] or arguments == ['']:
activity = _ba.get_foreground_host_activity()
activity.end_game()
def quit(arguments):
if arguments == [] or arguments == ['']:
ba.quit()
def mute():
return
def un_mute():
return
def remove(arguments):
if arguments == [] or arguments == ['']:
return
elif arguments[0] == 'all':
session = _ba.get_foreground_host_session()
for i in session.sessionplayers:
i.remove_from_game()
else:
try:
session = _ba.get_foreground_host_session()
session.sessionplayers[int(arguments[0])].remove_from_game()
except:
return
def slow_motion():
activity = _ba.get_foreground_host_activity()
if activity.globalsnode.slow_motion != True:
activity.globalsnode.slow_motion = True
else:
activity.globalsnode.slow_motion = False
def nv(arguments):
activity = _ba.get_foreground_host_activity()
if arguments == [] or arguments == ['']:
if activity.globalsnode.tint != (0.5, 0.7, 1.0):
activity.globalsnode.tint = (0.5, 0.7, 1.0)
else:
#will fix this soon
pass
elif arguments[0] == 'off':
if activity.globalsnode.tint != (0.5, 0.7, 1.0):
return
else:
pass
def dv(arguments):
activity = _ba.get_foreground_host_activity()
if arguments == [] or arguments == ['']:
if activity.globalsnode.tint != (1,1,1):
activity.globalsnode.tint = (1,1,1)
else:
#will fix this soon
pass
elif arguments[0] == 'off':
if activity.globalsnode.tint != (1,1,1):
return
else:
pass
def pause():
activity = _ba.get_foreground_host_activity()
if activity.globalsnode.paused != True:
activity.globalsnode.paused = True
else:
activity.globalsnode.paused = False
def rotate_camera():
activity = _ba.get_foreground_host_activity()
if activity.globalsnode.camera_mode != 'rotate':
activity.globalsnode.camera_mode = 'rotate'
else:
activity.globalsnode.camera_mode == 'normal'
def create_role(arguments):
try:
pdata.create_role(arguments[0])
except:
return
def add_role_to_player(arguments):
try:
session = _ba.get_foreground_host_session()
id = session.sessionplayers[int(arguments[1])].get_account_id()
pdata.add_player_role(arguments[0], id)
except:
return
def remove_role_from_player(arguments):
try:
session = _ba.get_foreground_host_session()
id = session.sessionplayers[int(arguments[1])].get_account_id()
pdata.remove_player_role(arguments[0], id)
except:
return
def change_role_tag(arguments):
try:
pdata.change_role_tag(arguments[0], arguments[1])
except:
return
all_commands = ["changetag","createrole", "addrole", "removerole", "addcommand", "addcmd","removecommand","removecmd","kick","remove","rm","end","next","quit","restart","mute","mutechat","unmute","unmutechat","sm","slow","slowmo","nv","night","dv","day","pause","pausegame","cameraMode","camera_mode","rotate_camera","kill","die","heal","heath","curse","cur","sleep","sp","superpunch","gloves","punch","shield","protect","freeze","ice","unfreeze","thaw","gm","godmode","fly","inv","invisible","hl","headless","creepy","creep","celebrate","celeb","spaz"]
def add_command_to_role(arguments):
try:
if arguments[1] in all_commands:
pdata.add_command_role(arguments[0], arguments[1])
except:
return
def remove_command_to_role(arguments):
try:
if arguments[1] in all_commands:
pdata.remove_command_role(arguments[0], arguments[1])
except:
return
def whitelst_it(accountid : str, arguments):
settings = setting.get_settings_data()
if arguments[0] == 'on':
settings["white_list"]["whitelist_on"] = True
setting.commit(settings)
cmsg("whitelist on")
return
elif arguments[0] == 'off':
settings["white_list"]["whitelist_on"] = False
setting.commit(settings)
cmsg("whitelist off")
return
else:
rost = _ba.get_game_roster()
for i in rost:
if i['client_id'] == int(arguments[0]):
add_to_white_list(i['account_id'], i['display_string'])
cmsg(str(i['display_string'])+" whitelisted")
add_commit_to_logs(accountid+" added "+i['account_id'])
def spectators(arguments):
if arguments[0] in ['on', 'off']:
settings = setting.get_settings_data()
if arguments[0] == 'on':
settings["white_list"]["spectators"] = True
setting.commit(settings)
cmsg("spectators on")
elif arguments[0] == 'off':
settings["white_list"]["spectators"] = False
setting.commit(settings)
cmsg("spectators off")
def change_lobby_check_time(arguments):
try:
argument = int(arguments[0])
except:
cmsg("must type numbe to change lobby check time")
settings = setting.get_settings_data()
settings["white_list"]["lobbychecktime"] = argument
setting.commit(settings)
cmsg(f"lobby check time is {arg} now")

View file

@ -0,0 +1,81 @@
from .Handlers import send
import ba, _ba
Commands = ['me', 'list', 'uniqeid']
CommandAliases = ['stats', 'score', 'rank', 'myself', 'l', 'id', 'pb-id', 'pb', 'accountid']
def ExcelCommand(command, arguments, clientid, accountid):
"""
Checks The Command And Run Function
Parameters:
command : str
arguments : str
clientid : int
accountid : int
Returns:
None
"""
if command in ['me', 'stats', 'score', 'rank', 'myself']:
stats()
elif command in ['list', 'l']:
list(clientid)
elif command in ['uniqeid', 'id', 'pb-id', 'pb' , 'accountid']:
accountid_request(arguments, clientid, accountid)
def stats():
""" Stats """
return
def list(clientid):
"""Returns The List Of Players Clientid and index"""
p = u'{0:^16}{1:^15}{2:^10}'
seprator = '\n______________________________\n'
list = p.format('Name', 'Client ID' , 'Player ID')+seprator
session = _ba.get_foreground_host_session()
for i in session.sessionplayers:
list += p.format(i.getname(icon = False),
i.inputdevice.client_id, i.id)
send(list, clientid)
def accountid_request(arguments, clientid, accountid):
"""Returns The Account Id Of Players"""
if arguments == [] or arguments == ['']:
send(f"Your account id is {accountid} ", clientid)
else:
try:
session = _ba.get_foreground_host_session()
player = session.sessionplayers[int(arguments[0])]
name = player.getname(full=True, icon=True)
accountid = player.get_account_id()
send(f" {name}'s account id is '{accountid}' ", clientid)
except:
return

View file

@ -1,7 +0,0 @@
# Released under the MIT License. See LICENSE for details.
#
"""Common bits of functionality shared between all efro projects.
Things in here should be hardened, highly type-safe, and well-covered by unit
tests since they are widely used in live client and server code.
"""

View file

@ -1,70 +0,0 @@
# Released under the MIT License. See LICENSE for details.
import ba, _ba
import setting
from playersData import pdata
from . import fun
from . import management, cheats, normal_commands as normal_cmds
def client_to_account(client_id):
rost = _ba.get_game_roster()
for i in rost:
if i['client_id'] == client_id:
return i['account_id']
return None
def check_permission(account_id, command):
roles = pdata.get_roles()
for role in roles:
if account_id in roles[role]["ids"] and command in roles[role]["commands"]:
return True
return False
def cmd_type(cmnd):
if cmnd in normal_cmds.cmnds or cmnd in normal_cmds.cmnd_aliases:
return "normal_cmd"
if cmnd in management.cmnds or cmnd in management.cmnd_aliases:
return "management"
if cmnd in fun.cmnds or cmnd in fun.cmnd_aliases:
return "fun"
if cmnd in cheats.cmnds or cmnd in cheats.cmnd_aliases:
return "cheats"
def cmd(msg, client_id):
cmnd = msg.split(" ")[0].lower().split("/")[1]
arg = msg.split(" ")[1:]
acid = "pb-IF48VgWkBFQ"
#client_to_account(client_id)
if cmd_type(cmnd) == "fun":
if check_permission(acid, cmnd):
fun.exec_cmd(cmnd, arg, client_id, acid)
elif cmd_type(cmnd) == "management":
if check_permission(acid, cmnd):
management.exec_cmd(cmnd, arg, client_id, acid)
elif cmd_type(cmnd) == "cheats":
if check_permission(acid, cmnd):
cheats.exec_cmd(cmnd, arg, client_id, acid)
elif cmd_type(cmnd) == "normal_cmd":
normal_cmds.exec_cmd(cmnd, arg, client_id, acid)
else:
_ba.chatmessage("no access")
if setting.brdcast_chatcmd:
return msg
return None

View file

@ -1,236 +0,0 @@
# Released under the MIT License. See LICENSE for details.
from _ba import chatmessage as cmsg, screenmessage as smsg
from .handlers import activity_players, on_command_error, handlemsg, handlemsg_all
import ba, _ba, time
cmnds = ['kill', 'heal', 'curse', 'sleep', 'superpunch', 'gloves', 'shield', 'freeze', 'unfreeze', 'godmode']
cmnd_aliases = ['die', 'heath', 'cur', 'sp', 'punch', 'protect', 'ice', 'thaw', 'gm']
def exec_cmd(cmnd, arg, client_id, pbid):
if cmnd in ['kill', 'die']:
kill_call(arg)
elif cmnd in ['heal', 'heath']:
heal_call(arg)
elif cmnd in ['curse', 'cur']:
curse_call(arg)
elif cmnd in ['sleep']:
sleep_call(arg)
elif cmnd in ['sp', 'superpunch']:
super_punch_call(arg)
elif cmnd in ['gloves', 'punch']:
gloves_call(arg)
elif cmnd in ['shield', 'protect']:
shield_call(arg)
elif cmnd in ['freeze', 'ice']:
freeze_call(arg)
elif cmnd in ['unfreeze', 'thaw']:
un_freeze_call(arg)
elif cmnd in ['gm', 'godmode']:
god_mode_call(arg)
def kill_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.DieMessage())
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.DieMessage())
except:
return
def heal_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='health'))
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='health'))
except:
return
def curse_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='curse'))
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='curse'))
except:
return
def sleep_call(arg):
if on_command_error(arg):
return
# ahh ! harsh here maybe fix in future
elif arg[0] == 'all':
for i in activity_players():
i.actor.node.handlemessage('knockout', 8000)
else:
try:
req_player = int(arg[0])
activity_players()[req_player].actor.node.handlemessage('knockout', 8000)
except:
return
def super_punch_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for i in activity_players():
if i.actor._punch_power_scale != 15:
i.actor._punch_power_scale = 15
i.actor._punch_cooldown = 0
else:
i.actor._punch_power_scale = 1.2
i.actor._punch_cooldown = 400
else:
try:
req_player = int(arg[0])
if activity_players()[req_player].actor._punch_power_scale != 15:
activity_players()[req_player].actor._punch_power_scale = 15
activity_players()[req_player].actor._punch_cooldown = 0
else:
activity_players()[req_player].actor._punch_power_scale = 1.2
activity_players()[req_player].actor._punch_cooldown = 400
except:
return
def gloves_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='punch'))
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='punch'))
except:
return
def shield_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.PowerupMessage(poweruptype='shield'))
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.PowerupMessage(poweruptype='shield'))
except:
return
def freeze_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.FreezeMessage())
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.FreezeMessage())
except:
return
def un_freeze_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.ThawMessage())
else:
try:
req_player = int(arg[0])
handlemsg(req_player, ba.ThawMessage())
except:
return
def god_mode_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for i in activity_players():
if i.actor._punch_power_scale != 7:
i.actor._punch_power_scale = 7
i.actor.node.hockey = True
i.actor.node.invincible = True
else:
i.actor._punch_power_scale = 1.2
i.actor.node.hockey = False
i.actor.node.invincible = False
else:
req_player = int(arg[0])
player = activity_players()[req_player].actor
if player._punch_power_scale != 7:
player._punch_power_scale = 7
player.node.hockey = True
player.node.invincible = True
else:
player._punch_power_scale = 1.2
player.node.hockey = False
player.node.invincible = False

View file

@ -1,177 +0,0 @@
# Released under the MIT License. See LICENSE for details.
from _ba import chatmessage as cmsg, screenmessage as smsg
from .handlers import activity_players, on_command_error, handlemsg, handlemsg_all
import ba, _ba
cmnds = ['fly', 'invisible', 'headless', 'creepy', 'celebrate', 'spaz']
cmnd_aliases = ['inv', 'hl', 'creep', 'celeb']
def exec_cmd(cmnd, arg, clid, pbid):
if cmnd in ['fly']:
fly_call(arg)
elif cmnd in ['inv', 'invisible']:
invi_call(arg)
elif cmnd in ['hl', 'headless']:
headless_call(arg)
elif cmnd in ['creepy', 'creep']:
creep_call(arg)
elif cmnd in ['celebrate', 'celeb']:
celeb_call(arg)
elif cmnd in ['spaz']:
spaz_call(arg)
def fly_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for players in activity_players():
if players.actor.node.fly != True:
players.actor.node.fly = True
else:
players.actor.node.fly = False
else:
try:
player = int(arg[0])
if activity_players()[player].actor.node.fly != True:
activity_players()[player].actor.node.fly = True
else:
activity_players()[player].actor.node.fly = False
except:
return
def invi_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for i in activity_players():
body = i.actor.node
if body.torso_model != None:
body.head_model = None
body.torso_model = None
body.upper_arm_model = None
body.forearm_model = None
body.pelvis_model = None
body.hand_model = None
body.toes_model = None
body.upper_leg_model = None
body.lower_leg_model = None
body.style = 'cyborg'
else:
player = int(arg[0])
body = activity_players()[player].actor.node
if body.torso_model != None:
body.head_model = None
body.torso_model = None
body.upper_arm_model = None
body.forearm_model = None
body.pelvis_model = None
body.hand_model = None
body.toes_model = None
body.upper_leg_model = None
body.lower_leg_model = None
body.style = 'cyborg'
def headless_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for players in activity_players():
node = players.actor.node
if node.head_model != None:
node.head_model = None
node.style='cyborg'
else:
try:
player = int(arg[0])
node = activity_players()[player].actor.node
if node.head_model != None:
node.head_model = None
node.style='cyborg'
except:
return
def creep_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for players in activity_players():
node = players.actor.node
if node.head_model != None:
node.head_model = None
node.handlemessage(ba.PowerupMessage(poweruptype='punch'))
node.handlemessage(ba.PowerupMessage(poweruptype='shield'))
else:
try:
player = int(arg[0])
node = activity_players()[player].actor.node
if node.head_model != None:
node.head_model = None
node.handlemessage(ba.PowerupMessage(poweruptype='punch'))
node.handlemessage(ba.PowerupMessage(poweruptype='shield'))
except:
return
def celeb_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
handlemsg_all(ba.CelebrateMessage())
else:
try:
player = int(arg[0])
handlemsg(player, ba.CelebrateMessage())
except:
return
def spaz_call(arg):
if on_command_error(arg):
return
pass

View file

@ -1,26 +0,0 @@
""" helper functions to reduce lot code """
import _ba, ba
def activity_players():
return _ba.get_foreground_host_activity().players
def sess_players():
return _ba.get_foreground_host_session().sessionplayers
def on_command_error(arg):
if arg == [] or arg == ['']:
return True
return False
def handlemsg(client, msg):
activity_players()[client].actor.node.handlemessage(msg)
def handlemsg_all(msg):
for i in activity_players():
i.actor.node.handlemessage(msg)

View file

@ -1,260 +0,0 @@
# Released under the MIT License. See LICENSE for details.
from _ba import chatmessage as cmsg, screenmessage as smsg
from .handlers import activity_players, sess_players, on_command_error, handlemsg, handlemsg_all
from playersData import pdata
import ba, _ba, time
cmnds = ['kick', 'remove', 'end', 'quit', 'mute', 'unmute', 'slowmo', 'nv', 'dv', 'pause', 'cameramode', 'createrole', 'addrole', 'removerole', 'addcommand', 'addcmd', 'removecommand', 'removecmd', 'changetag']
cmnd_aliases = ['rm', 'next', 'restart', 'mutechat', 'unmutechat', 'sm', 'slow', 'night', 'day', 'pausegame', 'camera_mode', 'rotate_camera']
def exec_cmd(cmnd, arg, client_id, pbid):
if cmnd in ['kick']:
kick(arg[0])
elif cmnd in ['end', 'next']:
end_call(arg)
elif cmnd in ['quit', 'restart']:
quit_call(arg)
elif cmnd in ['mute', 'mutechat']:
mute_call()
elif cmnd in ['unmute', 'unmutechat']:
un_mute_call()
elif cmnd in ['remove', 'rm']:
remove_call(arg)
elif cmnd in ['sm', 'slow', 'slowmo']:
slow_mo_call()
elif cmnd in ['nv', 'night']:
nv_call(arg)
elif cmnd in ['dv', 'day']:
dv_call(arg)
elif cmnd in ['pause', 'pausegame']:
pause_call()
elif cmnd in ['cameraMode', 'camera_mode', 'rotate_camera']:
rotate_camera_call()
elif cmnd in ['createrole']:
create_role_call(arg)
elif cmnd in ['addrole']:
add_role_to_player(arg)
elif cmnd in ['removerole']:
remove_role_from_player(arg)
elif cmnd in ['addcommand', 'addcmd']:
add_command_to_role(arg)
elif cmnd in ['removecommand', 'removecmd']:
remove_command_to_role(arg)
elif cmnd in ['changetag']:
change_role_tag_call(arg)
# =============
def kick(client_id):
_ba.disconnectclient(client_id)
def remove_call(arg):
if on_command_error(arg):
return
elif arg[0] == 'all':
for i in sess_players():
i.remove_from_game()
else:
try:
req_player = int(arg[0])
sess_players()[req_player].remove_from_game()
except:
return
def add():
pass
def end_call(arg):
if arg == [] or arg == ['']:
activity = _ba.get_foreground_host_activity()
activity.end_game()
"""
else:
try:
tmr = int(arg[0])
time.sleep(tmr)
activity = _ba.get_foreground_host_activity()
activity.end_game()
except:
return
"""
def quit_call(arg):
if arg == [] or arg == ['']:
ba.quit()
"""
else:
try:
tmr = int(arg[0])
time.sleep(tmr)
ba.quit()
except:
return
"""
def mute_call():
pass
def un_mute_call():
pass
def slow_mo_call():
activity = _ba.get_foreground_host_activity()
if activity.globalsnode.slow_motion != True:
activity.globalsnode.slow_motion = True
else:
activity.globalsnode.slow_motion = False
def nv_call(arg):
activity = _ba.get_foreground_host_activity()
if arg == [] or arg == ['']:
if activity.globalsnode.tint != (0.5, 0.7, 1.0):
activity.globalsnode.tint = (0.5, 0.7, 1.0)
else:
#will fix this soon
pass
elif arg[0] == 'off':
if activity.globalsnode.tint != (0.5, 0.7, 1.0):
return
else:
pass
def dv_call(arg):
activity = _ba.get_foreground_host_activity()
if arg == [] or arg == ['']:
if activity.globalsnode.tint != (1,1,1):
activity.globalsnode.tint = (1,1,1)
else:
#will fix this soon
pass
elif arg[0] == 'off':
if activity.globalsnode.tint != (1,1,1):
return
else:
pass
def pause_call():
activity = _ba.get_foreground_host_activity()
if activity.globalsnode.paused != True:
activity.globalsnode.paused = True
else:
activity.globalsnode.paused = False
def rotate_camera_call():
activity = _ba.get_foreground_host_activity()
if activity.globalsnode.camera_mode != 'rotate':
activity.globalsnode.camera_mode = 'rotate'
else:
activity.globalsnode.camera_mode == 'normal'
def create_role_call(arg):
pdata.create_role(arg[0])
def add_role_to_player(arg):
id = sess_players()[int(arg[1])].get_account_id()
try:
pdata.add_player_role(arg[0], id)
except:
return
def remove_role_from_player(arg):
id = sess_players()[int(arg[1])].get_account_id()
try:
pdata.remove_player_role(arg[0], id)
except:
return
def change_role_tag_call(arg):
pdata.change_role_tag(arg[0], arg[1])
all_commands = ["changetag","createrole", "addrole", "removerole", "addcommand", "addcmd","removecommand","removecmd","kick","remove","rm","end","next","quit","restart","mute","mutechat","unmute","unmutechat","sm","slow","slowmo","nv","night","dv","day","pause","pausegame","cameraMode","camera_mode","rotate_camera","kill","die","heal","heath","curse","cur","sleep","sp","superpunch","gloves","punch","shield","protect","freeze","ice","unfreeze","thaw","gm","godmode","fly","inv","invisible","hl","headless","creepy","creep","celebrate","celeb","spaz"]
def add_command_to_role(arg):
try:
if arg[1] in all_commands:
pdata.add_command_role(arg[0], arg[1])
except:
return
def remove_command_to_role(arg):
try:
if arg[1] in all_commands:
pdata.remove_command_role(arg[0], arg[1])
except:
return

View file

@ -1,54 +0,0 @@
# Released under the MIT License. See LICENSE for details.
from _ba import chatmessage as cmsg, screenmessage as smsg
from .handlers import sess_players
import ba, _ba
cmnds = ['me', 'list', 'uniqeid']
cmnd_aliases = ['stats', 'score', 'rank', 'myself', 'l', 'id', 'pb-id', 'pb', 'accountid']
def exec_cmd(cmnd, arg, clid, pbid):
if cmnd in ['me', 'stats', 'score', 'rank', 'myself']:
stats_call()
elif cmnd in ['list', 'l']:
list_call(clid)
elif cmnd in ['uniqeid', 'id', 'pb-id', 'pb' , 'accountid']:
show_id_call(arg, pbid, clid)
def stats_call():
pass
def list_call(clid):
seprator = '______________________________'
lst = u'{0:^16}{1:^15}{2:^10}'.format('name', 'client_id' , 'player_id') + f'\n{seprator}\n'
for i in sess_players():
lst += u'{0:^16}{1:^15}{2:^10}\n'.format(i.getname(icon = False), str(i.inputdevice.client_id), str(i.id))
smsg(lst, color = (0,2.55,2.55), transient = True , clients = [clid])
def show_id_call(arg, acid, clid):
if arg == [] or arg == ['']:
cmsg(f'Your account id is {acid} ')
else:
try:
rq_client = sess_players()[int(arg[0])]
name = rq_client.getname(full=True , icon=True)
acid = rq_client.get_account_id()
smsg(f" {name}'s account id is '{acid}' ", color = (0,2.55,2.55), transient = True , clients = [clid])
except:
return

View file

@ -0,0 +1,6 @@
# Released under the MIT License. See LICENSE for details.
import ba, _ba
def isAbuse(msg):
pass

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
# Released under the MIT License. See LICENSE for details.
def isAbuse():
def isspam():
return

View file

@ -1,19 +1,15 @@
# Released under the MIT License. See LICENSE for details.
from playersData import pdata
from chatHandle.chatCMDS import chatcmd
#from chatFilter import chatfilter
from PlayersData import pdata
from ChatHandle.ChatCommands import Main
import ba, _ba
def public_id(client_id):
rost=_ba.get_game_roster()
for client in rost:
if client['client_id']==client_id:
return client['account_id']
return None
def filter_chat_message(msg, client_id):
if msg.startswith("/"):
return chatcmd.cmd(msg,client_id)
return Main.Command(msg, client_id)
return msg
"""
@ -22,5 +18,3 @@ def filter_chat_message(msg,client_id):
return None
return msg
"""

View file

@ -0,0 +1,14 @@
###### remaining
mute / unmute
spaz
me
stats
nv / dv
replies for coamd like ' created role Pranav69 successfully'
some dirt here there
chat spam
chat filter

View file

@ -1,8 +1,7 @@
from ChatHandle import HandleChat
def filter_chat_message(msg,client_id):
from chatHandle import handlechat
return handlechat.filter_chat_message(msg,client_id)
return HandleChat.filter_chat_message(msg,client_id)
def on_app_launch():

View file

@ -8,6 +8,10 @@
],
"commands": [
"createrole",
"add",
"spectators",
"lobbytime",
"whitelist",
"addrole",
"removerole",
"addcommand",
@ -79,7 +83,8 @@
"changetag"
],
"ids": [
"pb-IF48VgWkBFQ"
"pb-IF48VWkBFQ",
"None"
]
},
"test69": {

View file

@ -1,27 +1,42 @@
"""Define a simple example plugin."""
"""
Private Server whitelist by Mr.Smoothy
* don't dare to remove credits or I will bite you
GitHub : https://github.com/imayushsaini/Bombsquad-Ballistica-Modded-Server
"""
# ba_meta require api 6
# Private Server whitelist by Mr.Smoothy
from __future__ import annotations
from typing import TYPE_CHECKING
from ba._enums import TimeType
import ba,json,_ba,time
import ba, json, _ba, time, datetime
if TYPE_CHECKING:
pass
import datetime
from ba._enums import TimeType
whitelist_on=True # change it by chat commands for by editing here
spectators=False # ,, ,, ,, ,, False means spectating not allowed
whitelist={} # dont change
lobbychecktime=3 # time in seconds, to check lobby players ... increase time ,for more time unwanted players can watch match
# decrease time , kick them fast , but can also give some lagg to the server , adjust yourself acrd. to cpu power
whitelist_on = True
""" Change It By Chat Commands For By Editing Here """
admins=['pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE'] # dirty admin system , for now , until we get good working chat commands
spectators = False
""" False Means Spectating Not Allowed """
whitelist = {}
""" Dont change """
lobbychecktime = 3
"""
Time in seconds, to check lobby players ... increase time ,for more time unwanted players can watch match
Decrease time , kick them fast , but can also give some lagg to the server , adjust yourself acrd. to cpu power """
admins = ['pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE']
"""Dirty admin system , for now , until we get good working chat commands """
def inWhiteList(id):

View file

@ -4,6 +4,15 @@
"spectators": false,
"lobbychecktime": 3
},
"ChatCommands": {
"BrodcastCommand": true
},
"textonmap": {
"top watermark": "Welcome to server \n ip 192.168.0.1",
"bottom left watermark": "join discord for fun",
@ -13,6 +22,9 @@
"message 3"
]
},
"enabletags": true,
"enablerank": true,
"enableeffects": false

View file

@ -1,224 +0,0 @@
damage_data = {}
#Don't touch the above line
"""
mystats module for BombSquad version 1.5.29
Provides functionality for dumping player stats to disk between rounds.
"""
ranks=[]
import threading,json,os,urllib.request,ba,_ba,setting
from ba._activity import Activity
from ba._music import setmusic, MusicType
from ba._enums import InputType, UIScale
# False-positive from pylint due to our class-generics-filter.
from ba._player import EmptyPlayer # pylint: disable=W0611
from ba._team import EmptyTeam # pylint: disable=W0611
from typing import Any, Dict, Optional
from ba._lobby import JoinInfo
from ba import _activitytypes as ba_actypes
from ba._activitytypes import *
our_settings = setting.get_settings_data()
# where our stats file and pretty html output will go
base_path = os.path.join(_ba.env()['python_directory_user'],"stats" + os.sep)
statsfile = base_path + 'stats.json'
htmlfile = base_path + 'stats_page.html'
table_style = "{width:100%;border: 3px solid black;border-spacing: 5px;border-collapse:collapse;text-align:center;background-color:#fff}"
heading_style = "{border: 3px solid black;text-align:center;}"
html_start = f'''<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Server</title>
<style>table{table_style} th{heading_style}</style>
</head>
<body>
<h3 style="text-align:center">Top 200 Players </h3>
<table border=1>
<tr>
<th><b>Rank</b></th>
<th style="text-align:center"><b>Name</b></th>
<th><b>Score</b></th>
<th><b>Kills</b></th>
<th><b>Deaths</b></th>
<th><b>Games Played</b></th>
</tr>
'''
# <th><b>Total Damage</b></th> #removed this line as it isn't crt data
def refreshStats():
# lastly, write a pretty html version.
# our stats url could point at something like this...
f=open(statsfile)
stats = json.loads(f.read())
f=open(htmlfile, 'w')
f.write(html_start)
entries = [(a['scores'], a['kills'], a['deaths'], a['games'], a['name_html'], a['aid']) for a in stats.values()]
# this gives us a list of kills/names sorted high-to-low
entries.sort(reverse=True)
rank = 0
toppers = {}
pStats = stats
toppersIDs=[]
_ranks=[]
for entry in entries:
if True:
rank += 1
scores = str(entry[0])
kills = str(entry[1])
deaths = str(entry[2])
games = str(entry[3])
name = str(entry[4])
aid = str(entry[5])
if rank < 6: toppersIDs.append(aid)
#The below kd and avg_score will not be added to website's html document, it will be only added in stats.json
try:
kd = str(float(kills) / float(deaths))
kd_int = kd.split('.')[0]
kd_dec = kd.split('.')[1]
p_kd = kd_int + '.' + kd_dec[:3]
except Exception:
p_kd = "0"
try:
avg_score = str(float(scores) / float(games))
avg_score_int = avg_score.split('.')[0]
avg_score_dec = avg_score.split('.')[1]
p_avg_score = avg_score_int + '.' + avg_score_dec[:3]
except Exception:
p_avg_score = "0"
if damage_data and aid in damage_data:
dmg = damage_data[aid]
dmg = str(str(dmg).split('.')[0] + '.' + str(dmg).split('.')[1][:3])
else: dmg = 0
_ranks.append(aid)
pStats[str(aid)]["rank"] = int(rank)
pStats[str(aid)]["scores"] = int(scores)
pStats[str(aid)]["total_damage"] += float(dmg) #not working properly
pStats[str(aid)]["games"] = int(games)
pStats[str(aid)]["kills"] = int(kills)
pStats[str(aid)]["deaths"] = int(deaths)
pStats[str(aid)]["kd"] = float(p_kd)
pStats[str(aid)]["avg_score"] = float(p_avg_score)
if rank < 201:
#<td>{str(dmg)}</td> #removed this line as it isn't crt data
f.write(f'''
<tr>
<td>{str(rank)}</td>
<td style="text-align:center">{str(name)}</td>
<td>{str(scores)}</td>
<td>{str(kills)}</td>
<td>{str(deaths)}</td>
<td>{str(games)}</td>
</tr>''')
f.write('''
</table>
</body>
</html>''')
f.close()
global ranks
ranks=_ranks
f2 = open(statsfile, "w")
f2.write(json.dumps(pStats, indent=4))
f2.close()
from playersData import pdata
pdata.update_toppers(toppersIDs)
def update(score_set):
"""
Given a Session's ScoreSet, tallies per-account kills
and passes them to a background thread to process and
store.
"""
# look at score-set entries to tally per-account kills for this round
account_kills = {}
account_deaths = {}
account_scores = {}
for p_entry in score_set.get_records().values():
account_id = p_entry.player.get_account_id()
if account_id is not None:
account_kills.setdefault(account_id, 0) # make sure exists
account_kills[account_id] += p_entry.accum_kill_count
account_deaths.setdefault(account_id, 0) # make sure exists
account_deaths[account_id] += p_entry.accum_killed_count
account_scores.setdefault(account_id, 0) # make sure exists
account_scores[account_id] += p_entry.accumscore
# Ok; now we've got a dict of account-ids and kills.
# Now lets kick off a background thread to load existing scores
# from disk, do display-string lookups for accounts that need them,
# and write everything back to disk (along with a pretty html version)
# We use a background thread so our server doesn't hitch while doing this.
print(account_kills)
print(account_scores)
if account_scores:
UpdateThread(account_kills, account_deaths, account_scores).start()
class UpdateThread(threading.Thread):
def __init__(self, account_kills, account_deaths, account_scores):
threading.Thread.__init__(self)
self._account_kills = account_kills
self.account_deaths = account_deaths
self.account_scores = account_scores
print("init thread")
def run(self):
# pull our existing stats from disk
print("run thead")
try:
if os.path.exists(statsfile):
with open(statsfile) as f:
stats = json.loads(f.read())
except:
stats={}
# now add this batch of kills to our persistant stats
for account_id, kill_count in self._account_kills.items():
# add a new entry for any accounts that dont have one
if account_id not in stats:
# also lets ask the master-server for their account-display-str.
# (we only do this when first creating the entry to save time,
# though it may be smart to refresh it periodically since
# it may change)
'''url = 'http://bombsquadgame.com/accountquery?id=' + account_id
response = json.loads(
urllib.request.urlopen(urllib.Request(url)).read())
print('response variable from mystats.py line 183:')
print(response)
name_html = response['name_html']'''
stats[account_id] = {'rank': 0,
'name_html': str(account_id),
'scores': 0,
'total_damage': 0,
'kills': 0,
'deaths': 0,
'games': 0,
'kd': 0,
'avg_score': 0,
'aid': str(account_id)}
# now increment their kills whether they were already there or not
stats[account_id]['kills'] += kill_count
stats[account_id]['deaths'] += self.account_deaths[account_id]
stats[account_id]['scores'] += self.account_scores[account_id]
# also incrementing the games played and adding the id
stats[account_id]['games'] += 1
stats[account_id]['aid'] = str(account_id)
# dump our stats back to disk
tempppp = None
from datetime import datetime
with open(statsfile, 'w') as f:
f.write(json.dumps(stats))
# aaand that's it! There IS no step 27!
now = datetime.now()
update_time = now.strftime("%S:%M:%H - %d %b %y")
print(f"Added {str(len(self._account_kills))} account's stats entries. || {str(update_time)}")
refreshStats()
def getRank(acc_id):
global ranks
if ranks==[]:
refreshStats()
if acc_id in ranks:
return ranks.index(acc_id)+1

View file

@ -1 +0,0 @@
# Released under the MIT License. See LICENSE for details.

View file

@ -1,14 +0,0 @@
{
"pb-IF4VAk4a": {
"rank": 1,
"name_html": "pb-IF4VAk4a",
"scores": 0,
"total_damage": 0.0,
"kills": 0,
"deaths": 0,
"games": 18,
"kd": 0.0,
"avg_score": 0.0,
"aid": "pb-IF4VAk4a"
}
}

View file

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Server</title>
<style>table{width:100%;border: 3px solid black;border-spacing: 5px;border-collapse:collapse;text-align:center;background-color:#fff} th{border: 3px solid black;text-align:center;}</style>
</head>
<body>
<h3 style="text-align:center">Top 200 Players </h3>
<table border=1>
<tr>
<th><b>Rank</b></th>
<th style="text-align:center"><b>Name</b></th>
<th><b>Score</b></th>
<th><b>Kills</b></th>
<th><b>Deaths</b></th>
<th><b>Games Played</b></th>
</tr>
<tr>
<td>1</td>
<td style="text-align:center">pb-IF4VAk4a</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>18</td>
</tr>
</table>
</body>
</html>