Bombsquad-Ballistica-Modded.../dist/ba_root/mods/tools/ServerUpdate.py

111 lines
2.8 KiB
Python
Raw Normal View History

2023-08-14 18:29:15 +05:30
import _thread
import json
2023-08-15 16:43:07 +05:30
import time
import urllib.request
2023-08-14 18:29:15 +05:30
import requests
2023-08-15 16:43:07 +05:30
from playersData import pdata
2023-08-15 01:53:52 +05:30
import babase
import bascenev1
2023-08-15 16:43:07 +05:30
from efro.terminal import Clr
2023-08-14 18:29:15 +05:30
VERSION = 71
def check():
2023-08-15 01:53:52 +05:30
print("hey")
print(babase.app.classic)
print(babase.app.classic.server)
2023-08-14 18:29:15 +05:30
_thread.start_new_thread(updateProfilesJson, ())
_thread.start_new_thread(checkChangelog, ())
2023-08-15 01:53:52 +05:30
bascenev1.AppTimer(5, postStatus)
2023-08-14 18:29:15 +05:30
def updateProfilesJson():
profiles = pdata.get_profiles()
for id in profiles:
if "spamCount" not in profiles[id]:
profiles[id]["spamCount"] = 0
profiles[id]["lastSpam"] = time.time()
pdata.commit_profiles(profiles)
2023-08-15 01:53:52 +05:30
def postStatus():
print("post status clled finally")
link = 'https://bcsservers.ballistica.workers.dev/ping'
data = {'name': babase.app.classic.server._config.party_name,
'port': str(bascenev1.get_game_port()),
'build': babase.app.build_number,
'bcsversion': VERSION}
_thread.start_new_thread(postRequest, (link, data,))
2023-08-15 16:43:07 +05:30
2023-08-15 01:53:52 +05:30
def postRequest(link, data):
print(data)
2023-08-14 18:29:15 +05:30
try:
2023-08-15 01:53:52 +05:30
res = requests.post(link,
2023-08-14 18:29:15 +05:30
json=data)
except:
pass
def checkSpammer(data):
def checkMaster(data):
try:
2023-08-15 16:43:07 +05:30
res = requests.post(
'https://bcsservers.ballistica.workers.dev/checkspammer',
json=data)
2023-08-14 18:29:15 +05:30
except:
pass
# TODO handle response and kick player based on status
2023-08-15 16:43:07 +05:30
2023-08-14 18:29:15 +05:30
_thread.start_new_thread(checkMaster, (data,))
return
def fetchChangelogs():
url = "https://raw.githubusercontent.com/imayushsaini/Bombsquad-Ballistica-Modded-Server/public-server/dist/ba_root/mods/changelogs.json"
2023-08-15 16:43:07 +05:30
if 2 * 2 == 4:
2023-08-14 18:29:15 +05:30
try:
data = urllib.request.urlopen(url)
changelog = json.loads(data.read())
except:
return None
else:
return changelog
def checkChangelog():
changelog = fetchChangelogs()
if changelog == None:
print(
2023-08-15 16:43:07 +05:30
f'{Clr.BRED} UNABLE TO CHECK UPDATES , CHECK MANUALLY FROM URL {Clr.RST}',
flush=True)
2023-08-14 18:29:15 +05:30
else:
msg = ""
avail = False
for log in changelog:
if int(log) > VERSION:
avail = True
if not avail:
print(
2023-08-15 16:43:07 +05:30
f'{Clr.BGRN}{Clr.WHT} YOU ARE ON LATEST VERSION {Clr.RST}',
flush=True)
2023-08-14 18:29:15 +05:30
else:
2023-08-15 16:43:07 +05:30
print(f'{Clr.BYLW}{Clr.BLU} UPDATES AVAILABLE {Clr.RST}',
flush=True)
2023-08-14 18:29:15 +05:30
for log in changelog:
if int(log) > VERSION:
msg = changelog[log]["time"]
print(f'{Clr.CYN} {msg} {Clr.RST}', flush=True)
msg = changelog[log]["log"]
print(f'{Clr.MAG} {msg} {Clr.RST}', flush=True)