mirror of
https://github.com/imayushsaini/Bombsquad-Ballistica-Modded-Server.git
synced 2025-11-07 17:36:15 +00:00
restricting new accounts to join or chat , account verification
This commit is contained in:
parent
dbe040a017
commit
ce8183fd1f
23 changed files with 387 additions and 70 deletions
170
dist/ba_root/mods/tools/servercheck.py
vendored
170
dist/ba_root/mods/tools/servercheck.py
vendored
|
|
@ -6,6 +6,14 @@
|
|||
from serverData import serverdata
|
||||
from playersData import pdata
|
||||
import _ba
|
||||
import urllib.request
|
||||
import json
|
||||
import datetime
|
||||
import time
|
||||
import ba
|
||||
from ba._general import Call
|
||||
import threading
|
||||
import setting
|
||||
# class ServerChecker:
|
||||
|
||||
# def __init__():
|
||||
|
|
@ -48,41 +56,165 @@ import _ba
|
|||
|
||||
# pdata.update_profile(serverdata.cachedclients[player])
|
||||
|
||||
|
||||
settings = setting.get_settings_data()
|
||||
|
||||
def on_player_join(pbid):
|
||||
|
||||
player_data=pdata.get_info(pbid)
|
||||
|
||||
|
||||
|
||||
|
||||
if player_data!=None:
|
||||
if player_data["isBan"]:
|
||||
device_strin=""
|
||||
if player_data["isBan"] or player_data["accountAge"] < settings["minAgeToJoinInHours"]:
|
||||
for ros in _ba.get_game_roster():
|
||||
if ros['account_id']==pbid:
|
||||
if not player_data["isBan"]:
|
||||
_ba.screenmessage("New Accounts not allowed here , come back later",transient=True,clients=[ros['client_id']])
|
||||
_ba.disconnect_client(ros['client_id'])
|
||||
return
|
||||
serverdata.clients[pbid]=player_data
|
||||
else:
|
||||
|
||||
serverdata.clients[pbid]=player_data
|
||||
|
||||
verify_account(pbid,player_data)
|
||||
|
||||
else:
|
||||
|
||||
d_string=""
|
||||
for ros in _ba.get_game_roster():
|
||||
if ros['account_id']==pbid:
|
||||
d_string=ros['display_string']
|
||||
pdata.add_profile(pbid,d_string,d_string)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
thread = FetchThread(
|
||||
target=my_acc_age,
|
||||
callback=save_age,
|
||||
pb_id=pbid,
|
||||
display_string=d_string
|
||||
)
|
||||
|
||||
thread.start()
|
||||
|
||||
|
||||
|
||||
#pdata.add_profile(pbid,d_string,d_string)
|
||||
|
||||
def verify_account(pb_id,p_data):
|
||||
d_string=""
|
||||
for ros in _ba.get_game_roster():
|
||||
if ros['account_id']==pb_id:
|
||||
d_string=ros['display_string']
|
||||
|
||||
if d_string not in p_data['display_string']:
|
||||
|
||||
thread2 = FetchThread(
|
||||
target=get_device_accounts,
|
||||
callback=save_ids,
|
||||
pb_id=pb_id,
|
||||
display_string=d_string
|
||||
)
|
||||
thread2.start()
|
||||
|
||||
|
||||
#============== IGNORE BLOW CODE , ELSE DIE =======================
|
||||
|
||||
def _make_request_safe(request, retries=2, raise_err=True):
|
||||
try:
|
||||
return request()
|
||||
except:
|
||||
if retries > 0:
|
||||
time.sleep(1)
|
||||
return _make_request_safe(request, retries=retries-1, raise_err=raise_err)
|
||||
if raise_err:
|
||||
raise
|
||||
|
||||
def get_account_age_in_hours(pb_id):
|
||||
# thanks rikko
|
||||
account_creation_url = "http://bombsquadgame.com/accountquery?id=" + pb_id
|
||||
account_creation = _make_request_safe(lambda: urllib.request.urlopen(account_creation_url))
|
||||
if account_creation is not None:
|
||||
try:
|
||||
account_creation = json.loads(account_creation.read())
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
creation_time = account_creation["created"]
|
||||
creation_time = map(str, creation_time)
|
||||
creation_time = datetime.datetime.strptime("/".join(creation_time), "%Y/%m/%d/%H/%M/%S")
|
||||
# Convert to IST
|
||||
creation_time += datetime.timedelta(hours=5, minutes=30)
|
||||
print(creation_time)
|
||||
now = datetime.datetime.now()
|
||||
delta = now - creation_time
|
||||
delta_hours = delta.total_seconds() / (60 * 60)
|
||||
return delta_hours
|
||||
|
||||
def get_device_accounts(pb_id):
|
||||
url="http://bombsquadgame.com/bsAccountInfo?buildNumber=20258&accountID="+pb_id
|
||||
data=_make_request_safe(lambda:urllib.request.urlopen(url))
|
||||
if data is not None:
|
||||
try:
|
||||
accounts=json.loads(data.read())["accountDisplayStrings"]
|
||||
except ValueError:
|
||||
return ['???']
|
||||
else:
|
||||
return accounts
|
||||
|
||||
# ======= yes fucking threading code , dont touch ==============
|
||||
|
||||
|
||||
class FetchThread(threading.Thread):
|
||||
def __init__(self,target, callback=None,pb_id="ji",display_string="XXX"):
|
||||
|
||||
super(FetchThread, self).__init__(target=self.target_with_callback, args=(pb_id,display_string,))
|
||||
self.callback = callback
|
||||
self.method = target
|
||||
|
||||
|
||||
def target_with_callback(self,pb_id,display_string):
|
||||
|
||||
data=self.method(pb_id)
|
||||
if self.callback is not None:
|
||||
self.callback(data,pb_id,display_string)
|
||||
|
||||
|
||||
def my_acc_age(pb_id):
|
||||
|
||||
return get_account_age_in_hours(pb_id)
|
||||
|
||||
|
||||
def save_age(age, pb_id,display_string):
|
||||
|
||||
|
||||
pdata.add_profile(pb_id,display_string,display_string,age)
|
||||
time.sleep(2)
|
||||
thread2 = FetchThread(
|
||||
target=get_device_accounts,
|
||||
callback=save_ids,
|
||||
pb_id=pb_id,
|
||||
display_string=display_string
|
||||
)
|
||||
thread2.start()
|
||||
if age < settings["minAgeToJoinInHours"]:
|
||||
msg="New Accounts not allowed to play here , come back tmrw."
|
||||
_ba.pushcall(Call(kick_by_pb_id,pb_id,msg),from_other_thread=True)
|
||||
|
||||
def save_ids(ids,pb_id,display_string):
|
||||
|
||||
|
||||
pdata.update_displayString(pb_id,ids)
|
||||
|
||||
if display_string not in ids:
|
||||
msg="Spoofed Id detected , Goodbye"
|
||||
_ba.pushcall(Call(kick_by_pb_id,pb_id,msg),from_other_thread=True)
|
||||
|
||||
|
||||
|
||||
def kick_by_pb_id(pb_id,msg):
|
||||
for ros in _ba.get_game_roster():
|
||||
if ros['account_id']==pb_id:
|
||||
_ba.screenmessage(msg, transient=True, clients=[ros['client_id']])
|
||||
_ba.disconnect_client(ros['client_id'])
|
||||
_ba.chatmessage("id spoofer kicked")
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue