def send_message(self, message): """Sends a message to the peer represented by the Peer object""" sent_bytes = self._socket.send(message.serialize()) logging.info('%s - sent %d bytes' % (message.payload.payload_type, sent_bytes))
def _reply(self, message): reply = message.serialize() if self.server.debug: print "Sent: {}".format(reply.strip()) self.wfile.write(reply)
team = args.team name = args.name # TODO: This should use $PS2 prompt = 'all > ' dest = 'all' # Start listening for responses from the server. response_handler = ResponseHandler(sock) response_thread = threading.Thread(target=response_handler.serve_forever) response_thread.daemon = True response_thread.start() # Try-block to ensure socket gets closed even if something goes wrong. try: # Send client information to the server. sock.sendall(serialize(name, team, name, '/open')) # Get the first line of input. line = input(prompt) while line != '/quit': # Catch any command messages. if line.startswith('/'): if re.match('/channel (.+)', line): dest = re.match('/channel (.+)', line).group(1) prompt = '{} > '.format(dest) elif re.match('/drop (.+)', line): drop_message = re.match('/drop (.+)', line).group(1) response_handler.drop = serialize(name, team, dest, '/drop {}'.format(drop_message)) elif re.match('/effect (.+) (.*)', line):
# Get the first line of input. prompt = '{}:{} > '.format(ip, port) line = input(prompt) while line != 'quit': # Print currently connected clients. if line == 'clients': logger.info(server.connections) # Print current wiretaps. elif line == 'wiretaps': logger.info(server.wiretaps) # Send dead drop. elif line == 'drop': logger.info('Sending any dead drops.') server.send_to_group(serialize('server', 'server', 'all', '/drop'), server.russians.union(server.americans)) # Radio jamming. elif line == 'radiojamming': logger.info('Radio Jamming used.') # Unknown command. else: logger.info('Unknown command: {}'.format(line)) # Get the next line of input. line = input(prompt) # Cleanup once we're done. server.shutdown()