Ejemplo n.º 1
0
    def post(self):
        hash = self.request.url.split("/")[3]
        
        if (self.request.get('coordinates')):
            channel.send_message(hash+'tv', self.request.get('coordinates'))
            
        if (self.request.get('playerstop')):
            GS = Game.pull(hash)
            players = GS.players
            randomkeyword = wordlist[ (random.randint(0,len(wordlist)-1)) ]
            GS.currentKeyword = randomkeyword

            if ( GS.currentIndex < GS.totalPlayer - 1):
                GS.currentIndex += 1
            else:
                GS.currentIndex = 0
            
            GS.currentPlayer = players[GS.currentIndex].split("_")[1]
            
            for playerid in players:
                playerstandby = playerid.split("_")[1]
                if( GS.currentPlayer == playerstandby):
                     logging.info("SENDING READY TO "+GS.currentPlayer)
                     channel.send_message(hash + 'mobile' + GS.currentPlayer, CMD.get("PLAYER_READY", GS.currentPlayer, {"keyword":GS.currentKeyword}))
                     channel.send_message(hash + 'tv' , CMD.get("PLAYER_READY", GS.currentPlayer, {}))
                else:
                    channel.send_message(hash + 'mobile' + playerstandby, CMD.get("PLAYER_STOP", playerstandby, {"keyword":randomkeyword}))
            

            Game.push(GS)
Ejemplo n.º 2
0
    def post(self):
        
        hash = self.request.url.split("/")[3]
        player = self.request.url.split("/")[5]

        GS = Game.pull(hash)
        
        if (self.request.get('coordinates')):
            channel.send_message(hash+'tv', CMD.get("DRAW", player, self.request.get("coordinates"))) 

        if (self.request.get('readyAck')):
        # Notify Tv of player connection
            logging.info(GS.currentPlayer)

            if (GS.currentPlayer == player):
                randomkeyword = wordlist[random.randint(0,len(wordlist)-1)]
                GS.currentKeyword = randomkeyword
                channel.send_message(hash + 'tv', CMD.get("PLAYER_READY", player, {}))
               
                # defer sending event to mobile
                time.sleep(0.5)
                channel.send_message(hash + 'mobile' + player, CMD.get("PLAYER_READY", player, {"keyword":randomkeyword}))
                logging.info("SENDING PLAYER READY TO "+player);
                
            else:
                for playerid in GS.players:
                    playerstandby = playerid.split("_")[1]
                    if (not playerstandby == GS.currentPlayer):
                        channel.send_message(hash + 'mobile' + playerstandby, CMD.get("PLAYER_STOP", playerstandby, {"keyword":GS.currentKeyword}))
                        logging.info("SENDING PLAYER STOP TO "+playerstandby);
        if (self.request.get('playerstart')):
            channel.send_message(hash + 'tv', CMD.get("PLAYER_START", player, {}))
            
        if (player != GS.currentPlayer and self.request.get('playerattack')):
            channel.send_message(hash + 'mobile' + GS.currentPlayer, CMD.get("PLAYER_ATTACKED", GS.currentPlayer, {}))
            
        if (self.request.get('playerfound')):
            """players = GS.players
            randomkeyword = wordlist[random.randrange(0,len(wordlist))]
            GS.currentKeyword = randomkeyword
            
            for playerid in players:
                playerstandby = playerid.split("_")[1]
                channel.send_message(hash + 'mobile' + playerstandby, CMD.get("PLAYER_STOP", playerstandby, {"keyword":randomkeyword}))
            
            if ( not GS.currentIndex == GS.totalPlayer - 2):
                GS.currentIndex += 1
            else:
                GS.currentIndex = 0
            
            GS.currentPlayer = players[GS.currentIndex].split("_")[1]"""
            channel.send_message(hash + 'tv', CMD.get("PLAYER_FOUND", player, {}))
            #channel.send_message(hash + 'mobile' + GS.currentPlayer, CMD.get("PLAYER_READY", GS.currentPlayer, {"keyword":GS.currentKeyword}))
        
        Game.push(GS)
Ejemplo n.º 3
0
    def get(self):
        hash = self.request.url.split("/")[3]
        player_str = self.request.url.split("/")[5]
        GS = Game.pull(hash)

        
        if len(GS.players) == 0 or (hash+"_"+player_str) not in GS.players:
            logging.info("creating channel");
            token = channel.create_channel( hash + 'mobile' + player_str,ChannelTimeout)
            
            #Create a player and push it in the DB
            playerDb = Player(key_name = hash + "_" + player_str, player_name = player_str, player_token = token)
            
            GS.players.append(hash+"_"+player_str)
            GS.totalPlayer += 1
            PlayerManager.push(playerDb)
        else:
            logging.info("player already existing, restoring token")
            #TODO : Token are expiring so they shouldn't be stored
            token = PlayerManager.pull( (hash+"_"+player_str) ).player_token
        
        logging.info("____TOKEN "+token)

        if (self.request.get('message')):
            channel.send_message(hash+'tv', self.request.get('message'))
        
        #TODO: update with next version
        if (GS.currentPlayer == "-1"):
            GS.currentPlayer = player_str
        
        Game.push(GS)

        channel.send_message(hash+'tv', CMD.get("JOIN", player_str, {}))
        
        template2handler(self,'mobile','mobile-game.html',{
                                                   'client': 'mobile',
                                                   'title': 'You are the '+player_str+' !',
                                                   'token': token
                                                   })