From d8adea34e62eaf582b281d8ec3a3a65cff0203c0 Mon Sep 17 00:00:00 2001 From: Ayush Saini Date: Fri, 30 Apr 2021 19:13:53 +0530 Subject: [PATCH] more fix , integrated whitelist with chat cmds --- dist/ba_data/python/ba/_hooks.py | 4 +- dist/ba_data/python/ba/_session.py | 4 +- .../mods/chatHandle/ChatCommands/Handlers.py | 7 +- .../ChatCommands/commands/Management.py | 27 +++--- dist/ba_root/mods/custom_hooks.py | 6 +- dist/ba_root/mods/playersData/roles.json | 87 +------------------ ...{privateserver.py => privateserver.backup} | 1 + dist/ba_root/mods/setting.json | 2 +- dist/ba_root/mods/spazmod/tag.py | 6 +- dist/ba_root/mods/stats/mystats.py | 7 +- dist/ba_root/mods/tools/textonmap.py | 2 +- dist/ba_root/mods/tools/whitelist.py | 59 ++++++++----- 12 files changed, 78 insertions(+), 134 deletions(-) rename dist/ba_root/mods/{privateserver.py => privateserver.backup} (99%) diff --git a/dist/ba_data/python/ba/_hooks.py b/dist/ba_data/python/ba/_hooks.py index 3779a30..cb31ed8 100644 --- a/dist/ba_data/python/ba/_hooks.py +++ b/dist/ba_data/python/ba/_hooks.py @@ -307,7 +307,7 @@ def party_invite_revoke(invite_id: str) -> None: _ba.containerwidget(edit=win.get_root_widget(), transition='out_right') -import privateserver as pvt + import custom_hooks as chooks def filter_chat_message(msg: str, client_id: int) -> Optional[str]: """Intercept/filter chat messages. @@ -317,7 +317,7 @@ def filter_chat_message(msg: str, client_id: int) -> Optional[str]: Should filter and return the string to be displayed, or return None to ignore the message. """ - pvt.handlechat(msg,client_id) + return chooks.filter_chat_message(msg,client_id) diff --git a/dist/ba_data/python/ba/_session.py b/dist/ba_data/python/ba/_session.py index b892832..f40c75f 100644 --- a/dist/ba_data/python/ba/_session.py +++ b/dist/ba_data/python/ba/_session.py @@ -206,8 +206,8 @@ class Session: This should return True or False to accept/reject. """ - import privateserver as pvt - pvt.handlerequest(player) + from tools import whitelist + whitelist.handle_player_request(player) # Limit player counts *unless* we're in a stress test. if _ba.app.stress_test_reset_timer is None: diff --git a/dist/ba_root/mods/chatHandle/ChatCommands/Handlers.py b/dist/ba_root/mods/chatHandle/ChatCommands/Handlers.py index bb781ee..5837809 100644 --- a/dist/ba_root/mods/chatHandle/ChatCommands/Handlers.py +++ b/dist/ba_root/mods/chatHandle/ChatCommands/Handlers.py @@ -38,9 +38,12 @@ def check_permissions(accountid, command): Boolean """ roles = pdata.get_roles() - + for role in roles: - if accountid in roles[role]["ids"] and command in roles[role]["commands"]: + 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 diff --git a/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py b/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py index cfd1a1d..e4e67aa 100644 --- a/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py +++ b/dist/ba_root/mods/chatHandle/ChatCommands/commands/Management.py @@ -57,7 +57,7 @@ def ExcelCommand(command, arguments, clientid, accountid): rotate_camera() elif command == 'createrole': - create_role_call(arguments) + create_role(arguments) elif command == 'addrole': add_role_to_player(arguments) @@ -72,7 +72,7 @@ def ExcelCommand(command, arguments, clientid, accountid): remove_command_to_role(arguments) elif command == 'changetag': - change_role_tag_call(arguments) + change_role_tag(arguments) elif command in ['add', 'whitelist']: whitelst_it(accountid, arguments) @@ -280,15 +280,20 @@ 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") + if settings["white_list"]["whitelist_on"]: + _ba.chatmessage("Already on") + else: + settings["white_list"]["whitelist_on"] = True + setting.commit(settings) + _ba.chatmessage("whitelist on") + from tools import whitelist + whitelist.Whitelist() return elif arguments[0] == 'off': settings["white_list"]["whitelist_on"] = False setting.commit(settings) - cmsg("whitelist off") + _ba.chatmessage("whitelist off") return else: @@ -297,7 +302,7 @@ def whitelst_it(accountid : str, arguments): 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") + _ba.chatmessage(str(i['display_string'])+" whitelisted") add_commit_to_logs(accountid+" added "+i['account_id']) @@ -311,12 +316,12 @@ def spectators(arguments): if arguments[0] == 'on': settings["white_list"]["spectators"] = True setting.commit(settings) - cmsg("spectators on") + _ba.chatmessage("spectators on") elif arguments[0] == 'off': settings["white_list"]["spectators"] = False setting.commit(settings) - cmsg("spectators off") + _ba.chatmessage("spectators off") @@ -325,8 +330,8 @@ def change_lobby_check_time(arguments): try: argument = int(arguments[0]) except: - cmsg("must type numbe to change lobby check time") + _ba.chatmessage("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") + _ba.chatmessage(f"lobby check time is {arg} now") diff --git a/dist/ba_root/mods/custom_hooks.py b/dist/ba_root/mods/custom_hooks.py index fedcaa1..5803b5f 100644 --- a/dist/ba_root/mods/custom_hooks.py +++ b/dist/ba_root/mods/custom_hooks.py @@ -1,11 +1,13 @@ from chatHandle import handlechat def filter_chat_message(msg, client_id): - return HandleChat.filter_chat_message(msg, client_id) + return handlechat.filter_chat_message(msg, client_id) def on_app_launch(): - pass + from tools import whitelist + whitelist.Whitelist() + #something def score_screen_on_begin(_stats): diff --git a/dist/ba_root/mods/playersData/roles.json b/dist/ba_root/mods/playersData/roles.json index 75865f8..2c56c73 100644 --- a/dist/ba_root/mods/playersData/roles.json +++ b/dist/ba_root/mods/playersData/roles.json @@ -1,90 +1,11 @@ { "owner": { - "tag": "pranav", - "tagcolor": [ - 1, - 1, - 1 - ], - "commands": [ - "createrole", - "add", - "spectators", - "lobbytime", - "whitelist", - "addrole", - "removerole", - "addcommand", - "addcmd", - "removecommand", - "removecmd", - "remove", - "kick", - "rm", - "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", - "me", - "stats", - "score", - "list", - "l", - "uniqeid", - "id", - "pb-id", - "pb", - "accountid", - "end", - "changetag" - ], + "tag": "owner", + "tagcolor": [1,0.6,0.4], + "commands": ["ALL"], "ids": [ "pb-IF48VWkBFQ", - "None" + "pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE" ] }, "test69": { diff --git a/dist/ba_root/mods/privateserver.py b/dist/ba_root/mods/privateserver.backup similarity index 99% rename from dist/ba_root/mods/privateserver.py rename to dist/ba_root/mods/privateserver.backup index 8f62f33..a629ded 100644 --- a/dist/ba_root/mods/privateserver.py +++ b/dist/ba_root/mods/privateserver.backup @@ -159,6 +159,7 @@ class private(ba.Plugin): _ba.disconnect_client(clt['client_id']) except: pass + diff --git a/dist/ba_root/mods/setting.json b/dist/ba_root/mods/setting.json index 935d8b9..8462600 100644 --- a/dist/ba_root/mods/setting.json +++ b/dist/ba_root/mods/setting.json @@ -2,7 +2,7 @@ "white_list": { "whitelist_on": true, "spectators": false, - "lobbychecktime": 3 + "lobbychecktime": 1 }, diff --git a/dist/ba_root/mods/spazmod/tag.py b/dist/ba_root/mods/spazmod/tag.py index 00b6f18..1aff481 100644 --- a/dist/ba_root/mods/spazmod/tag.py +++ b/dist/ba_root/mods/spazmod/tag.py @@ -31,7 +31,7 @@ class Tag(object): mnode = ba.newnode('math', owner=self.node, attrs={ - 'input1': (0, 1.4, 0), + 'input1': (0, 1.5, 0), 'operation': 'add' }) self.node.connectattr('torso_position', mnode, 'input2') @@ -42,7 +42,7 @@ class Tag(object): 'in_world': True, 'shadow': 1.0, 'flatness': 1.0, - 'color': (1,1,1), + 'color': (1,0.6,0.7), 'scale': 0.01, 'h_align': 'center' }) @@ -61,7 +61,7 @@ class Rank(object): self.rank_text = ba.newnode('text', owner=self.node, attrs={ - 'text': str(rank), + 'text': "#"+str(rank), 'in_world': True, 'shadow': 1.0, 'flatness': 1.0, diff --git a/dist/ba_root/mods/stats/mystats.py b/dist/ba_root/mods/stats/mystats.py index 8e52ca5..94569ad 100644 --- a/dist/ba_root/mods/stats/mystats.py +++ b/dist/ba_root/mods/stats/mystats.py @@ -152,8 +152,7 @@ def update(score_set): # 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() @@ -163,10 +162,10 @@ class UpdateThread(threading.Thread): 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: diff --git a/dist/ba_root/mods/tools/textonmap.py b/dist/ba_root/mods/tools/textonmap.py index a60caae..1664bd2 100644 --- a/dist/ba_root/mods/tools/textonmap.py +++ b/dist/ba_root/mods/tools/textonmap.py @@ -43,7 +43,7 @@ class textonmap: 'h_align': 'left', 'v_attach':'bottom', 'scale':1, - 'position':(-450,30), + 'position':(-480,20), 'color':(1,1,1) }) diff --git a/dist/ba_root/mods/tools/whitelist.py b/dist/ba_root/mods/tools/whitelist.py index 2336c1a..354ae92 100644 --- a/dist/ba_root/mods/tools/whitelist.py +++ b/dist/ba_root/mods/tools/whitelist.py @@ -19,15 +19,16 @@ if TYPE_CHECKING: pass +whitelist={} -white_logs_path = _ba.env()["python_directory_user"]+"/tools/whitelist.json" -logs_paths = _ba.env()["python_directory_user"]+"/tools/logs.txt" +whitelistFile = _ba.env()["python_directory_user"]+"/tools/whitelist.json" +logs_path = _ba.env()["python_directory_user"]+"/serverData/wl_logs.txt" def commit(data): - with open(white_logs_path, "w") as f: + with open(whitelistFile, "w") as f: json.dump(data, f, indent=4) @@ -37,9 +38,20 @@ def add_commit_to_logs(commit : str): def get_whitelist_data(): - with open(white_logs_path, "r") as f: - data = json.load(f) - return data + global whitelist + if whitelist != {}: + return whitelist + try: + with open(whitelistFile, "r") as f: + data = json.load(f) + whitelist=data + except: + print("No Whitelist Detected , Creating One") + whitelist={} + whitelist['pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE']=['smoothyki-id','mr.smoothy'] + commit(whitelist) + + return whitelist def in_white_list(accountid : str): @@ -83,47 +95,48 @@ def display_string_in_white_list(display_string : str): return any(display_string in i for i in data.values()) -class _whitelist_: +class Whitelist: def __init__(self): + global whitelist settings = setting.get_settings_data()["white_list"] whitelist_on = settings["whitelist_on"] spectators = settings["spectators"] lobbychecktime = settings["lobbychecktime"] - _ba.chatmessage(f"{settings} {whitelist_on} {spectators} {lobbychecktime}") + # _ba.chatmessage(f"{settings} {whitelist_on} {spectators} {lobbychecktime}") + + + get_whitelist_data() - try: - data = get_whitelist_data() - - except: - print("No Whitelist Detected , Creating One") - self.whitelst = {} - self.whitelst['pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE']=['smoothyki-id','mr.smoothy'] - commit(whitelst) if whitelist_on and not spectators: - self.timer = ba.timer(lobbychecktime, self.checklobby, repeat=True, timetype=TimeType.REAL) + self.timer = ba.Timer(lobbychecktime, self.checklobby, repeat=True, timetype=TimeType.REAL) def checklobby(self): - + global whitelist settings = setting.get_settings_data()["white_list"] whitelist_on = settings["whitelist_on"] spectators = settings["spectators"] lobbychecktime = settings["lobbychecktime"] if whitelist_on and not spectators: - try: + if True: rost = _ba.get_game_roster() for i in rost: if i['account_id'] in whitelist and i['account_id'] != '' or i['client_id'] == -1: - return + pass else: - add_commit_to_logs("Kicked from lobby "+i['account_id']+" "+i['spec_string']) + try: + add_commit_to_logs("Kicked from lobby "+i['account_id']) + except: + pass _ba.disconnect_client(i['client_id']) - except: - return + # except: + # return + else: + self.timer =None