示例#1
0
    def get(self, progress):
        self._current_user = self.require_login()
        if not self._current_user:
            self.response.out.write(json.dumps({"error": "please log in"}))
            return

        match = getCurrentMatchByUser(self._current_user.id)
        if not match:
            self.response.out.write(json.dumps({"error": "couldn't find current match"}))
            return

            
        #Update the match data
        userindex = match.users.index(self._current_user.id)
        
        #Add food at the halfway point
        if ((match.outcome[userindex] < 50) and (int(progress) >= 50) and int(progress) > match.outcome[userindex]):
            in_stock = match.food_stockpile 
            MAX_STOCK = [3, 4, 2]
            
            match.food_stockpile = [random.randint(in_stock[0], MAX_STOCK[0]),
                                    random.randint(in_stock[1], MAX_STOCK[1]),
                                    random.randint(in_stock[2], MAX_STOCK[2])]
            broadcast(match, json.dumps({"food": match.food_stockpile}))
        
        
        match.outcome[userindex] = int(progress)
        match.put()

        #Notify all participating users
        broadcast(match, json.dumps({"progress": match.outcome}))

        self.response.out.write(json.dumps({"success": "node completed"}))
示例#2
0
    def get(self, food):
        self._current_user = self.require_login()
        if not self._current_user:
            self.response.out.write(json.dumps({"error": "please log in"}))
            return

        match = getCurrentMatchByUser(self._current_user.id)
        if not match:
            self.response.out.write(json.dumps({"error": "couldn't find current match"}))
            return
        
        foodIndex = ["pizza", "soda", "coffee"].index(food)
        
        if (match.food_stockpile[foodIndex] > 0):
            match.food_stockpile[foodIndex] -= 1
            match.put()
            self.response.out.write(json.dumps({"success": food}))
            broadcast(match, json.dumps({"food": match.food_stockpile}))
        else:
            self.response.out.write(json.dumps({"error": "this food not available"}))
示例#3
0
    def get(self):
        self._current_user = self.require_login()
        if not self._current_user:
            self.response.out.write(json.dumps({"error": "please log in"}))
            return

        q = Queue.all().get()
        if not q:
            q = Queue()

        #Push onto queue
        if str(self._current_user.id) in q.users:
            self.response.out.write(json.dumps({"success": "already in queue"}))
        elif len(q.users) == 0:
            q.users = [self._current_user.id]
            self.response.out.write(json.dumps({"success": "added to queue"}))
        else: #Found a match. Pop & Serve
            matched = q.users[0]
            q.users = q.users[1:]

            #Randomly choose a project
            projects = Project.all().fetch(1000)
            random.seed()
            project = random.choice(projects)

            #Actually create the match
            match = Match(project_id = str(project.key()),
                          users = [self._current_user.id, matched],
                          outcome = [0, 0])

            hackers = Hacker.all().filter("user IN", match.users).fetch(8)
            match.hacker_list = []
            for hacker in hackers:
                match.hacker_list.append(str(hacker.key()))

            match.put()

            #Notify the users via socket
            broadcast(match, json.dumps({"success": "match found"}))
            self.response.out.write("herp")
        q.put()
示例#4
0
    def get(self):
        self._current_user = self.require_login()
        if not self._current_user:
            self.response.out.write(json.dumps({"error": "please log in"}))
            return

        match = getCurrentMatchByUser(self._current_user.id)
        if not match:
            self.response.out.write(json.dumps({"error": "couldn't find current match"}))
            return
            
        in_stock = match.food_stockpile 
        MAX_STOCK = [3, 4, 2]
        
        match.food_stockpile = [random.randint(in_stock[0], MAX_STOCK[0]),
                                random.randint(in_stock[1], MAX_STOCK[1]),
                                random.randint(in_stock[2], MAX_STOCK[2])]
        match.put()
        
        broadcast(match, json.dumps({"food": match.food_stockpile}))
        self.response.out.write(json.dumps({"success": "food added"}))