def on_search_for_rebus(self): client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.search_for_rebus.SetInParent() client_to_server.search_for_rebus.dummy = 0; self.server_connection.send_message_to_server(client_to_server) self.rebus_button["text"] = "Letar efter rebus" self.rebus_button["state"] = "disabled"
def run(self): while not self.terminate: try: data, addr = self.udp_sock.recvfrom(65536) # print("Received data to proxy: {0}".format(data)) size = int.from_bytes(data[0:4], "big") if len(data) != size + 4: print("Invalid subprocess data: {0}".format(data)) continue # Send message on to the server # TODO: not really needed that we unpack the message and then pack it again... client_to_server = clientprotocol_pb2.ClientToServer() unpack_result = client_to_server.ParseFromString(data[4:]) if unpack_result > 0: if client_to_server.HasField("sub_client_register"): # TODO: mutex? print("Subclient {0} registered".format( client_to_server.sub_client_register.udp_port)) self.clients.append( client_to_server.sub_client_register.udp_port) else: self.server_connection.send_message_to_server( client_to_server) except socket.timeout: continue except (ConnectionResetError, ConnectionAbortedError): print("Lost connection to a sub process") continue except Exception as e: print("Sub process communications error: {0}".format(e)) continue
def send_rebus_answer(section, answer): global args client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.counter = args.client_index client_to_server.set_rebus_answer.SetInParent() client_to_server.set_rebus_answer.section = section client_to_server.set_rebus_answer.answer = answer sub_client_communicator.send(client_to_server)
def on_placing_cb_changed(self, data): position_value = self.positions_map[self.combo_select_seating.get()] #global server_connection client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.select_seat.SetInParent() client_to_server.select_seat.user_id = self.server_connection.status_information.user_id client_to_server.select_seat.seat_index = position_value # print("Send message") self.server_connection.send_message_to_server(client_to_server)
def send_rebus_answer(section, answer, east, north): global args my_answers[section] = MyAnswer(answer, east, north) client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.counter = args.client_index client_to_server.test_rebus_solution.SetInParent() client_to_server.test_rebus_solution.section = section; client_to_server.test_rebus_solution.answer = answer; client_to_server.test_rebus_solution.map_east = east; client_to_server.test_rebus_solution.map_north = north; sub_client_communicator.send(client_to_server)
def request_a_solution(self, section, rebus_type): global args client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.counter = args.client_index client_to_server.open_rebus_solution.SetInParent() client_to_server.open_rebus_solution.user_id = args.user_id client_to_server.open_rebus_solution.section = section if rebus_type == Rebus.HELP: client_to_server.open_rebus_solution.open_help = True else: client_to_server.open_rebus_solution.open_solution = True self.sub_client_communicator.send(client_to_server)
def run(self): # Register with the client client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.counter = 0 client_to_server.sub_client_register.SetInParent() client_to_server.sub_client_register.udp_port = self.receive_port client_to_server.sub_client_register.client_index = self.client_index self.send(client_to_server) while not self.terminate: try: data, addr = self.udp_sock.recvfrom(65536) #print("Received data to sub client {1}: {0}".format(data, self.client_index)) size = int.from_bytes(data[0:4], "big") if len(data) != size + 4: print("Invalid subprocess data: {0}".format(data)) continue server_to_client = clientprotocol_pb2.ServerToClient() unpack_result = server_to_client.ParseFromString(data[4:]) if unpack_result > 0: if self.raw_receiver is not None: self.raw_receiver(server_to_client) if server_to_client.HasField("status_update"): if self.status_information is not None: self.status_information.update_status( server_to_client.status_update) if self.receiver is not None: self.receiver(self.status_information) if server_to_client.HasField("status_update"): if server_to_client.status_update.HasField( "pos_update"): if self.raw_pos_receiver is not None: self.raw_pos_receiver( server_to_client.status_update. pos_update) if self.pos_receiver is not None: self.pos_receiver(self.status_information) if self.raw_status_receiver is not None: self.raw_status_receiver( server_to_client.status_update) if self.status_receiver is not None: self.status_receiver(self.status_information) except socket.timeout: continue except (ConnectionResetError, ConnectionAbortedError): print("Subclient: Lost connection to a the rally client") continue except Exception as e: print("Subclient communications error: {0}".format(e)) continue
def send_to_client(self): if not self.connected: self.window.after(1000, self.send_to_client) return client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.counter = self.my_client_index client_to_server.pos_update.SetInParent() client_to_server.pos_update.speed = self.speed client_to_server.pos_update.delta_distance = self.accumulated_movement self.accumulated_movement = 0.0 client_to_server.pos_update.current_section = self.current_section client_to_server.pos_update.indicator = self.indicator_light self.sub_client_communicator.send(client_to_server) self.window.after(1000, self.send_to_client)
def look_for_rebus(self): if self.team.which_rebus == 5 or self.team.which_rebus == 9: print("Workaround for lunch") self.team.which_rebus = 5 self.team.phase = Team.SOLVING_REBUS return client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.search_for_rebus.SetInParent() client_to_server.search_for_rebus.dummy = 0; self.send_message_to_server(client_to_server) #rc = self.server_configuration.get_rebus_config(self.team.which_rebus) while not self.terminate: sleep(1) txt, extra = self.status_information.rebus_statuses.get_rebus_number(self.team.which_rebus).get_text(RebusConfig.NORMAL) if txt is not None: print("Got rebus text: {0}".format(txt)) self.team.solve_rebus(self.team.which_rebus) break
def solve_rebus(self): rc = self.server_configuration.get_rebus_config(self.team.which_rebus) client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.test_rebus_solution.SetInParent() client_to_server.test_rebus_solution.section = rc.section; client_to_server.test_rebus_solution.answer = rc.solution; client_to_server.test_rebus_solution.map_east = rc.east; client_to_server.test_rebus_solution.map_north = rc.north; self.send_message_to_server(client_to_server) while not self.terminate: sleep(1) if self.team.which_rebus in self.status_information.rebus_solutions: rs = self.status_information.rebus_solutions[self.team.which_rebus] #print(rs) if rs.target_east > 0 and rs.target_north > 0: print("Solved the rebus!") self.team.drive_to_next_rebus_checkpoint() return
def perform_driving(self): while not self.terminate and self.status_information is None: sleep(1) wait_frame = 0 wait_section = 0 while not self.terminate: sleep(1) indicator = clientprotocol_pb2.ClientPositionUpdate.NONE track_information = self.server_configuration.track_information section_obj = track_information.get_section(self.status_information.current_section) if section_obj is not None: turn = section_obj.get_correct_turn() if turn is not None: indicator = turn.direction if len(section_obj.rebus_places) > 0: current_frame = section_obj.calculate_default_video_frame_from_distance(self.status_information.distance) if self.status_information.current_section > wait_section or current_frame > wait_frame: for rebus_place in section_obj.rebus_places: if rebus_place.is_close_to(current_frame): wait_frame = current_frame + 300 wait_section = self.status_information.current_section team.search_for_rebus_checkpoint(rebus_place.number) break if team.phase == Team.DRIVING: speed = self.rand_speed / 3.6 else: speed = 0.0 delta_distance = speed * 1.0 client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.pos_update.SetInParent() client_to_server.pos_update.speed = speed client_to_server.pos_update.delta_distance = delta_distance client_to_server.pos_update.current_section = 0 # TODO: is this used? Should it be removed? client_to_server.pos_update.indicator = indicator self.send_message_to_server(client_to_server)
def run(self): self.main_server.send_all_messages_to_client(self) server_to_client = clientprotocol_pb2.ServerToClient() for txt in self.main_server.rally_configuration.start_messages: server_to_client.broadcast_message.SetInParent() welcome_message = server_to_client.broadcast_message welcome_message.message = txt welcome_message.date_time = datetime.datetime.now().strftime( "%Y-%m-%d, %H:%M:%S") self.send(server_to_client) while not self.terminate: success, size_bytes = self._receive_data(4) if not success: break size = int.from_bytes(size_bytes[0:4], "big") if size <= 0: print("Error in communications, size: {0}".format(size)) break success, data = self._receive_data(size) if not success: print("{0} disconnected from {1}".format( self.username, self.team_server.teamname)) break try: client_to_server = clientprotocol_pb2.ClientToServer() unpack_result = client_to_server.ParseFromString(data) if unpack_result > 0: if client_to_server.HasField("select_seat"): self.team_server.select_seat( client_to_server.select_seat) if client_to_server.HasField("pos_update"): self.team_server.update_pos_from_driver( client_to_server.pos_update) if client_to_server.HasField("open_rebus_solution"): self.team_server.open_rebus_solution( client_to_server.open_rebus_solution) if client_to_server.HasField("set_photo_answer"): self.team_server.set_photo_answer( client_to_server.set_photo_answer) if client_to_server.HasField("set_plate_answer"): self.team_server.set_plate_answer( client_to_server.set_plate_answer) if client_to_server.HasField("set_rebus_answer"): self.team_server.set_rebus_answer( client_to_server.set_rebus_answer) if client_to_server.HasField("search_for_rebus"): self.team_server.search_for_rebus() if client_to_server.HasField("test_rebus_solution"): self.team_server.test_rebus_solution( client_to_server.test_rebus_solution) if client_to_server.HasField("open_extra_puzzle"): self.team_server.open_extra_puzzle( client_to_server.open_extra_puzzle) except google.protobuf.message.DecodeError as e: print("Incorrect message from {0} disconnected from {1}: {2}". format(self.username, self.team_server.teamname, e)) break except Exception as e: print( "Unknown error in communication from {0} disconnected from {1}: {2}" .format(self.username, self.team_server.teamname, e)) break self.terminate = True # We exited the loop, so might as well set terminate to true self._remove_client() self.connection = None self.main_server = None
def send_request_to_open(self, extra_puzzle): client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.counter = self.client_index client_to_server.open_extra_puzzle.SetInParent() client_to_server.open_extra_puzzle.puzzle_id = extra_puzzle.id self.sub_client_communicator.send(client_to_server)
def select_seat(self): client_to_server = clientprotocol_pb2.ClientToServer() client_to_server.select_seat.SetInParent() client_to_server.select_seat.user_id = self.user_id client_to_server.select_seat.seat_index = self.role_in_bus self.send_message_to_server(client_to_server)