From 826f433e38adf76215fc30d47eefd915ab3b4bd6 Mon Sep 17 00:00:00 2001 From: Ayush Saini Date: Wed, 31 Mar 2021 13:02:42 +0530 Subject: [PATCH] basic role management and chatcmd --- .../mods/chatHandle/chatCMDS/chatcmd.py | 44 +++++++++ dist/ba_root/mods/chatHandle/chatCMDS/fun.py | 23 +++++ .../mods/chatHandle/chatCMDS/management.py | 22 +++++ .../mods/chatHandle/chatSpam/chatfilter.py | 3 + dist/ba_root/mods/chatHandle/handlechat.py | 24 ++++- dist/ba_root/mods/playersData/pdata.py | 89 ++++++++++++++++++ dist/ba_root/mods/playersData/roles.json | 27 ++++++ .../__pycache__/__init__.cpython-38.pyc | Bin 0 -> 378 bytes .../__pycache__/serverdata.cpython-38.pyc | Bin 0 -> 188 bytes dist/ba_root/mods/serverData/serverdata.py | 1 + dist/ba_root/mods/setting.py | 1 + dist/ba_root/mods/stats/rank.py | 1 + .../__pycache__/whitelist.cpython-38.pyc | Bin 0 -> 1032 bytes dist/ba_root/mods/tools/spamcheck.py | 1 + dist/ba_root/mods/tools/textonmap.py | 1 + 15 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 dist/ba_root/mods/chatHandle/chatSpam/chatfilter.py create mode 100644 dist/ba_root/mods/playersData/pdata.py create mode 100644 dist/ba_root/mods/serverData/__pycache__/__init__.cpython-38.pyc create mode 100644 dist/ba_root/mods/serverData/__pycache__/serverdata.cpython-38.pyc create mode 100644 dist/ba_root/mods/serverData/serverdata.py create mode 100644 dist/ba_root/mods/tools/__pycache__/whitelist.cpython-38.pyc diff --git a/dist/ba_root/mods/chatHandle/chatCMDS/chatcmd.py b/dist/ba_root/mods/chatHandle/chatCMDS/chatcmd.py index e69de29..0be0f4c 100644 --- a/dist/ba_root/mods/chatHandle/chatCMDS/chatcmd.py +++ b/dist/ba_root/mods/chatHandle/chatCMDS/chatcmd.py @@ -0,0 +1,44 @@ +# Released under the MIT License. See LICENSE for details. + +import ba +import _ba +from playersData import pdata +import fun,management +import setting +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 check_permission(pbid,cmnd): + roles=pdata.roles() + for role in roles: + if pbid in role.ids and cmnd in role.commands: + return True + return False + +def cmd_type(cmnd): + if cmnd in fun.cmnds: + return "fun" + if cmnd in management.cmnds: + return "management" + +def cmd(msg,client_id): + cmnd=msg.split(" ")[0].lower() + arg=msg.split(" ")[1:] + pbid=public_id(client_id) + if check_permission(pbid,cmnd): + if cmd_type(cmnd)=="fun": + fun.exec_cmd(cmnd,arg,client_id,pbid) + elif cmd_type(cmnd)=="management": + management.exec_cmd(cmnd,arg,client_id,pbid) + else: + _ba.chatmessage("no access",clients=client_id) + + if setting.brdcast_chatcmd: + return msg + return None + + diff --git a/dist/ba_root/mods/chatHandle/chatCMDS/fun.py b/dist/ba_root/mods/chatHandle/chatCMDS/fun.py index e69de29..6c79754 100644 --- a/dist/ba_root/mods/chatHandle/chatCMDS/fun.py +++ b/dist/ba_root/mods/chatHandle/chatCMDS/fun.py @@ -0,0 +1,23 @@ +# Released under the MIT License. See LICENSE for details. + + +cmnds=["/fly","/freeze"] + + +def exec_cmd(cmnd,arg,client_id,pbid): + if cmnd =="/fly": + fly() + + + +# ============== + +def fly(): + # do something + + +def freeze(): + # do something + +def spaz(): + #do something diff --git a/dist/ba_root/mods/chatHandle/chatCMDS/management.py b/dist/ba_root/mods/chatHandle/chatCMDS/management.py index e69de29..7d8240c 100644 --- a/dist/ba_root/mods/chatHandle/chatCMDS/management.py +++ b/dist/ba_root/mods/chatHandle/chatCMDS/management.py @@ -0,0 +1,22 @@ +# Released under the MIT License. See LICENSE for details. +cmnds=["/add","/kick"] + + +def exec_cmd(cmnd,arg,client_id,pbid): + if cmnd =="/kick": + kick(arg[0]) + + + +# ============== + +def kick(client_id): + _ba.disconnectclient(client_id) + # do something + + +def add(): + # do something + +def end(): + #do something diff --git a/dist/ba_root/mods/chatHandle/chatSpam/chatfilter.py b/dist/ba_root/mods/chatHandle/chatSpam/chatfilter.py new file mode 100644 index 0000000..bf3dea9 --- /dev/null +++ b/dist/ba_root/mods/chatHandle/chatSpam/chatfilter.py @@ -0,0 +1,3 @@ +# Released under the MIT License. See LICENSE for details. +def isAbuse(): + return \ No newline at end of file diff --git a/dist/ba_root/mods/chatHandle/handlechat.py b/dist/ba_root/mods/chatHandle/handlechat.py index 7796c9b..804ced4 100644 --- a/dist/ba_root/mods/chatHandle/handlechat.py +++ b/dist/ba_root/mods/chatHandle/handlechat.py @@ -1,2 +1,24 @@ -import playersData +# Released under the MIT License. See LICENSE for details. +from playersData import pdata +from chatCMDS import chatcmd +from chatFilter import chatfilter +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) + + if chatfilter.isAbuse(msg): + pdata.warn(public_id(client_id)) + return None + return msg + + diff --git a/dist/ba_root/mods/playersData/pdata.py b/dist/ba_root/mods/playersData/pdata.py new file mode 100644 index 0000000..fb54814 --- /dev/null +++ b/dist/ba_root/mods/playersData/pdata.py @@ -0,0 +1,89 @@ +# Released under the MIT License. See LICENSE for details. +roles={} +data={} + + +def roles(): + global roles + if roles=={}: + f=open("roles.json","r") + dat=json.loads(f.read()) + roles=dat + f.close() + return roles + +def create_role(role): + global roles + _roles=roles() + if role not in _roles: + _roles[role]={ + "tag":role, + "tagcolor":(1,1,1), + "commands":[], + "ids":[] + } + roles=_roles + comit() + return 'created successfully' + + + return 'already exists' + +def add_player_role(role,id): + global roles + _roles=roles() + if role in _roles: + _roles[role].ids.append(id) + roles=_roles + commit() + return 'added to '+role + return "role not exists" + +def add_command_role(role,command): + global roles + _roles=roles() + if role in _roles: + _roles[role].commands.append(command) + roles=_roles + commit() + return 'added '+command+"to "+role + return role+"not exists" + + +def remove_player_role(role,id): + global roles + _roles=roles() + if role in _roles: + _roles[role].ids.remove(id) + roles=_roles + commit() + return "removed" + return "role not exists" + +def remove_command_role(): + global roles + _roles=roles() + if role in _roles: + _roles[role].commands.remove(command) + roles=_roles + commit() + return 'removed '+command+"from "+role + return role+"not exists" + +def change_role_tag(role,tag): + global roles + _roles=roles() + if role in _roles: + _roles[role].tag=tag + roles=_roles + commit() + return "tag changed" + return "role not exists" + + +def commit(): + global roles + f=open("roles.json",'w') + json.dump(roles,f,indent=4) + f.close() + diff --git a/dist/ba_root/mods/playersData/roles.json b/dist/ba_root/mods/playersData/roles.json index e69de29..3903a38 100644 --- a/dist/ba_root/mods/playersData/roles.json +++ b/dist/ba_root/mods/playersData/roles.json @@ -0,0 +1,27 @@ +{ + "owner":{ + "tag":"OWNER", + "tagcolor":(1,1,1), + "commands":["add","kick","remove"], + "ids":["pb-ihugg7g9==","pb-7gt78"] + + }, + "admin":{ + "tag":"ADMIN", + "tagcolor":(1,1,1), + "commands":["kick","end"], + "ids":["pb-ugg","pb-767fyfd"] + }, + "vip":{ + "tag":"VIP", + "tagcolor":(1,1,1), + "commands":[], + "ids":[] + }, + "donor":{ + "tag":"DONOR", + "tagcolor":(2,2,2), + "commands":[], + "ids":[] + } +} \ No newline at end of file diff --git a/dist/ba_root/mods/serverData/__pycache__/__init__.cpython-38.pyc b/dist/ba_root/mods/serverData/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c2d851589a38bcae8471ca6aa8daea59bd692ca4 GIT binary patch literal 378 zcmYk1F-}7<42IJ(P(7&=7w}rC?Ew%%KszFq(gj5dY2w!yrO8v0*XnTwF2ZTpyK)3J zCfvtTOSa_X|9;!+@wgHktB>{T)j){vQ*$2tChj=%h>I03!VXqqGJOA9#N93i*igw3 zYpB~`3dNv3l@7Ag2`y}}91sI&?*Z!+p-J%#P091BdUh1H87P3mgiOTNp9o;oVn90u zM_cDRC|!fItZSTt4i*mR{mjHYQ>^cx4OFUvnfJ&P3_@|(0ndj6S!BM=EaW+!_6Wuk zhSD2lOl$%sTAWu;lfm&)DI1MapCS$U+P?fQ7uRyl(kxvg@0(_+ig`k0!7}G1Ti4}7{oyaOhAqU5Et_RiByIZhGs@ah7`tN22G|a-s04vveY7l zl*E#fl0-jE##^ifMVWaeD;bJF+Q7swH)pGuP@ux%n2drL$ASWv#FE4qpZw&+oEWFX yoSe+!lFZ~p=lr77nB4r7;uwgLU_}rn(C|dPg34PQHbD8(oK!nTpwXX!m;nHTWigxp literal 0 HcmV?d00001 diff --git a/dist/ba_root/mods/serverData/serverdata.py b/dist/ba_root/mods/serverData/serverdata.py new file mode 100644 index 0000000..9b46f9f --- /dev/null +++ b/dist/ba_root/mods/serverData/serverdata.py @@ -0,0 +1 @@ +# Released under the MIT License. See LICENSE for details. \ No newline at end of file diff --git a/dist/ba_root/mods/setting.py b/dist/ba_root/mods/setting.py index e69de29..9b46f9f 100644 --- a/dist/ba_root/mods/setting.py +++ b/dist/ba_root/mods/setting.py @@ -0,0 +1 @@ +# Released under the MIT License. See LICENSE for details. \ No newline at end of file diff --git a/dist/ba_root/mods/stats/rank.py b/dist/ba_root/mods/stats/rank.py index e69de29..9b46f9f 100644 --- a/dist/ba_root/mods/stats/rank.py +++ b/dist/ba_root/mods/stats/rank.py @@ -0,0 +1 @@ +# Released under the MIT License. See LICENSE for details. \ No newline at end of file diff --git a/dist/ba_root/mods/tools/__pycache__/whitelist.cpython-38.pyc b/dist/ba_root/mods/tools/__pycache__/whitelist.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..776e704a8709127c10c4ea7d1bada8051f77a4c0 GIT binary patch literal 1032 zcmYjQU2oGc6tx{EO}h?Fd`L*V1c8t$K?RSX35}JOF-A4PfDu*l+}hpJIZjAipjCO= zUil4dkNhRS^0dFe6W3vzcBRk9N&CcUTz?Wy-@7^@(}vtlB+=>SwjeyV*mmP ztWb($j2$M5q+aY**i$s7Q1g@@`_&%ALABT7n)Hg*3WsqBJ5}|x5jQY;g@iAHV)T*611ublsxYn8BCdqUO>GIC!?JnzVbUSZe_h0p)67D3a+?nNa_>p!aGKwl|m=q*773x%8i`gc{_{7Nl}_;$dyV;lZ<$jtLc8C z?~X8#Tm-m;LU=lk{X2m90|UMs;UC!G6SBZ3-YGi8Kgfb`3YmY3F#3e_7KR-o69{qy z{v~LESWS3>?vn+Y)P%o^9FGW&h+~?BuDZaYCc>ZK@deXoq{%M059;gv`L%BciIGlj zds1e4eqU$NWhoNU$dQpEdKirg2|numDARJ@EYmDA2eZTEQ6lDzv}m6f=J)d9qs^qh z`QqI=-|hC+KlYw(^bY&GyS*pf-s70RQ*qbgZ)a{S!2cl8LTb~hTbkukTk1quUu9gB zmO@Km>z8t@KT=sKtq+!K6BCtKDyC`P@+>W-8e2Su>*3}%DsBM%-?h%O!G}^7<=`M6 zyvXyH-0;CxHsWfqetAWmtdN5=6Xn2UnJNdD-P-xghKwaTF^oCBY7$UDaEPyAikmn9 z6aa4E>v+C$J_qfKBYhYSIInps8M6(>pvhD@++^&_l&kYMHO53XVyw6YJu2Z>mYc5T z!?NN8IMYH*NmXerJJRvgObZ|_+`QVr%yPJ+!i|_ELteOl(|T;kEj2LdHUxWQh3Z4z sW>QbnvT(FE*seykqP`-)eR$zi*l_j#2RwIj$|fvL(j*a~B*abf55F`B@c;k- literal 0 HcmV?d00001 diff --git a/dist/ba_root/mods/tools/spamcheck.py b/dist/ba_root/mods/tools/spamcheck.py index e69de29..9b46f9f 100644 --- a/dist/ba_root/mods/tools/spamcheck.py +++ b/dist/ba_root/mods/tools/spamcheck.py @@ -0,0 +1 @@ +# Released under the MIT License. See LICENSE for details. \ No newline at end of file diff --git a/dist/ba_root/mods/tools/textonmap.py b/dist/ba_root/mods/tools/textonmap.py index e69de29..9b46f9f 100644 --- a/dist/ba_root/mods/tools/textonmap.py +++ b/dist/ba_root/mods/tools/textonmap.py @@ -0,0 +1 @@ +# Released under the MIT License. See LICENSE for details. \ No newline at end of file