Esempio n. 1
0
def register():
    response.loginmenu = [(T("Login/Register"), URL("default", "user") == URL(), URL("default", "user"), [])]
    playermgmt.ensure_session_vars(auth, inreguser=True)
    # If the user has already registered, forward user to user the index page
    if current.session.playerid != None:
        http.redirect(html.URL("default", "index"))
    return dict()
Esempio n. 2
0
def ingame():
    playermgmt.ensure_session_vars(auth)
    try:
        return {"game_id": request.vars.game_id,
                "websocket_server": config.websocket_server}
    except AttributeError:
        pass
    return dict()
Esempio n. 3
0
def check_groupname():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ["json"]

    try:
        return {"free": playermgmt.is_groupname_free(request.vars.name)}
    except:
        return {"free": False}
Esempio n. 4
0
def active_playgroup():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']

    try:
        playermgmt.set_active_playgroup(int(request.vars.group))
    except:
        pass

    return dict()
Esempio n. 5
0
def list_games():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']

    amount = None

    try:
        amount = int(request.vars.amount)
    except:
        pass
    return {"games": game.list_games(amount)}
Esempio n. 6
0
def filter():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']
    
    try:
        filters = gluon.contrib.simplejson.loads(request.body.read())
        games = game.get_games_for_stats(filters)
        stats = game.get_stats(games)
        stats["games"] = games
        return stats
    except:
        raise HTTP(403)
Esempio n. 7
0
def update_game_info():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']
    
    update_fields = gluon.contrib.simplejson.loads(request.body.read())
    changed = game.update_game(request.vars.game_id, update_fields)
    websocket_send("http://" + config.websocket_server,
                   gluon.contrib.simplejson.dumps(changed),
                   config.websocket_key,
                   str(request.vars.game_id))


    return dict()
Esempio n. 8
0
def create_user():
    playermgmt.ensure_session_vars(auth, inreguser=True)
    response.generic_patterns = ["json"]

    try:
        playername = gluon.contrib.simplejson.loads(request.body.read())["playername"]

        if playername != None and playername != "":
            playermgmt.register_player(auth, playername)
            return {}
        else:
            raise HTTP(403)
    except:
        raise HTTP(403)
Esempio n. 9
0
def end_game():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']
    wininfo = gluon.contrib.simplejson.loads(request.body.read())

    try:
        saveid = game.end_game(request.vars.game_id, wininfo)
        websocket_send("http://" + config.websocket_server, 
                       gluon.contrib.simplejson.dumps(
                            {"gameFinished": True}),
                            config.websocket_key,
                            str(request.vars.game_id))
        return {"saveid": saveid}  
    #except game.storeGameException as e:
    except e:
        pass
Esempio n. 10
0
def discard_game():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']
    game.discard_game(request.vars.game_id)
    return dict()
Esempio n. 11
0
def get_game_state():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']

    return game.get_ongoing_game(request.vars.game_id)
Esempio n. 12
0
def get_deck_names():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']

    return {'decks': [deck["name"] for deck in 
                      deckmgmt.list_decks(player_only=False)]}
Esempio n. 13
0
def list_ongoing_games():
    playermgmt.ensure_session_vars(auth)
    response.generic_patterns = ['json']

    return {"games": game.list_ongoing_games()}
Esempio n. 14
0
def index():
    playermgmt.ensure_session_vars(auth)

    return dict()
Esempio n. 15
0
def newgame():
    playermgmt.ensure_session_vars(auth)

    if "copy" in request.vars:
        # copy a previous game
        try:
            game_id = game.create_game(copyfrom=int(request.vars["copy"]))
            redirect(URL("ingame", "ingame", vars=dict(game_id=game_id)))
        except (ValueError, game.NewGameException):
            pass

    formgame = SQLFORM.factory(
        Field("gametype", requires=IS_IN_SET(game.GAMETYPES, zero=None)),
        Field("players", requires=IS_IN_SET(["2", "3", "4", "5", "6"], zero=None)),
        Field("format", requires=IS_IN_SET(game.FORMATS, zero=None)),
        Field("tags"),
        Field("player1"),
        Field("player2"),
        Field("player3"),
        Field("player4"),
        Field("player5"),
        Field("player6"),
        formstyle="divs",
        submit_button="Start",
    )

    if formgame.process().accepted:
        try:
            playeramount = int(formgame.vars.players)
            players = []

            if playeramount not in game.PLAYERAMOUNTS.get(formgame.vars.gametype, []):
                raise game.NewGameException("Wrong amount of players for the format")

            for i in range(1, playeramount + 1):
                try:
                    playerid = int(formgame.vars["player" + str(i)])
                except ValueError:
                    raise game.NewGameException("Invalid player id")
                if playerid == None:
                    raise game.NewGameException("Please insert player " + str(i))
                else:
                    addplayer = [player for player in session.groupplayers if player["id"] == playerid]
                    if len(addplayer) != 0:
                        players.append(addplayer[0])
                    elif playerid == session.guestplayer["id"]:
                        players.append(session.guestplayer)
                    else:
                        raise game.NewGameException("Player not found")

            gamedata = dict(formgame.vars)
            tags = gamedata["tags"]
            gamedata["tags"] = tags.replace(",", " ").strip()
            gamedata["players"] = players
            gamedata["playeramount"] = playeramount

            game_id = game.create_game(gamedata)
            redirect(URL("ingame", "ingame", vars=dict(game_id=game_id)))
        except game.NewGameException as nge:
            if nge.message:
                response.flash = nge.message

    elif formgame.errors:
        response.flash = "form has errors"

    return dict(
        formgame=formgame, playerlist=session.groupplayers, guestplayer=session.guestplayer, tags=game.get_recent_tags()
    )
Esempio n. 16
0
def stats():
    playermgmt.ensure_session_vars(auth)
    return {"decks": deckmgmt.list_decks(player_only=False)}