auto stats reset , more mini games , known bugs fix

This commit is contained in:
Ayush Saini 2022-02-11 23:33:27 +05:30
parent d7f7d751f5
commit a9441c3e0a
15 changed files with 82 additions and 30 deletions

View file

@ -48,7 +48,7 @@ max_party_size: 6
# playlist editor in the regular version of the game.
# This will give you a numeric code you can enter here to host that
# playlist.
playlist_code: 345700
playlist_code: 347990
# Alternately, you can embed playlist data here instead of using codes.
# Make sure to set session_type to the correct type for the data here.

View file

@ -16,6 +16,8 @@ def filter(msg,pb_id,client_id):
addWarn(pb_id,client_id)
now = time.time()
if pb_id not in serverdata.clients:
return None
if "lastMsgTime" in serverdata.clients[pb_id]:
count=serverdata.clients[pb_id]["cMsgCount"]

View file

@ -165,9 +165,18 @@ def on_kick_vote_end():
import os
import importlib
def importgames():
from games import SquidRace
from games import StumbleRace
from games import SubwayRun
from maps import InTheAir
games=os.listdir("ba_root/mods/games")
for game in games:
if game.endswith(".py") or game.endswith(".so"):
importlib.import_module("games."+game.replace(".so","").replace(".py",""))
maps=os.listdir("ba_root/mods/maps")
for map in maps:
if map.endswith(".py") or map.endswith(".so"):
importlib.import_module("maps."+map.replace(".so","").replace(".py",""))

BIN
dist/ba_root/mods/games/CanonFight.so vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
dist/ba_root/mods/games/FlappyBird.so vendored Normal file

Binary file not shown.

BIN
dist/ba_root/mods/games/MonkeyClimb.so vendored Normal file

Binary file not shown.

Binary file not shown.

0
dist/ba_root/mods/games/__init__.py vendored Normal file
View file

Binary file not shown.

BIN
dist/ba_root/mods/maps/FloatingIsland.so vendored Normal file

Binary file not shown.

View file

@ -29,7 +29,7 @@
1
],
"commands": [],
"ids": ["pb-IF5XUm9eAg==", "pb-IF43VUwlAg==", "pb-IF4iVUc5Cg==", "pb-IF4vNnMJ", "pb-IF4TVWwZUQ=="]
"ids": ["pb-IF4VAk4a"]
},
"smoothy": {
"tag": "smoothy", "tagcolor": [1,

View file

@ -17,6 +17,7 @@
]
}
},
"statsResetAfterDays":31,
"leaderboard":{
"enable":true,
"barsBehindName":true

View file

@ -9,6 +9,7 @@ def addtag(node,player):
roles=pdata.get_roles()
p_roles=pdata.get_player_roles(account_id)
tag=None
col=(0.5,0.5,1) # default color for custom tags
if account_id in customtag:
tag=customtag[account_id]
elif p_roles !=[]:

View file

@ -18,6 +18,7 @@ from ba import _activitytypes as ba_actypes
from ba._activitytypes import *
import urllib.request
import custom_hooks
import datetime
#variables
our_settings = setting.get_settings_data()
# where our stats file and pretty html output will go
@ -45,16 +46,55 @@ html_start = f'''<!DOCTYPE html>
<th><b>Games Played</b></th>
</tr>
'''
statsDefault={
"pb-IF4VAk4a": {
"rank": 65,
"name": "pb-IF4VAk4a",
"scores": 0,
"total_damage": 0.0,
"kills": 0,
"deaths": 0,
"games": 18,
"kd": 0.0,
"avg_score": 0.0,
"aid": "pb-IF4VAk4a"
}
}
# <th><b>Total Damage</b></th> #removed this line as it isn't crt data
#useful functions
seasonStartDate=None
import shutil,os
def get_all_stats():
global seasonStartDate
if os.path.exists(statsfile):
renameFile=False
with open(statsfile, 'r') as f:
return json.loads(f.read())
else: print('Stats file not found!')
jsonData=json.loads(f.read())
try:
stats=jsonData["stats"]
seasonStartDate=datetime.datetime.strptime(jsonData["startDate"],"%d-%m-%Y")
if (datetime.datetime.now()-seasonStartDate).days >=our_settings["statsResetAfterDays"]:
backupStatsFile()
seasonStartDate=datetime.datetime.now()
return statsDefault
return stats
except:
return jsonData
else:
return {}
def backupStatsFile():
shutil.copy(statsfile,statsfile.replace(".json","")+str(seasonStartDate)+".json")
def dump_stats(s: dict):
global seasonStartDate
if seasonStartDate ==None:
seasonStartDate=datetime.datetime.now()
s={"startDate":seasonStartDate.strftime("%d-%m-%Y") , "stats":s}
if os.path.exists(statsfile):
with open(statsfile, 'w') as f:
f.write(json.dumps(s, indent=4))
@ -73,8 +113,9 @@ def refreshStats():
# lastly, write a pretty html version.
# our stats url could point at something like this...
pStats = get_all_stats()
f=open(htmlfile, 'w')
f.write(html_start)
# f=open(htmlfile, 'w')
# f.write(html_start)
entries = [(a['scores'], a['kills'], a['deaths'], a['games'], a['name'], a['aid']) for a in pStats.values()]
# this gives us a list of kills/names sorted high-to-low
entries.sort(reverse=True)
@ -123,24 +164,24 @@ def refreshStats():
pStats[str(aid)]["kd"] = float(p_kd)
pStats[str(aid)]["avg_score"] = float(p_avg_score)
if rank < 201:
#<td>{str(dmg)}</td> #removed this line as it isn't crt data
f.write(f'''
<tr>
<td>{str(rank)}</td>
<td style="text-align:center">{str(name)}</td>
<td>{str(scores)}</td>
<td>{str(kills)}</td>
<td>{str(deaths)}</td>
<td>{str(games)}</td>
</tr>''')
f.write('''
</table>
</body>
</html>''')
# if rank < 201:
# #<td>{str(dmg)}</td> #removed this line as it isn't crt data
# f.write(f'''
# <tr>
# <td>{str(rank)}</td>
# <td style="text-align:center">{str(name)}</td>
# <td>{str(scores)}</td>
# <td>{str(kills)}</td>
# <td>{str(deaths)}</td>
# <td>{str(games)}</td>
# </tr>''')
# f.write('''
# </table>
# </body>
# </html>''')
f.close()
# f.close()
global ranks
ranks=_ranks
@ -192,9 +233,7 @@ class UpdateThread(threading.Thread):
# pull our existing stats from disk
try:
if os.path.exists(statsfile):
with open(statsfile) as f:
stats = json.loads(f.read())
stats=get_all_stats()
except:
stats={}