Bombsquad-Ballistica-Modded.../dist/ba_root/mods/privateserver.backup
2021-04-30 19:13:53 +05:30

168 lines
4.6 KiB
Text

"""
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
from __future__ import annotations
from typing import TYPE_CHECKING
from ba._enums import TimeType
import ba, json, _ba, time, datetime
if TYPE_CHECKING:
pass
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 """
admins = ['pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE']
"""Dirty admin system , for now , until we get good working chat commands """
def inWhiteList(id):
global whitelist
if id in whitelist:
return True
else:
return False
def addToWhitelist(id,displaystr):
global whitelist
if id not in whitelist:
whitelist[id]=[displaystr]
else:
whitelist[id].append(displaystr)
f=open("whitelist.json","w")
json.dump(whitelist,f,indent=4)
f.close()
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 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 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 dstrinWhiteList(dstr):
global whitelist
return any(dstr in chici for chici in whitelist.values())
# ba_meta export plugin
class private(ba.Plugin):
"""My first ballistica plugin!"""
def __init__(self):
global whitelist
global whitelist_on
global spectators
global lobbychecktime
try:
f=open("whitelist.json")
dat=json.loads(f.read())
whitelist=dat
f.close()
except:
print("no whitelist detected , creating one")
self.li={}
self.li['pb-JiNJARBaXEFBVF9HFkNXXF1EF0ZaRlZE']=['smoothyki-id','mr.smoothy']
f=open("whitelist.json",'w')
json.dump(self.li,f,indent=4)
f.close()
if whitelist_on and not spectators:
self.timerr=ba.Timer(lobbychecktime,self.checklobby,repeat=True,timetype=TimeType.REAL)
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