Writing a Client

A client is generally made up of three parts:

Skeleton Client

By default quarry proceeds through the authentication process and then switches into the “play” protocol mode. The skeleton client below will receive world data from the server, but as it does not send any position updates it will be disconnected by the server after a few seconds. Please see the Examples for less silly clients.

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


class ExampleClientProtocol(ClientProtocol):
    pass


class ExampleClientFactory(ClientFactory):
    protocol = ExampleClientProtocol


@defer.inlineCallbacks
def main():
    print("logging in...")
    profile = yield Profile.from_credentials(
        "someone@somewhere.com", "p4ssw0rd")
    factory = ExampleClientFactory(profile)
    print("connecting...")
    factory = yield factory.connect("localhost", 25565)
    print("connected!")


if __name__ == "__main__":
    main()
    reactor.run()

Offline Profiles

Use an OfflineProfile if you only need to log into offline-mode servers:

from quarry.net.auth import OfflineProfile
profile = OfflineProfile("Notch")
class quarry.net.auth.OfflineProfile[source]
__init__(display_name='quarry')[source]
classmethod from_display_name(display_name)[source]

For compatibility with the from_ methods on Profile, this method returns a Deferred that immediately fires with a constructed OfflineProfile object.

Online Profiles

Quarry also provides a number of methods for logging in to the Mojang session servers. Each of these returns a Deferred that will fire with a Profile object when login succeeds. Defining a callback and then calling Profile.from_credentials(...).addCallback(myfunc) is one approach, but it’s usually cleaner to use inlineCallbacks, as in the first example.

class quarry.net.auth.Profile(client_token, access_token, display_name, uuid)[source]
to_file(profiles_path=None)[source]
classmethod from_credentials(email, password)[source]
classmethod from_token(client_token, access_token, display_name, uuid)[source]
classmethod from_file(display_name=None, uuid=None, profiles_path=None)[source]