Skip to content

Commit

Permalink
Fixed some scoreboard triggers #330
Browse files Browse the repository at this point in the history
  • Loading branch information
eljeffeg committed Jan 17, 2020
1 parent 94ca6ad commit b8b12a3
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions handlers/AdminHandlers/AdminGameHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions handlers/AdminHandlers/AdminGameObjectHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
)
from libs.ValidationError import ValidationError
from libs.SecurityDecorators import *
from libs.Scoreboard import Scoreboard
from builtins import str


Expand Down Expand Up @@ -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)])
Expand Down Expand Up @@ -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,
Expand All @@ -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))
Expand All @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions handlers/AdminHandlers/AdminUserHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down Expand Up @@ -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)])
Expand Down Expand Up @@ -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)])
Expand All @@ -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"])
Expand All @@ -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"])


Expand Down
3 changes: 2 additions & 1 deletion handlers/MarketHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions handlers/MissionsHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 """
Expand Down
2 changes: 0 additions & 2 deletions handlers/PublicHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions handlers/UpgradeHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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() """
Expand Down Expand Up @@ -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 """
Expand Down
4 changes: 4 additions & 0 deletions libs/EventManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 """
Expand Down
2 changes: 1 addition & 1 deletion setup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "3.3.5"
__version__ = "3.3.6"

0 comments on commit b8b12a3

Please sign in to comment.