def __create_response(self): message = self.request.get("message") if message == "CONNECT": self.__player_name = self.request["name"] response = ProtoMessage.init_message({ "object1": { "game_type": "/Some/gob_type/from/inventory", "pos": [23, 32], "heading": 54, "health": 100 }, "Player1": { "game_type": "/Ship", "pos": (0, 2), "heading": 0, "health": 58 } }) self.response_created = True return response elif message == "READY": response = ProtoMessage.start_message() self.response_created = True return response elif message == "INPUT": if self.__processed_count < 10: response = ProtoMessage.update_message({ "object1": { "id": 43, "pos": [230, 2], "heading": 5, "health": 30 }, "Player1": { "id": 23, "pos": (120, 2), "heading": 20, "health": 98 } }) else: response = ProtoMessage.stop_message() self.response_created = True return response return None
def propagate_game_state(self, game_state_dict): """Propagates the dictionary that represents game state to all the connected clients.""" message = ProtoMessage.update_message(game_state_dict) for _, client in self.__connected_clients.items(): client.set_game_state_message(message)