From b8b12a3e5115ff3e91bdfcc903d7115280e3d314 Mon Sep 17 00:00:00 2001 From: ElJeffe Date: Thu, 16 Jan 2020 16:49:27 -0800 Subject: [PATCH] Fixed some scoreboard triggers #330 --- handlers/AdminHandlers/AdminGameHandlers.py | 1 + handlers/AdminHandlers/AdminGameObjectHandlers.py | 7 ++++--- handlers/AdminHandlers/AdminUserHandlers.py | 9 +++++++-- handlers/MarketHandlers.py | 3 ++- handlers/MissionsHandler.py | 7 +++---- handlers/PublicHandlers.py | 2 -- handlers/UpgradeHandlers.py | 9 ++++++--- libs/EventManager.py | 4 ++++ setup/__init__.py | 2 +- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/handlers/AdminHandlers/AdminGameHandlers.py b/handlers/AdminHandlers/AdminGameHandlers.py index 868d7962..37f8d3df 100644 --- a/handlers/AdminHandlers/AdminGameHandlers.py +++ b/handlers/AdminHandlers/AdminGameHandlers.py @@ -621,6 +621,7 @@ def post(self, *args, **kwargs): self.dbsession.add(flag) self.dbsession.commit() self.dbsession.flush() + self.event_manager.push_score_update() self.flush_memcached() success = "Successfully Reset Game" self.render("admin/reset.html", success=success, errors=errors) diff --git a/handlers/AdminHandlers/AdminGameObjectHandlers.py b/handlers/AdminHandlers/AdminGameObjectHandlers.py index 08155a1c..ab66e59d 100644 --- a/handlers/AdminHandlers/AdminGameObjectHandlers.py +++ b/handlers/AdminHandlers/AdminGameObjectHandlers.py @@ -57,7 +57,6 @@ ) from libs.ValidationError import ValidationError from libs.SecurityDecorators import * -from libs.Scoreboard import Scoreboard from builtins import str @@ -139,7 +138,7 @@ def create_team(self): team.avatar = self.request.files["avatar"][0]["body"] self.dbsession.add(team) self.dbsession.commit() - Scoreboard.update_gamestate(self) + self.event_manager.push_score_update() self.redirect("/admin/users") except ValidationError as error: self.render("admin/create/team.html", errors=[str(error)]) @@ -416,6 +415,7 @@ def post(self, *args, **kwargs): if penalty: self.dbsession.delete(penalty) self.dbsession.add(team) + self.dbsession.commit() self.event_manager.admin_score_update( team, "%s penalty reversed - score has been updated." % team.name, @@ -431,6 +431,7 @@ def post(self, *args, **kwargs): ) flag.value = int(flag.value - (flag.value * depreciation)) self.dbsession.add(flag) + self.dbsession.commit() self.event_manager.flag_captured(team, flag) self._check_level(flag, team) success.append("%s awarded %d" % (team.name, value)) @@ -447,12 +448,12 @@ def post(self, *args, **kwargs): if len(token) < 256: flag.token = token self.dbsession.add(flag) + self.dbsession.commit() success.append( "Token succesfully added for Flag %s" % flag.name ) else: errors.append("Flag token too long. Can not expand token.") - self.dbsession.commit() self.render(uri[args[0]], errors=errors, success=success) else: self.render("public/404.html") diff --git a/handlers/AdminHandlers/AdminUserHandlers.py b/handlers/AdminHandlers/AdminUserHandlers.py index cb60faf3..d047662c 100644 --- a/handlers/AdminHandlers/AdminUserHandlers.py +++ b/handlers/AdminHandlers/AdminUserHandlers.py @@ -61,13 +61,12 @@ def post(self, *args, **kwargs): for team in teams: team.money += value self.dbsession.add(team) - self.event_manager.admin_score_update(team, message, value) else: team = Team.by_uuid(group) team.money += value self.dbsession.add(team) - self.event_manager.admin_score_update(team, message, value) self.dbsession.commit() + self.event_manager.admin_score_update(team, message, value) self.redirect("/admin/users") except ValidationError as error: self.render("admin/view/users.html", errors=[str(error)]) @@ -102,6 +101,7 @@ def edit_team(self): team._avatar = avatar self.dbsession.add(team) self.dbsession.commit() + self.event_manager.push_score_update() self.redirect("/admin/users") except ValidationError as error: self.render("admin/view/users.html", errors=[str(error)]) @@ -179,6 +179,7 @@ def edit_user(self): self.dbsession.delete(permission) self.dbsession.commit() + self.event_manager.push_score_update() self.redirect("/admin/users") except ValidationError as error: self.render("admin/view/users.html", errors=[str(error)]) @@ -202,8 +203,10 @@ def del_user(self): user = User.by_uuid(self.get_argument("uuid", "")) if user is not None and user != self.get_current_user(): logging.info("Deleted User: '%s'" % str(user.handle)) + EventManager.instance().deauth(user) self.dbsession.delete(user) self.dbsession.commit() + self.event_manager.push_score_update() self.redirect("/admin/users") else: self.render("admin/view/users.html", errors=["User does not exist"]) @@ -225,8 +228,10 @@ def del_team(self): logging.info("Deleted Team: '%s'" % str(team.name)) self.dbsession.delete(team) self.dbsession.commit() + self.event_manager.push_score_update() self.redirect("/admin/users") else: + self.event_manager.push_score_update() self.render("admin/view/users.html", errors=["Team does not exist"]) diff --git a/handlers/MarketHandlers.py b/handlers/MarketHandlers.py index e5438601..d28417a3 100644 --- a/handlers/MarketHandlers.py +++ b/handlers/MarketHandlers.py @@ -64,7 +64,7 @@ def post(self, *args, **kwargs): money = "$%d" % team.money else: money = "%d points" % team.money - message = "You only have %s" % (money) + message = "You only have %s" % money self.render("market/view.html", user=user, errors=[message]) else: logging.info( @@ -87,6 +87,7 @@ def purchase_item(self, team, item): team.items.append(item) self.dbsession.add(team) self.dbsession.commit() + self.event_manager.push_score_update() class MarketDetailsHandler(BaseHandler): diff --git a/handlers/MissionsHandler.py b/handlers/MissionsHandler.py index ad9f532f..93d596d4 100644 --- a/handlers/MissionsHandler.py +++ b/handlers/MissionsHandler.py @@ -31,7 +31,6 @@ from builtins import next from builtins import str from past.utils import old_div - from libs.SecurityDecorators import authenticated from libs.StringCoding import decode, encode from handlers.BaseHandlers import BaseHandler @@ -360,7 +359,7 @@ def success_capture(self, flag, old_reward=None): self.dbsession.commit() self.event_manager.level_unlocked(user, next_level) success.append("Congratulations! You have unlocked " + next_level.name) - + self.event_manager.push_score_update() return success def failed_capture(self, flag, submission): @@ -490,12 +489,12 @@ def post(self, *args, **kwargs): def _purchase_hint(self, hint, team): """ Add hint to team object """ if hint not in team.hints: + user = self.get_current_user() team.money -= abs(hint.price) team.hints.append(hint) - user = self.get_current_user() - self.event_manager.hint_taken(user, hint) self.dbsession.add(team) self.dbsession.commit() + self.event_manager.hint_taken(user, hint) def render_page(self, box, errors=[], success=[], info=[]): """ Wrapper to .render() to avoid duplicate code """ diff --git a/handlers/PublicHandlers.py b/handlers/PublicHandlers.py index bb55d75f..ef0ab0ab 100644 --- a/handlers/PublicHandlers.py +++ b/handlers/PublicHandlers.py @@ -30,7 +30,6 @@ from netaddr import IPAddress from libs.SecurityDecorators import blacklist_ips from libs.ValidationError import ValidationError -from libs.Scoreboard import Scoreboard from builtins import str from models.Team import Team from models.Theme import Theme @@ -234,7 +233,6 @@ def create_user(self): self.dbsession.add(user) self.dbsession.add(team) self.dbsession.commit() - Scoreboard.update_gamestate(self) self.event_manager.user_joined_team(user) # Chat diff --git a/handlers/UpgradeHandlers.py b/handlers/UpgradeHandlers.py index 053f5dcf..056110e1 100644 --- a/handlers/UpgradeHandlers.py +++ b/handlers/UpgradeHandlers.py @@ -69,6 +69,7 @@ def post(self, *args, **kwargs): user.team.money -= self.config.password_upgrade_cost self.dbsession.add(user.team) self.dbsession.commit() + self.event_manager.push_score_update() self.update_password(passwd) self.render_page() else: @@ -134,7 +135,7 @@ def post(self, *args, **kwargs): def ls(self): current_user = self.get_current_user() - if self.get_argument("data").lower() == "accounts": + if self.get_argument("data", "").lower() == "accounts": data = {} for team in Team.all(): if team == current_user.team: @@ -146,7 +147,7 @@ def ls(self): "bots": team.bot_count, } self.write({"accounts": data}) - elif self.get_argument("data").lower() == "users": + elif self.get_argument("data", "").lower() == "users": data = {} target_users = User.not_team(current_user.team.id) for user in target_users: @@ -161,7 +162,7 @@ def ls(self): self.finish() def info(self): - team_name = self.get_argument("account") + team_name = self.get_argument("account", "") team = Team.by_name(team_name) if team is not None: self.write( @@ -271,6 +272,7 @@ def purchase_code(self, box): ) self.dbsession.add(team) self.dbsession.commit() + self.event_manager.push_score_update() def render_page(self, errors=None): """ Addes extra params to render() """ @@ -362,6 +364,7 @@ def create_swat(self, user, target): self.dbsession.add(swat) self.dbsession.add(user.team) self.dbsession.commit() + self.event_manager.push_score_update() def render_page(self, errors=None): """ Render page with extra arguments """ diff --git a/libs/EventManager.py b/libs/EventManager.py index 4cca686e..e5db9d45 100644 --- a/libs/EventManager.py +++ b/libs/EventManager.py @@ -161,6 +161,9 @@ def admin_score_update(self, team, message, value): self.io_loop.add_callback(self.push_team, team.id) self.io_loop.add_callback(self.push_scoreboard) + def push_score_update(self): + self.io_loop.add_callback(self.push_scoreboard) + def admin_message(self, message): """ Callback for when admin point change is made """ Notification.create_broadcast(None, "Admin Message", message, INFO) @@ -267,6 +270,7 @@ def user_joined_team(self, user): message = "%s has joined the game" % (user.handle,) Notification.create_team(user.team, "New Player", message, INFO) self.io_loop.add_callback(self.push_team, user.team.id) + self.io_loop.add_callback(self.push_scoreboard) def team_file_shared(self, user, file_upload): """ Callback when a team file share is created """ diff --git a/setup/__init__.py b/setup/__init__.py index 3506f611..28ff9bbc 100644 --- a/setup/__init__.py +++ b/setup/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -__version__ = "3.3.5" +__version__ = "3.3.6"