def _getclientpacketset(self):
     # Determine packet types  - in this context, pktSB/pktCB is
     # what is being received/sent from/to the client.
     # That is why we refresh to the clientversion.
     self.pktSB = mcpackets_sb.Packets(self.clientversion)
     self.pktCB = mcpackets_cb.Packets(self.clientversion)
     self._define_parsers()
Example #2
0
    def _refresh_server_version(self):
        """Get serverversion for mcpackets use"""

        self.version = self.proxy.srv_data.protocolVersion
        self.pktSB = mcpackets_sb.Packets(self.version)
        self.pktCB = mcpackets_cb.Packets(self.version)
        self.parse_cb = ParseCB(self, self.packet)
        self._define_parsers()
    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
        }