def __init__(self, localClient): Thread.__init__(self) self.localClient = localClient self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connected = False self.parser = PacketParser()
def __init__(self, fd, addr, ip, port): Thread.__init__(self) self.fd = fd self.addr = addr self.ip = ip self.port = port self.connected = False self.parser = PacketParser()
def __init__(self, serverIp, serverPort): Thread.__init__(self) self.listeningSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.listeningSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.serverIp = serverIp self.serverPort = serverPort self.connected = False self.parser = PacketParser()
class GameRemoteClient(Thread): def __init__(self, localClient, serverIp, serverPort): Thread.__init__(self) self.localClient = localClient self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.serverIp = serverIp self.serverPort = serverPort self.connected = False self.parser = PacketParser() def send(self, data): if self.connected: self.socket.sendall(data) return True return False def processPackets(self): newPacket = self.parser.getPacket() while newPacket: Logger.debug("[GAME] << " + newPacket) DatabaseManager().addPacket(0, newPacket) data = bytearray(newPacket.encode("utf-8")) data += b'\x00' if self.localClient.send(data) == False: self.socket.close() Logger.info("[GAME] Server disconnected") return (False) newPacket = self.parser.getPacket() return (True) def run(self): self.socket.connect((self.serverIp, self.serverPort)) self.connected = True recvData = self.socket.recv(4096) while recvData: self.parser.feed(recvData) if self.processPackets() == False: return (False) recvData = self.socket.recv(4096) self.connected = False Logger.info("[GAME] Server disconnected")
class RealmLocalClient(Thread): def __init__(self, fd, addr, ip, port): Thread.__init__(self) self.fd = fd self.addr = addr self.ip = ip self.port = port self.connected = False self.parser = PacketParser() def send(self, data): if self.connected: self.fd.sendall(data) return True return False def processPackets(self): newPacket = self.parser.getPacket() while newPacket: Logger.debug("[REALM] >> " + newPacket) DatabaseManager().addPacket(1, newPacket) data = bytearray(newPacket.encode("utf-8")) data += b'\x00' if self.remoteServer.send(data) == False: self.fd.close() Logger.info("[REALM] Client " + self.ip + ":" + self.port + " disconnected") return (False) newPacket = self.parser.getPacket() return (True) def run(self): self.connected = True self.remoteServer = RealmRemoteClient(self) self.remoteServer.start() recvData = self.fd.recv(4096) while recvData: self.parser.feed(recvData) if self.processPackets() == False: return (False) recvData = self.fd.recv(4096) self.connected = False Logger.info("[REALM] Client " + self.ip + ":" + self.port + " disconnected")
class GameLocalClient(Thread): def __init__(self, serverIp, serverPort): Thread.__init__(self) self.listeningSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.listeningSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.serverIp = serverIp self.serverPort = serverPort self.connected = False self.parser = PacketParser() def getListeningIp(self): return (self.listeningSocket.getsockname()[0]) def getListeningPort(self): return (self.listeningSocket.getsockname()[1]) def listen(self): try: self.listeningSocket.bind(("127.0.0.1", 0)) except socket.error as msg: Logger.error('[GAME] Bind failed. Error : ' + str(sys.exc_info())) return (False) self.listeningSocket.listen(1) def send(self, data): if self.connected: self.fd.sendall(data) return True return False def processPackets(self): newPacket = self.parser.getPacket() while newPacket: Logger.debug("[GAME] >> " + newPacket) DatabaseManager().addPacket(1, newPacket) data = bytearray(newPacket.encode("utf-8")) data += b'\x00' if self.remoteServer.send(data) == False: self.fd.close() Logger.info("[GAME] Client " + self.ip + ":" + self.port + " disconnected") return (False) newPacket = self.parser.getPacket() return (True) def run(self): Logger.info("[GAME] Listening on " + self.getListeningIp() + ":" + str(self.getListeningPort()) + "...") self.fd, self.addr = self.listeningSocket.accept() self.ip, self.port = str(self.addr[0]), str(self.addr[1]) Logger.info('[GAME] New incomming connection: ' + self.ip + ':' + self.port) self.listeningSocket.close() self.connected = True self.remoteServer = GameRemoteClient(self, self.serverIp, self.serverPort) self.remoteServer.start() recvData = self.fd.recv(4096) while recvData: self.parser.feed(recvData) if self.processPackets() == False: return (False) recvData = self.fd.recv(4096) self.connected = False Logger.info("[GAME] Client " + self.ip + ":" + self.port + " disconnected")
class RealmRemoteClient(Thread): def __init__(self, localClient): Thread.__init__(self) self.localClient = localClient self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connected = False self.parser = PacketParser() def send(self, data): if self.connected: self.socket.sendall(data) return True return False def parsePacket(self, packet): if len(packet) > 3 and packet[0] == 'A' and packet[ 1] == 'X' and packet[2] == 'K': Logger.debug("[REALM] onSelectServer packet detected!") encryptedIp = packet[3:11] encryptedPort = packet[11:14] ticket = packet[14:] decryptedIp = CipherManager.decryptIp(encryptedIp) decryptedPort = CipherManager.decryptPort(encryptedPort) newGameClient = GameLocalClient(decryptedIp, decryptedPort) newGameClient.listen() newEncryptedIp = CipherManager.encryptIp( newGameClient.getListeningIp()) newEncryptedPort = CipherManager.encryptPort( newGameClient.getListeningPort()) newPacket = "AXK" + newEncryptedIp + newEncryptedPort + ticket Logger.debug("[REALM] Replacing packet '" + packet + "' with packet '" + newPacket + "'") newGameClient.start() return (newPacket) return (packet) def processPackets(self): newPacket = self.parser.getPacket() while newPacket: Logger.debug("[REALM] << " + newPacket) DatabaseManager().addPacket(0, newPacket) newPacket = self.parsePacket(newPacket) data = bytearray(newPacket.encode("utf-8")) data += b'\x00' if self.localClient.send(data) == False: self.socket.close() Logger.info("[REALM] Server disconnected") return (False) newPacket = self.parser.getPacket() return (True) def run(self): self.socket.connect(("34.251.172.139", 443)) self.connected = True recvData = self.socket.recv(4096) while recvData: self.parser.feed(recvData) if self.processPackets() == False: return (False) recvData = self.socket.recv(4096) self.connected = False Logger.info("[REALM] Server disconnected")