本文整理汇总了Python中models.Team.Team类的典型用法代码示例。如果您正苦于以下问题:Python Team类的具体用法?Python Team怎么用?Python Team使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Team类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_team
def create_team():
team = Team()
team.name = "TestTeam"
team.motto = "TestMotto"
dbsession.add(team)
dbsession.commit()
return team
示例2: create_team
def create_team(self):
''' Create a new team in the database '''
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
self.dbsession.add(team)
self.dbsession.commit()
self.redirect('/admin/view/user_objects')
示例3: post
def post(self, *args, **kwargs):
game_objects = {
'game_level': GameLevel,
'corporation': Corporation,
'flag': Flag,
'box': Box,
'hint': Hint,
}
obj_name = self.get_argument('obj', '')
uuid = self.get_argument('uuid', '')
if obj_name in game_objects.keys():
obj = game_objects[obj_name].by_uuid(uuid)
if obj is not None:
self.write(obj.to_dict())
else:
self.write({'Error': 'Invalid uuid.'})
elif obj_name == "stats":
flag = Flag.by_uuid(uuid)
if flag is not None:
if options.banking:
flaginfo = [{"name": flag.name, "token": flag.token, "price": "$" + str(flag.value)}]
else:
flaginfo = [{"name": flag.name, "token": flag.token, "price": str(flag.value) + " points"}]
captures = []
for item in Flag.captures(flag.id):
team = Team.by_id(item[0])
if team:
captures.append({"name": team.name})
attempts = []
for item in Penalty.by_flag_id(flag.id):
team = Team.by_id(item.team_id)
if team:
attempts.append({"name": team.name, "token": item.token})
hints = []
for item in Hint.taken_by_flag(flag.id):
team = Team.by_id(item.team_id)
hint = Hint.by_id(item.hint_id)
if team:
if options.banking:
hints.append({"name": team.name, "price": "$" + str(hint.price)})
else:
hints.append({"name": team.name, "price": str(hint.price) + " points"})
obj = {
"flag": flaginfo,
"captures": captures,
"attempts": attempts,
"hints": hints,
}
self.write(obj)
else:
self.write({'Error': 'Invalid uuid.'})
else:
self.write({'Error': 'Invalid object type.'})
self.finish()
示例4: create_team
def create_team(self):
''' Create a new team '''
if self.config.public_teams:
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
return team
else:
raise ValidationError("Public teams are not enabled")
示例5: team_details
def team_details(self):
print self.get_argument('uuid', '')
team = Team.by_uuid(self.get_argument('uuid', ''))
if team is not None:
self.write(team.to_dict())
else:
self.write({})
示例6: post
def post(self, *args, **kwargs):
''' Called to purchase an item '''
uuid = self.get_argument('uuid', '')
item = MarketItem.by_uuid(uuid)
if not item is None:
user = self.get_current_user()
team = Team.by_id(user.team.id) # Refresh object
if user.has_item(item.name):
self.render('market/view.html',
user=user,
errors=["You have already purchased this item."]
)
elif team.money < item.price:
message = "You only have $%d" % (team.money,)
self.render('market/view.html', user=user, errors=[message])
else:
logging.info("%s (%s) purchased '%s' for $%d" % (
user.handle, team.name, item.name, item.price
))
self.purchase_item(team, item)
self.event_manager.item_purchased(user, item)
self.redirect('/user/market')
else:
self.render('market/view.html',
user=self.get_current_user(),
errors=["Item does not exist."]
)
示例7: score_bots
def score_bots():
''' Award money for botnets '''
logging.info("Scoring botnets, please wait ...")
bot_manager = BotManager.instance()
for team in Team.all():
bots = bot_manager.by_team(team.name)
reward = 0
for bot in bots:
try:
reward += options.bot_reward
bot.write_message({
'opcode': 'status',
'message': 'Collected $%d reward' % options.bot_reward
})
except:
logging.info(
"Bot at %s failed to respond to score ping" % bot.remote_ip
)
if 0 < len(bots):
logging.info("%s was awarded $%d for controlling %s bot(s)" % (
team.name, reward, len(bots),
))
bot_manager.add_rewards(team.name, options.bot_reward)
bot_manager.notify_monitors(team.name)
team.money += reward
dbsession.add(team)
dbsession.flush()
dbsession.commit()
示例8: create_team
def create_team(self):
''' Admins can create teams manually '''
try:
name = self.get_argument('team_name', '')
motto = self.get_argument('motto', '')
if Team.by_name(name) is not None:
raise ValidationError("Team already exists")
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
level_0 = GameLevel.all()[0]
self.dbsession.add(team)
self.dbsession.commit()
self.redirect('/admin/users')
except ValidationError as error:
self.render("admin/create/team.html", errors=[str(error), ])
示例9: ls
def ls(self):
current_user = self.get_current_user()
if self.get_argument('data').lower() == 'accounts':
data = {}
for team in Team.all():
if team == current_user.team:
continue
else:
data[team.name] = {
'money': team.money,
'flags': len(team.flags),
'bots': team.bot_count,
}
self.write({'accounts': data})
elif self.get_argument('data').lower() == 'users':
data = {}
target_users = User.not_team(current_user.team.id)
for user in target_users:
data[user.handle] = {
'account': user.team.name,
'algorithm': user.algorithm,
'password': user.bank_password,
}
self.write({'users': data})
else:
self.write({'Error': 'Invalid data type'})
self.finish()
示例10: now
def now(self, app):
''' Returns the current game state '''
game_state = {}
for team in Team.all():
if len(team.members) > 0:
millis = int(round(time.time() * 1000))
game_state[team.name] = {
'uuid': team.uuid,
'flags': [str(flag) for flag in team.flags],
'game_levels': [str(lvl) for lvl in team.game_levels],
}
highlights = {'money': 0, 'flag': 0, 'bot': 0, 'hint': 0}
for item in highlights:
value = team.get_score(item)
game_state[team.name][item] = value
game_history = app.settings['scoreboard_history']
if team.name in game_history:
prev = game_history[team.name][item]
if prev < value:
highlights[item] = millis
else:
highlights[item] = game_history[team.name]['highlights'][item]
highlights['now'] = millis
game_state[team.name]['highlights'] = highlights
app.settings['scoreboard_history'][team.name] = game_state.get(team.name)
return json.dumps(game_state)
示例11: create_team
def create_team(self):
''' Admins can create teams manually '''
try:
name = self.get_argument('team_name', '')
if Team.by_name(name) is not None:
raise ValidationError("Team already exists")
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
if not self.config.banking:
team.money = 0
level_0 = GameLevel.by_number(0)
if not level_0:
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
self.dbsession.add(team)
self.dbsession.commit()
# Avatar
avatar_select = self.get_argument('team_avatar_select', '')
if avatar_select and len(avatar_select) > 0:
team._avatar = avatar_select
elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
team.avatar = self.request.files['avatar'][0]['body']
self.dbsession.add(team)
self.dbsession.commit()
self.redirect('/admin/users')
except ValidationError as error:
self.render("admin/create/team.html", errors=[str(error), ])
示例12: now
def now(self):
''' Returns the current game state '''
game_state = {}
for team in Team.all():
game_state[team.name] = {
'money': team.money,
'flags': [str(flag) for flag in team.flags],
'game_levels': [str(lvl) for lvl in team.game_levels],
}
return json.dumps(game_state)
示例13: now
def now(self):
""" Returns the current game state """
game_state = {}
for team in Team.all():
game_state[team.name] = {
"money": team.money,
"flags": [str(flag) for flag in team.flags],
"game_levels": [str(lvl) for lvl in team.game_levels],
}
return json.dumps(game_state)
示例14: transfer
def transfer(self):
user = self.get_current_user()
source = Team.by_name(self.get_argument('source', ''))
destination = Team.by_name(self.get_argument('destination', ''))
try:
amount = int(self.get_argument('amount', 0))
except ValueError:
amount = 0
victim_user = User.by_handle(self.get_argument('user', None))
password = self.get_argument('password', '')
user = self.get_current_user()
# Validate what we got from the user
if source is None:
self.write({"error": "Source account does not exist"})
elif destination is None:
self.write({"error": "Destination account does not exist"})
elif victim_user is None or victim_user not in source.members:
self.write({"error": "User is not authorized for this account"})
elif victim_user in user.team.members:
self.write({"error": "You cannot steal from your own team"})
elif not 0 < amount <= source.money:
self.write({
"error":
"Invalid transfer amount; must be greater than 0 and less than $%d" % source.money
})
elif destination == source:
self.write({
"error": "Source and destination are the same account"
})
elif victim_user.validate_bank_password(password):
logging.info("Transfer request from %s to %s for $%d by %s" % (
source.name, destination.name, amount, user.handle
))
xfer = self.theft(victim_user, destination, amount, password)
self.write({
"success":
"Confirmed transfer to '%s' for $%d (15%s commission)" % (
destination.name, xfer, '%'
)
})
else:
self.write({"error": "Incorrect password for account, try again"})
self.finish()
示例15: get_team
def get_team(self):
''' Create a team object, or pull the existing one '''
code = self.get_argument('team-code', '')
if len(code) > 0:
team = Team.by_code(code)
if not team:
raise ValidationError("Invalid team code")
elif self.config.max_team_size <= len(team.members):
raise ValidationError("Team %s is already full" % team.name)
return team
return self.create_team()