Пример #1
0
        def observe_started(self, data):
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            tgtid, pldata = data
            from client.core import PeerPlayer, PlayerList, TheLittleBrother
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            i = pid.index(tgtid)
            g = self.game
            g.players = PlayerList(pl)
            g.me = g.players[i]
            g.me.__class__ = TheLittleBrother
            #g.start()
            log.info('=======OBSERVE STARTED=======')
            log.info(g)

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started', g)
Пример #2
0
        def game_started(self, pldata):
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            from client.core import PeerPlayer, TheChosenOne, PlayerList
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            me = TheChosenOne()
            i = pid.index(me.account.userid)
            pl[i] = me
            g = self.game
            g.me = me
            g.players = PlayerList(pl)
            #g.start()
            log.info('=======GAME STARTED: %d=======' % g.gameid)
            log.info(g)

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started', g)
Пример #3
0
        def observe_started(self, data):
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            tgtid, pldata = data
            from client.core import PeerPlayer, PlayerList, TheLittleBrother
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            i = pid.index(tgtid)
            g = self.game
            g.players = PlayerList(pl)
            g.me = g.players[i]
            g.me.__class__ = TheLittleBrother
            #g.start()
            log.info('=======OBSERVE STARTED=======')
            log.info(g)

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started', g)
Пример #4
0
        def game_started(self, pldata):
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            from client.core import PeerPlayer, TheChosenOne, PlayerList
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            me = TheChosenOne()
            i = pid.index(me.account.userid)
            pl[i] = me
            g = self.game
            g.me = me
            g.players = PlayerList(pl)
            #g.start()
            log.info('=======GAME STARTED: %d=======' % g.gameid)
            log.info(g)

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started', g)
Пример #5
0
    def testChooseOptionInputlet(self):
        from game import autoenv
        from game.autoenv import user_input
        from client.core import TheChosenOne, PeerPlayer

        from thb.thb3v3 import THBattle
        from thb.inputlets import ChooseOptionInputlet
        from utils import BatchList

        autoenv.init('Server')
        g = THBattle()
        g.IS_DEBUG = True
        pl = [create_mock_player([]) for i in xrange(6)]
        p = pl[0]
        g.me = p
        p.client.gdlist.extend([
            ['I:ChooseOption:1', True],
            ['I&:ChooseOption:2', False],
            ['I|:ChooseOption:3', True],
        ])
        p.client.gdevent.set()
        g.players = BatchList(pl)
        hook_game(g)
        g.gr_groups = WeakSet()

        ilet = ChooseOptionInputlet(self, (False, True))

        eq_(user_input([p], ilet), True)
        eq_(user_input([p], ilet, type='all'), {p: False})
        eq_(user_input([p], ilet, type='any'), (p, True))

        for p in pl:
            eq_(p.client.gdhistory, [
                ['RI:ChooseOption:1', True],
                ['RI&:ChooseOption:2', False],
                ['RI|:ChooseOption:3', True],
            ])

        autoenv.init('Client')
        g = THBattle()
        pl = [PeerPlayer() for i in xrange(6)]
        svr = MockConnection([
            ['RI:ChooseOption:1', True],
            ['RI&:ChooseOption:2', False],
            ['RI|:ChooseOption:3', True],
        ])
        p = TheChosenOne(svr)
        pl[0] = p
        g.me = p
        svr.gdevent.set()
        g.players = BatchList(pl)
        hook_game(g)
        assert autoenv.Game.getgame() is g

        ilet = ChooseOptionInputlet(self, (False, True))

        eq_(user_input([p], ilet), True)
        eq_(user_input([p], ilet, type='all'), {p: False})
        eq_(user_input([p], ilet, type='any'), (p, True))
Пример #6
0
    def start_replay(self, rep, event_cb):
        assert self.state == 'initial'

        self.state = 'replay'

        from client.core import PeerPlayer, TheLittleBrother
        from thb import modes

        g = modes[rep.game_mode]()
        self.server = ReplayEndpoint(rep, g)

        pl = [PeerPlayer.parse(i) for i in rep.users]

        g.players = BatchList(pl)
        me = g.players[rep.me_index]
        me.__class__ = TheLittleBrother
        me.server = self.server
        g.me = me
        g.game_params = rep.game_params
        g.game_items = rep.game_items
        log.info('=======REPLAY STARTED=======')

        # g.start()  Starts by UI

        @g.link_exception
        def crash(*a):
            self.state = 'initial'
            event_cb('game_crashed', g)

        @g.link_value
        def finish(*a):
            self.state = 'initial'
            v = g.get()
            if not isinstance(v, ForcedKill):
                event_cb('client_game_finished', g)

            event_cb('end_game', g)

        return g
Пример #7
0
    def start_replay(self, rep, event_cb):
        assert self.state == 'initial'

        self.state = 'replay'

        from client.core import PeerPlayer, TheLittleBrother
        from thb import modes

        g = modes[rep.game_mode]()
        self.server = ReplayEndpoint(rep, g)

        pl = [PeerPlayer.parse(i) for i in rep.users]

        g.players = BatchList(pl)
        me = g.players[rep.me_index]
        me.__class__ = TheLittleBrother
        me.server = self.server
        g.me = me
        g.game_params = rep.game_params
        g.game_items = rep.game_items
        log.info('=======REPLAY STARTED=======')

        # g.start()  Starts by UI

        @g.link_exception
        def crash(*a):
            self.state = 'initial'
            event_cb('game_crashed', g)

        @g.link_value
        def finish(*a):
            self.state = 'initial'
            v = g.get()
            if not isinstance(v, ForcedKill):
                event_cb('client_game_finished', g)

            event_cb('end_game', g)

        return g
Пример #8
0
        def game_started(self, data):
            params, items, pldata = data
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            from client.core import PeerPlayer, TheChosenOne
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            me = TheChosenOne(Executive.server)
            me.account = self.account
            i = pid.index(me.account.userid)
            pl[i] = me
            g = self.game
            g.me = me
            g.game_params = params
            g.game_items = items
            g.players = BatchList(pl)
            # g.start()  Starts by UI
            log.info('=======GAME STARTED: %d=======' % g.gameid)
            log.info(g)

            self.last_game_info = params, items, i, pldata

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started',
                          (g, params, items, pldata, g.players[:]))
Пример #9
0
        def observe_started(self, data):
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            params, items, tgtid, pldata = data
            from client.core import PeerPlayer, TheLittleBrother
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            i = pid.index(tgtid)
            self.last_game_info = params, items, i, pldata
            g = self.game
            g.players = BatchList(pl)
            me = g.players[i]
            me.__class__ = TheLittleBrother
            me.server = Executive.server
            g.me = me
            g.game_params = params
            g.game_items = items
            # g.start()  Starts by UI
            log.info('=======OBSERVE STARTED=======')
            log.info(g)

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started',
                          (g, params, items, pldata, g.players[:]))
Пример #10
0
        def game_started(self, data):
            params, items, pldata = data
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            from client.core import PeerPlayer, TheChosenOne
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            me = TheChosenOne(Executive.server)
            me.account = self.account
            i = pid.index(me.account.userid)
            pl[i] = me
            g = self.game
            g.me = me
            g.game_params = params
            g.game_items = items
            g.players = BatchList(pl)
            # g.start()  Starts by UI
            log.info('=======GAME STARTED: %d=======' % g.gameid)
            log.info(g)

            self.last_game_info = params, items, i, pldata

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started', (g, params, items, pldata, g.players[:]))
Пример #11
0
        def observe_started(self, data):
            Executive.server.gclear()
            if self.last_game:
                self.last_game.kill(ForcedKill)
                self.last_game.get()
                self.last_game = None

            params, items, tgtid, pldata = data
            from client.core import PeerPlayer, TheLittleBrother
            pl = [PeerPlayer.parse(i) for i in pldata]
            pid = [i.account.userid for i in pl]
            i = pid.index(tgtid)
            self.last_game_info = params, items, i, pldata
            g = self.game
            g.players = BatchList(pl)
            me = g.players[i]
            me.__class__ = TheLittleBrother
            me.server = Executive.server
            g.me = me
            g.game_params = params
            g.game_items = items
            # g.start()  Starts by UI
            log.info('=======OBSERVE STARTED=======')
            log.info(g)

            @g.link_exception
            def crash(*a):
                self.event_cb('game_crashed', g)

            @g.link_value
            def finish(*a):
                v = g.get()
                if not isinstance(v, ForcedKill):
                    self.event_cb('client_game_finished', g)

            self.event_cb('game_started', (g, params, items, pldata, g.players[:]))
Пример #12
0
data.pop(0)  # seed
data.pop(0)  # server data

loc = options.location
gdlist = json.loads(data.pop(0))[loc]

server = MockServer(gdlist)
Executive = MockExecutive(server)

from client.core import game_client
game_client.Executive = Executive  # Hack

GameMode = modes[mode]
npcs = len(GameMode.npc_players)

players = [PeerPlayer() for i in xrange(GameMode.n_persons + npcs)]
players[loc + npcs].__class__ = TheLittleBrother
players[loc + npcs].server = server

for p in players:
    p.account = Account.authenticate('Proton', '123')

g = GameMode()
g.players = BatchList(players)
g.game_params = params
g.game_items = items
g.me = players[loc + npcs]
g.replay_file = options.replay_file


@hook(g)