Merge pull request #22 from Argon2000/master

Add button / api to reload bots
This commit is contained in:
oldnapalm
2020-11-17 11:12:50 -03:00
committed by GitHub
4 changed files with 20 additions and 1 deletions
+2 -1
View File
@@ -3,4 +3,5 @@ storage/*
!storage/force_dir_in_git.txt
example-requests/*
zoffline.log
migrate_auth.sql
migrate_auth.sql
bots
+3
View File
@@ -20,6 +20,9 @@
{% elif is_admin %}
<a href="/cancelrestart" class="btn btn-sm btn-danger">Cancel restart</a>
{% endif %}
{% if is_admin %}
<a href="/reloadbots" class="btn btn-sm btn-warning">Reload bots</a>
{% endif %}
</div>
</div>
{% endif %}
+5
View File
@@ -402,7 +402,12 @@ def load_bots():
bot.position = 0
def play_bots():
global global_bots
while True:
if zwift_offline.reload_pacer_bots:
zwift_offline.reload_pacer_bots = False
global_bots.clear()
load_bots()
for bot_id in global_bots.keys():
bot = global_bots[bot_id]
if bot.position < len(bot.route.states) - 1: bot.position += 1
+10
View File
@@ -99,6 +99,7 @@ app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
db = SQLAlchemy(app)
online = {}
global_pace_partners = {}
global_bots = {}
ghosts_enabled = {}
player_update_queue = {}
player_ids = {}
@@ -106,6 +107,7 @@ player_partial_profiles = {}
save_ghost = None
restarting = False
restarting_in_minutes = 0
reload_pacer_bots = False
class User(UserMixin, db.Model):
player_id = db.Column(db.Integer, primary_key=True)
@@ -384,6 +386,14 @@ def cancel_restart_server():
send_message_to_all_online('Restart of the server has been cancelled. Ride on!')
return redirect('/user/%s/' % current_user.username)
@app.route("/reloadbots")
@login_required
def reload_bots():
global reload_pacer_bots
if bool(current_user.is_admin):
reload_pacer_bots = True
return redirect('/user/%s/' % current_user.username)
@app.route("/upload/<username>/", methods=["GET", "POST"])
@login_required
def upload(username):