How to use the quarry.net.client.ClientFactory 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 barneygale / quarry / examples / client_chat_logger.py View on Github external
class ChatLoggerProtocol(SpawningClientProtocol):
    def packet_chat_message(self, buff):
        p_text = buff.unpack_chat()

        # 1.7.x
        if self.protocol_version <= 5:
            pass
        # 1.8.x
        else:
            p_position = buff.unpack('B')

        self.logger.info(":: %s" % p_text)


class ChatLoggerFactory(ClientFactory):
    protocol = ChatLoggerProtocol


@defer.inlineCallbacks
def run(args):
    # Log in
    profile = yield ProfileCLI.make_profile(args)

    # Create factory
    factory = ChatLoggerFactory(profile)

    # Connect!
    factory.connect(args.host, args.port)


def main(argv):
github barneygale / quarry / examples / client_messenger.py View on Github external
# 1.7.x
        if self.protocol_version <= 5:
            p_position = 0
        # 1.8.x
        else:
            p_position = buff.unpack('B')

        if p_position in (0, 1) and p_text.strip():
            self.stdio_protocol.send_line(p_text)

    def send_chat(self, text):
        self.send_packet("chat_message", self.buff_type.pack_string(text))


class MinecraftFactory(ClientFactory):
    protocol = MinecraftProtocol
    log_level = "WARN"

    def buildProtocol(self, addr):
        minecraft_protocol = super(MinecraftFactory, self).buildProtocol(addr)
        stdio_protocol = StdioProtocol()

        minecraft_protocol.stdio_protocol = stdio_protocol
        stdio_protocol.minecraft_protocol = minecraft_protocol

        stdio.StandardIO(stdio_protocol)
        return minecraft_protocol


@defer.inlineCallbacks
def run(args):
github Gjum / Bat / bot.py View on Github external
def main(args):
    # Parse options
    if len(args) < 4:
        print 'usage: %s    [password]' % args[0]
        return 0
    host, port, username = args[1:4]
    password = args[4] if len(args) > 4 else None

    # Create profile
    profile = Profile()

    class BotFactory(ClientFactory):
        protocol = Bot

    # Create factory
    factory = BotFactory()
    factory.profile = profile
    factory.connect(host, int(port))

    # login
    if password is not None:
        def login_ok(data):
            factory.connect(host, int(port))

        def login_failed(err):
            print "login failed:", err.value
            factory.stop()
github barneygale / quarry / quarry / net / bot.py View on Github external
def buildProtocol(self, addr):
        self.resetDelay()
        return ClientFactory.buildProtocol(self, addr)
github barneygale / quarry / quarry / net / proxy.py View on Github external
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


class Bridge(PacketDispatcher):
    """
    This class exchanges packets between the upstream and downstream.
    """

    upstream_factory_class = UpstreamFactory
    log_level = logging.INFO

    logger = None
    buff_type = None

    downstream_factory = None
github barneygale / quarry / examples / client_player_list.py View on Github external
def packet_chunk_data(self, buff):
        buff.discard()

        # convert self.players into a more readable format
        printable_players = []
        for data in self.players.values():
            printable_players.append((data['name'], data['ping']))

        for display_name, ping in sorted(printable_players):
            self.logger.info("%4sms %s" % (ping, display_name))

        reactor.stop()


class PlayerListFactory(ClientFactory):
    protocol = PlayerListProtocol


@defer.inlineCallbacks
def run(args):
    # Log in
    profile = yield ProfileCLI.make_profile(args)

    # Create factory
    factory = PlayerListFactory(profile)

    # Connect!
    factory.connect(args.host, args.port)


def main(argv):
github barneygale / quarry / quarry / net / client.py View on Github external
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"

    def __init__(self, profile=None):
        super(PingClientFactory, self).__init__(profile)
        self.detected_protocol_version = defer.Deferred()
github barneygale / quarry / examples / client_ping.py View on Github external
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
    parser = argparse.ArgumentParser()
    parser.add_argument("host")
    parser.add_argument("-p", "--port", default=25565, type=int)
    args = parser.parse_args(argv)

    factory = PingFactory()
    factory.connect(args.host, args.port)
    reactor.run()

if __name__ == "__main__":
github barneygale / quarry / quarry / net / bot.py View on Github external
p_coords[2],
            p_look[0],
            p_look[1],
            p_on_ground))

        if not self.spawned:
            self.tasks.add_loop(1.0/20, self.update_position)
            self.tasks.add_loop(self.chat_message_interval, self.update_chat)
            self.spawned = True

    @register("play", 0x40)
    def packet_play_kick(self, buff):
        p_reason = buff.unpack_chat()
        self.logger.warn("Kicked: %s" % p_reason)

class BotFactory(ClientFactory, ReconnectingClientFactory):
    protocol = BotProtocol

    def buildProtocol(self, addr):
        self.resetDelay()
        return ClientFactory.buildProtocol(self, addr)