本文整理汇总了Python中models.Team.Team类的典型用法代码示例。如果您正苦于以下问题:Python Team类的具体用法?Python Team怎么用?Python Team使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Team类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_team
def create_team():
team = Team()
team.name = "TestTeam"
team.motto = "TestMotto"
dbsession.add(team)
dbsession.commit()
return team
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:7,代码来源:Helpers.py
示例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')
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:10,代码来源:AdminHandlers.py
示例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()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:54,代码来源:AdminGameObjectHandlers.py
示例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")
开发者ID:WeiEast,项目名称:RootTheBox,代码行数:11,代码来源:PublicHandlers.py
示例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({})
开发者ID:WeiEast,项目名称:RootTheBox,代码行数:7,代码来源:AdminUserHandlers.py
示例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."]
)
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:27,代码来源:MarketHandlers.py
示例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()
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:28,代码来源:Scoreboard.py
示例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), ])
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:16,代码来源:AdminGameObjectHandlers.py
示例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()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:27,代码来源:UpgradeHandlers.py
示例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)
开发者ID:moloch--,项目名称:RootTheBox,代码行数:26,代码来源:Scoreboard.py
示例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), ])
开发者ID:moloch--,项目名称:RootTheBox,代码行数:29,代码来源:AdminGameObjectHandlers.py
示例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)
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:10,代码来源:Scoreboard.py
示例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)
开发者ID:ElmoArmy,项目名称:RootTheBox,代码行数:10,代码来源:Scoreboard.py
示例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()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:43,代码来源:UpgradeHandlers.py
示例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()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:11,代码来源:PublicHandlers.py
示例16: info
def info(self):
team_name = self.get_argument('account')
team = Team.by_name(team_name)
if team is not None:
self.write({
'name': team.name,
'balance': team.money,
'users': [user.handle for user in team.members]
})
else:
self.write({'error': 'Account does not exist'})
self.finish()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:12,代码来源:UpgradeHandlers.py
示例17: post
def post(self, *args, **kwargs):
try:
group = self.get_argument('team_uuid', 'all')
message = self.get_argument('message', '')
value = int(self.get_argument('money', 0))
if group == 'all':
teams = Team.all()
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.redirect('/admin/users')
except ValidationError as error:
self.render('admin/view/users.html',
errors=[str(error), ]
)
开发者ID:moloch--,项目名称:RootTheBox,代码行数:22,代码来源:AdminUserHandlers.py
示例18: existing_avatars
def existing_avatars(dir):
avatars = []
if dir == "team":
from models.Team import Team
teams = Team.all()
for team in teams:
if team.avatar is not None and len(team.members) > 0:
avatars.append(team.avatar)
else:
from models.User import User
users = User.all()
for user in users:
if user.avatar is not None:
avatars.append(user.avatar)
return avatars
开发者ID:moloch--,项目名称:RootTheBox,代码行数:15,代码来源:XSSImageCheck.py
示例19: edit_team
def edit_team(self):
''' Edits the team object '''
try:
team = Team.by_uuid(self.get_argument('uuid', ''))
if team is None:
raise ValidationError("Team does not exist")
team.name = self.get_argument('name', team.name)
team.motto = self.get_argument('motto', team.motto)
team.money = self.get_argument('money', team.money)
self.dbsession.add(team)
self.dbsession.commit()
self.redirect('/admin/users')
except ValidationError as error:
self.render('admin/view/users.html',
errors=[str(error), ]
)
开发者ID:WeiEast,项目名称:RootTheBox,代码行数:16,代码来源:AdminUserHandlers.py
示例20: edit_user
def edit_user(self):
''' Update user objects in the database '''
try:
user = User.by_uuid(self.get_argument('uuid', ''))
if user is None:
raise ValidationError("User does not exist")
handle = self.get_argument('handle', '')
if user.handle != handle:
if User.by_handle(handle) is None:
logging.info("Updated user handle %s -> %s" % (
user.handle, handle
))
user.handle = handle
else:
raise ValidationError("Handle is already in use")
hash_algorithm = self.get_argument('hash_algorithm', '')
if hash_algorithm != user.algorithm:
if hash_algorithm in user.algorithms:
if 0 < len(self.get_argument('bank_password', '')):
logging.info("Updated %s's hashing algorithm %s -> %s" % (
user.handle, user.algorithm, hash_algorithm,
))
user.algorithm = hash_algorithm
else:
raise ValidationError(
"You must provide a new bank password when updating the hashing algorithm")
else:
raise ValidationError("Not a valid hash algorithm")
user.password = self.get_argument('password', '')
if len(self.get_argument('bank_password', '')):
user.bank_password = self.get_argument('bank_password', '')
team = Team.by_uuid(self.get_argument('team_uuid', ''))
if team is not None:
if user not in team.members:
logging.info("Updated %s's team %s -> %s" % (
user.handle, user.team_id, team.name
))
user.team_id = team.id
else:
raise ValidationError("Team does not exist in database")
self.dbsession.add(user)
self.dbsession.commit()
self.redirect('/admin/users')
except ValidationError as error:
self.render("admin/view/users.html",
errors=[str(error), ]
)
开发者ID:WeiEast,项目名称:RootTheBox,代码行数:47,代码来源:AdminUserHandlers.py
注:本文中的models.Team.Team类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论