def pollserver(self, host="localhost", port=None): if port is None: port = self.srv_data.server_port server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # server_sock = socket.socket() server_sock.settimeout(5) server_sock.connect((host, port)) packet = Packet(server_sock, self) packet.send(0x00, "varint|string|ushort|varint", (5, host, port, 1)) packet.send(0x00, "", ()) packet.flush() self.srv_data.protocolVersion = -1 while True: pkid, original = packet.grabpacket() if pkid == 0x00: data = json.loads(packet.read("string:response")["response"]) self.srv_data.protocolVersion = data["version"]["protocol"] self.srv_data.version = data["version"]["name"] if "modinfo" in data and data["modinfo"]["type"] == "FML": self.forge = True self.mod_info["modinfo"] = data["modinfo"] break server_sock.close()
def pollserver(self, host="localhost", port=None): """ Pings server for server json response information. :param host: ip of server :param port: server port. :returns: a list - [protocol, string version name, Forge?(Bool), modinfo (if Forge) ] """ if port is None: port = self.srv_data.server_port server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # server_sock = socket.socket() server_sock.connect((host, port)) packet = Packet(server_sock, self) packet.sendpkt( # 340 is protocol and 1 means "Next State = status" 0x00, [VARINT, STRING, USHORT, VARINT], (340, host, port, STATUS)) # Disconnect packet.sendpkt(0x00, [ NULL, ], [ "", ]) packet.flush() self.srv_data.protocolVersion = -1 container = [] while True: pkid, packet_tuple = packet.grabpacket() if pkid == 0x00: data = json.loads(packet.readpkt([ STRING, ])[0]) container.append(data["version"]["protocol"]) container.append(data["version"]["name"]) if "modinfo" in data and data["modinfo"]["type"] == "FML": container.append(True) container.append(data["modinfo"]) else: container.append(False) break server_sock.close() return container
def pollserver(self, host="localhost", port=None): if port is None: port = self.srv_data.server_port server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # server_sock = socket.socket() server_sock.connect((host, port)) packet = Packet(server_sock, self) packet.sendpkt( # 340 is protocol and 1 means "Next State = status" 0x00, [VARINT, STRING, USHORT, VARINT], (340, host, port, STATUS)) # Disconnect packet.sendpkt(0x00, [ NULL, ], [ "", ]) packet.flush() self.srv_data.protocolVersion = -1 while True: pkid, packet_tuple = packet.grabpacket() if pkid == 0x00: data = json.loads(packet.readpkt([ STRING, ])[0]) self.srv_data.protocolVersion = data["version"]["protocol"] self.srv_data.version = data["version"]["name"] if "modinfo" in data and data["modinfo"]["type"] == "FML": self.forge = True self.mod_info["modinfo"] = data["modinfo"] break server_sock.close()
def connect(self): """ This simply establishes the tcp socket connection and starts the flush loop, NOTHING MORE. """ self.state = LOGIN # Connect to a local server address if self.ip is None: self.server_socket.connect( ("localhost", self.proxy.srv_data.server_port)) # Connect to some specific server address else: self.server_socket.connect((self.ip, self.port)) # start packet handler self.packet = Packet(self.server_socket, self) self.packet.version = self.client.clientversion # define parsers self.parse_cb = ParseCB(self, self.packet) self._define_parsers() t = threading.Thread(target=self.flush_loop, args=()) t.daemon = True t.start()
def __init__(self, proxy, clientsock, client_addr, banned=False): """ Handle the client connection. This class Client is a "fake" server, accepting connections from clients. It receives "SERVER BOUND" packets from client, parses them, and forards them on to the server. It "sends" to the client (self.send() or self.sendpkt()) Client receives the parent proxy as it's argument. No longer receives the proxy's wrapper instance! All data is passed via servervitals from proxy's srv_data. """ # basic __init__ items from passed arguments self.client_socket = clientsock self.client_address = client_addr self.proxy = proxy self.publicKey = self.proxy.publicKey self.privateKey = self.proxy.privateKey self.servervitals = self.proxy.srv_data self.log = self.proxy.log self.ipbanned = banned # constants from config: self.spigot_mode = self.proxy.config["spigot-mode"] self.hidden_ops = self.proxy.config["hidden-ops"] self.silent_bans = self.proxy.config["silent-ipban"] # client setup and operating paramenters self.username = "******" self.packet = Packet(self.client_socket, self) self.verifyToken = encryption.generate_challenge_token() self.serverID = encryption.generate_server_id().encode('utf-8') self.MOTD = {} # client will reset this later, if need be.. self.clientversion = self.servervitals.protocolVersion # default server port (to this wrapper's server) self.serverport = self.servervitals.server_port self.onlinemode = self.proxy.config["online-mode"] # packet stuff self.pktSB = mcpackets_sb.Packets(self.clientversion) self.pktCB = mcpackets_cb.Packets(self.clientversion) self.parse_sb = ParseSB(self, self.packet) # dictionary of parser packet constants and associated parsing methods self.parsers = {} self._getclientpacketset() self.buildmode = False # keep alive data self.time_server_pinged = 0 self.time_client_responded = 0 self.keepalive_val = 0 # client and server status self.abort = False # Proxy ServerConnection() (not the javaserver) self.server_connection = None self.state = HANDSHAKE # UUIDs - all should use MCUUID unless otherwise specified # -------------------------------------------------------- # Server UUID - which is the local offline UUID. self.serveruuid = None # -------------------------------------------------------- # The client UUID authenticated by connection to session server. self.uuid = None # -------------------------------------------------------- # the formal, unique, mojang UUID as looked up on mojang servers. # This ID will be the same no matter what mode wrapper is in # or whether it is a lobby, etc. This will be the formal uuid # to use for all wrapper internal functions for referencing a # unique player. # TODO - Unused except by plugin channel. # not to be confused with the fact that API player has a property # with the same name. self.mojanguuid = None # information gathered during login or socket connection processes # TODO in the future, we could use plugin channels to # communicate these to subworld wrappers From socket data self.address = None # this will store the client IP for use by player.py self.ip = self.client_address[0] # From client handshake. For vanilla clients, it is what # the user entered to connect to your wrapper. self.serveraddressplayerused = None self.serverportplayerused = None # player api Items # EID collected by serverconnection (changes on each server) self.server_eid = 0 self.gamemode = 0 self.dimension = 0 self.position = (0, 0, 0) # X, Y, Z self.head = (0, 0) # Yaw, Pitch self.inventory = {} self.slot = 0 self.riding = None # last placement (for use in cases of bucket use) self.lastplacecoords = (0, 0, 0) self.properties = {} self.clientSettings = False self.clientSettingsSent = False self.skinBlob = {} self.windowCounter = 2 self.currentwindowid = -1 self.noninventoryslotcount = 0 self.lastitem = None # wrapper's own channel on each player client self.shared = { "username": "", "uuid": "", "ip": "", "received": False, "sent": False }