Writing a Client¶
A client is generally made up of three parts:
- A
Profile
orOfflineProfile
object, representing the Minecraft account to use. - A subclass of
ClientFactory
. Client factories don’t do a lot; simply pass a profile to its initializer and then callconnect()
. You may also want to subclass from twisted’s ReconnectingClientFactory - A subclass of
ClientProtocol
. This represents your connection to the server.
See also
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")
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.