示例#1
0
    def force_turn(self):
        user = getUser()
        world = worlds.get(user.wid)

        country: Country = countries.get(world.current, world.wid)
        world_countries = world.countries
        dict_countries = OrderedDict((c.iso, c) for c in world_countries)

        if not country:
            # ???
            return

        try:
            round_end_events = turns.end_turn(world, country, dict_countries)
        except turns.TurnException as e:
            return {"err": e.reason}
        except turns.EndGameException as e:
            # fake end game: used for playtesting
            # we don't schedule the world to be deleted and don't give ratings
            return ApiResponse({
                "route": "Game:end_game",
                "winner": e.reason
            })

        worlds.save(world)

        return ApiResponse({
            "route": "Game:end_turn",
            "iso": country.iso,
            "turn_end": {
                "turns": world.turns,
                "current": world.current,
            },
            "round_end": round_end_events.to_dict() if round_end_events else None
        })
示例#2
0
    def reset(self):
        user = getUser()
        world = worlds.get(user.wid)

        reset_world(world)

        return ApiResponse({})
示例#3
0
    def debug(self):
        user = getUser()
        if user.wid:
            world = worlds.get(user.wid)
        else:
            world = None

        return render_template('/client/debug.html',
                               conf=settings._conf,
                               world=world,
                               err=request.args.get('err'))
示例#4
0
    def history(self):
        user = getUser()

        if user.username is None:
            return redirect('/')

        l_histories = histories.list_results_user(user.uid)

        return render_template('/worlds/history.html',
                               histories=[(h.to_dict(), r.to_dict())
                                          for h, r in l_histories],
                               err=request.args.get('err'))
示例#5
0
    def get_index(self, wid=None):
        user = getUser()

        if user.username is None:
            return redirect('/')

        if user.uid == 'None':
            raise Exception("hifga iiii Volume II")

        return render_template('/worlds/index.html',
                               wid=wid,
                               conf=settings._conf)
示例#6
0
    def index(self):
        user = getUser()

        if user.uid == 'None':
            raise Exception("hifga i eeeeeeeeeeeeeeeeeeeee")

        if not user.wid:
            return redirect('/client/welcome')
        world = worlds.get(user.wid)

        return render_template('/client/index.html',
                               conf=settings._conf,
                               world=world,
                               err=request.args.get('err'))
示例#7
0
    def new_world(self):
        user = getUser()

        if not user.username:
            return "Login first"

        world = World(name="Test world", map='hu_test', max_rounds=None)
        worlds.save(world)

        start_world(world, AI=True)

        user.wid = world.wid
        user.iso = 'UK'
        users.save(world)

        return 'New world created: {}'.format(world.wid)
示例#8
0
    def load(self):
        user = getUser()

        world = worlds.get(user.wid)
        players = users.list_all(user.wid)
        _countries = world.countries
        _areas = world.areas

        return ApiResponse({
            "world": world.to_dict(),
            "countries": _countries,
            "areas": _areas,
            "players":
            {player.iso: player.to_game_view()
             for player in players},
        })
示例#9
0
    def purge(self):
        # exclude our dear admin
        user = getUser()
        obo = users.find_user(username='******')

        if obo.uid != user.uid:
            return 'No rights'

        users.set_world(obo.uid, None, None)

        # delete all test users
        lworlds = worlds.list_all()

        for world in lworlds:
            worlds.delete(world)

        # delete all entities
        users.delete_all_test()
        histories.delete_all()

        return 'Purged everything :)'
示例#10
0
    def welcome(self):
        user = getUser()

        return render_template('/client/welcome.html',
                               debug=True,
                               err=request.args.get('err'))