How to use the quarry.net.client.ClientProtocol function in quarry

To help you get started, we’ve selected a few quarry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Gjum / Bat / botProtocol.py View on Github external
from nbt.nbt import TAG_Compound

from quarry.net.client import ClientProtocol, register

from world import World
from entity import EntityHandler
from window import WindowHandler
from info import packet_dict # TODO only used for logging


class BotProtocol(ClientProtocol):

    def setup(self):
        self.eid = -1
        self.coords = [0, 0, 0]
        self.yaw = 0
        self.pitch = 0
        self.selected_slot = 0
        self.health = 0
        self.food = 0
        self.saturation = 0

        self.world = World()
        self.window_handler = WindowHandler()
        self.entities = EntityHandler()

        self.spawned = False
github barneygale / quarry / quarry / net / client.py View on Github external
class ClientFactory(Factory, protocol.ClientFactory):
    protocol = ClientProtocol
    protocol_mode_next = "login"

    def __init__(self, profile=None):
        if profile is None:
            profile = auth.OfflineProfile()
        self.profile = profile

    def connect(self, host, port=25565):
        reactor.connectTCP(host, port, self, self.connection_timeout)


class PingClientProtocol(ClientProtocol):

    def status_response(self, data):
        self.close()
        detected_version = int(data["version"]["protocol"])
        if detected_version in self.factory.minecraft_versions:
            self.factory.detected_protocol_version.callback(detected_version)
        else:
            self.factory.detected_protocol_version.errback(
                failure.Failure(ProtocolError(
                    "Unsupported protocol version: %d" % detected_version)))


class PingClientFactory(ClientFactory):
    protocol = PingClientProtocol
    protocol_mode_next = "status"
github barneygale / quarry / quarry / net / bot.py View on Github external
import re
from twisted.internet.protocol import ReconnectingClientFactory

from quarry.net.client import ClientFactory, ClientProtocol, register

# 1.7.x only!

class BotProtocol(ClientProtocol):
    protocol_mode_next = "login"

    chat_message_interval = 1.0
    chat_throttle_length = 3.0

    command_prefix = "!"

    #-- SETUP -----------------------------------------------------------------

    def setup(self):
        self.on_ground = False

        self.spawned = False

        self.chat_throttled = False
        self.pending_chat = []
github barneygale / quarry / examples / client_player_list.py View on Github external
"""
Player lister example client

This client requires a Mojang account for online-mode servers. It logs in to
the server and prints the players listed in the tab menu.
"""

from twisted.internet import reactor, defer
from quarry.net.client import ClientFactory, ClientProtocol
from quarry.net.auth import ProfileCLI


class PlayerListProtocol(ClientProtocol):
    def setup(self):
        self.players = {}

    def packet_player_list_item(self, buff):
        # 1.7.x
        if self.protocol_version <= 5:
            p_player_name = buff.unpack_string()
            p_online = buff.unpack('?')
            p_ping = buff.unpack('h')

            if p_online:
                self.players[p_player_name] = {
                    'name': p_player_name,
                    'ping': p_ping
                }
            elif p_player_name in self.players:
github barneygale / quarry / quarry / net / proxy.py View on Github external
data directly to the second endpoint, without any packet decoding.
    """
    if len(endpoint1.recv_buff) > 0:
        endpoint2.transport.write(
            endpoint2.cipher.encrypt(
                endpoint1.recv_buff.read()))

    def data_received(data):
        endpoint2.transport.write(
            endpoint2.cipher.encrypt(
                endpoint1.cipher.decrypt(data)))

    endpoint1.data_received = data_received


class Upstream(ClientProtocol):
    def setup(self):
        self.bridge = self.factory.bridge
        self.bridge.upstream = self

    def player_joined(self):
        self.bridge.upstream_ready()

    def connection_lost(self, reason=None):
        ClientProtocol.connection_lost(self, reason)
        self.bridge.upstream_disconnected()


class UpstreamFactory(ClientFactory):
    protocol = Upstream
    bridge = None
github barneygale / quarry / quarry / net / client.py View on Github external
def connection_made(self):
        """Called when the connection is established"""
        super(ClientProtocol, self).connection_made()

        # Determine protocol version
        if self.factory.protocol_mode_next == "status":
            pass
        elif self.factory.force_protocol_version is not None:
            self.protocol_version = self.factory.force_protocol_version
        else:
            factory = PingClientFactory()
            factory.connect(self.remote_addr.host, self.remote_addr.port)
            self.protocol_version = yield factory.detected_protocol_version

        self.switch_protocol_mode(self.factory.protocol_mode_next)
github barneygale / quarry / quarry / net / proxy.py View on Github external
def connection_lost(self, reason=None):
        ClientProtocol.connection_lost(self, reason)
        self.bridge.upstream_disconnected()
github barneygale / quarry / examples / client_ping.py View on Github external
"""
Pinger example client

This example client connects to a server in "status" mode to retrieve some
information about the server. The information returned is what you'd normally
see in the "Multiplayer" menu of the official client.
"""

from twisted.internet import reactor
from quarry.net.client import ClientFactory, ClientProtocol


class PingProtocol(ClientProtocol):

    def status_response(self, data):
        for k, v in sorted(data.items()):
            if k != "favicon":
                self.logger.info("%s --> %s" % (k, v))

        reactor.stop()


class PingFactory(ClientFactory):
    protocol = PingProtocol
    protocol_mode_next = "status"


def main(argv):
    import argparse
github barneygale / quarry / quarry / net / client.py View on Github external
p_uuid = buff.unpack_string()
        p_display_name = buff.unpack_string()

        self.switch_protocol_mode("play")
        self.player_joined()

    def packet_login_set_compression(self, buff):
        self.set_compression(buff.unpack_varint())

    def packet_set_compression(self, buff):
        self.set_compression(buff.unpack_varint())

    packet_disconnect = packet_login_disconnect


class SpawningClientProtocol(ClientProtocol):
    spawned = False

    def __init__(self, factory, remote_addr):
        # x, y, z, yaw, pitch
        self.pos_look = [0, 0, 0, 0, 0]

        super(SpawningClientProtocol, self).__init__(factory, remote_addr)

    # Send a 'player' packet every tick
    def update_player_inc(self):
        self.send_packet("player", self.buff_type.pack('?', True))

    # Sent a 'player position and look' packet every 20 ticks
    def update_player_full(self):
        self.send_packet(
            "player_position_and_look",