def create_tournament(name = 'Dummy tournament', desc = 'Dummy description', kind = 'settlers', owner = None, engine = 'randomized', password = None, num_players = 12, limit_rounds = 4, limit = 3): gm = games.game_module(kind) tkwargs = { 'name': name, 'desc': desc, 'kind': kind, 'owner': owner, 'engine': engine, 'password': password, 'num_players': num_players, 'limit_rounds': limit_rounds } tflags = tournaments.TournamentCreationFlags(**tkwargs) tflags.owner = hruntime.dbroot.users['User #0'] = DummyUser('User #0') tflags.limit = num_players gkwargs = { 'kind': kind, 'limit': limit } gflags = gm.GameCreationFlags(**gkwargs) gflags.opponents = [] gflags.desc = '' gflags.password = None gflags.owner = None return tournaments.Tournament.create_tournament(tflags, gflags)
def index(self, username = None): if username not in hruntime.dbroot.users: raise hlib.error.NoSuchUserError(username) user = hruntime.dbroot.users[username] gm = games.game_module('settlers', submodule = 'stats') return self.generate('profile.mako', params = {'player': user, 'player_stats': gm.stats.player_stats[user.name] if user.name in gm.stats.player_stats else None})
def prepare_notify_events(self, no_trumpet = False): pn = PullNotify() if not no_trumpet and hruntime.user.seen_board != True: txt = lib.trumpet.Board().text if len(txt) > 0: pn.trumpet = hlib.format.tagize(txt) # Do I have unread posts on global chat? cnt = lib.chat.ChatPagerGlobal().unread if cnt > 0: pn.chat = cnt # Are there any free games? cnt = sum([1 for g in games.f_active(hruntime.user) if g.is_free and not g.is_personal_free(hruntime.user)]) cnt += sum([1 for t in tournaments.f_active(hruntime.user) if t.is_active and not t.has_player(hruntime.user)]) if cnt > 0: pn.free_games = cnt # Am I on turn in any game? cnt = 0 for k in games.GAME_KINDS: cnt += len(games.game_module(k, submodule = 'handler').GameOnTurnChecker.check()) for g in games.f_active(hruntime.user): if g.has_player(hruntime.user): # Am I invited to this game? if not g.has_confirmed_player(hruntime.user): cnt += 1 continue # Do I have undread posts? if g.my_player.chat.unread > 0: cnt += 1 continue # Do I have unread posts in inactive games? cnt += sum([1 for g in games.f_inactive(hruntime.user) if g.my_player.chat.unread > 0]) # Do I have unread posts in tournaments' chat? cnt += sum([1 for t in tournaments.f_active(hruntime.user) if t.has_player(hruntime.user) and t.my_player.chat.unread > 0]) # Do I have unread posts in inactive tournaments? cnt += sum([1 for t in tournaments.f_inactive(hruntime.user) if t.my_player.chat.unread > 0]) if cnt > 0: pn.on_turn = cnt return pn
def do_pass_turn(self, gid, **kwargs): # pylint: disable-msg=E1101 g = require_on_turn(gid) g.pass_turn(**kwargs) if hruntime.user.after_pass_turn == lib.datalayer.User.AFTER_PASS_TURN_STAY: return hlib.api.Reply(200, game = g.to_state()) if hruntime.user.after_pass_turn == lib.datalayer.User.AFTER_PASS_TURN_NEXT: for kind in games.GAME_KINDS: check_result = games.game_module(kind, submodule = 'handler').GameOnTurnChecker.check() if len(check_result) <= 0: continue raise hlib.http.Redirect('/game?gid=' + str(check_result[0].id)) else: raise hlib.http.Redirect('/home/') raise hlib.http.Redirect('/home/')
def new(self, **kwargs): gm = games.game_module(kwargs['kind']) tkwargs = {} for name in tournaments.TournamentCreationFlags.FLAGS: if name in kwargs: tkwargs[name] = kwargs[name] gkwargs = {} for name in gm.GameCreationFlags.FLAGS: if name in kwargs: gkwargs[name] = kwargs[name] tflags = tournaments.TournamentCreationFlags(**tkwargs) tflags.owner = hruntime.user tflags.limit = int(kwargs['num_players']) gflags = gm.GameCreationFlags(**gkwargs) gflags.opponents = [] gflags.desc = '' gflags.password = None gflags.owner = None tournaments.Tournament.create_tournament(tflags, gflags)
def produce(self): games.game_module(self.kind, submodule = 'stats').stats.refresh_stats()