Beispiel #1
0
 def main_conversation(self):
     while True:
         print('\n\n\n', MAIN_MENU)
         opt = input('choose an option: ')
         my_send(self.client_send, opt.encode())
         if opt == '1':
             print(
                 f"Your pass: {my_receive(self.client_recv, 1024).decode()}"
             )
         elif opt == '3':
             response = my_receive(self.client_recv, 1024).decode()
             print(response)
             if "ok" in response:
                 HostClient(self.client_send, self.client_recv).host_mode()
         elif opt == '4':
             password = my_receive(self.client_recv, 1024).decode()
             if password != "-1":
                 print(f"Your password is {password}")
             else:
                 print("You must be a host")
         elif opt == '5':
             break
         elif 'connect' in opt:
             response = my_receive(self.client_recv, 1024).decode()
             if response == 'ok':
                 print("Wait for host to start the conversation")
                 ViewerClient(self.client_send,
                              self.client_recv).viewer_mode()
                 continue
             else:
                 print(response)
         input('press any key to continue...')
Beispiel #2
0
 def see_screen(self):
     global STOP
     os.environ['SDL_VIDEO_CENTERED'] = '1'
     pygame.init()
     while True:
         total_data = b''
         settings = my_receive(self.recv_socket, con.SPECIAL_BUFFER_SIZE)
         mode, length, x, y = settings.split(b", ")
         y, data = y.split(b")")
         size = int(x[1:-1].decode()), int(y[1:-1].decode())
         length = int(length[1:-1].decode())
         mode = mode[2:-1].decode()
         if data:
             length -= len(data)
             total_data += data
         while length > 0:
             data = my_receive(self.recv_socket, length)
             length -= len(data)
             total_data += data
         if length < 0:
             total_data = total_data[:length]
         image = pygame.image.fromstring(total_data, size, mode)
         display_surface = pygame.display.set_mode(image.get_size())
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 pygame.quit()
                 STOP = True
                 my_send(self.send_socket, "STOP".encode())
                 break
         else:
             display_surface.blit(image, (0, 0))
             pygame.display.update()
             continue
         break
Beispiel #3
0
 def on_scroll(self, x, y, dx, dy):
     if pygame.display.get_active():
         try:
             my_send(self.client_socket,
                     f"scroll {dx * 10} {dy * 10},".encode())
         except OSError:
             return False
Beispiel #4
0
 def on_move(self, x, y):
     try:
         x, y = pygame.mouse.get_pos()
     except Exception:
         pass
     try:
         my_send(self.client_socket, f"pos {x} {y},".encode())
     except OSError:
         return False
Beispiel #5
0
 def on_press(self, key):
     if pygame.display.get_active():
         if "." in str(key):
             key = str(key).split(".")[1]
         else:
             key = str(key)[1:-1]
         try:
             my_send(self.client_socket, f"press {key},".encode())
         except ConnectionResetError:
             return False
Beispiel #6
0
 def on_click(self, x, y, button, pressed):
     try:
         x, y = pygame.mouse.get_pos()
     except Exception:
         pass
     try:
         if pressed:
             my_send(self.client_socket,
                     f"click {x} {y} {convert_button(button)},".encode())
         else:
             my_send(
                 self.client_socket,
                 f"release mouse {x} {y} {convert_button(button)},".encode(
                 ))
     except OSError:
         return False