Added a MinecraftServer.lookup method, converts a string to host/port (including SRV lookup)

This closes #12
This commit is contained in:
Nathan Adams
2014-09-26 01:05:47 +02:00
parent 18af499c62
commit 7bcbbc7409
9 changed files with 101 additions and 11 deletions

View File

@@ -2,7 +2,7 @@ mcstatus
========
`mcstatus` provides an easy way to query Minecraft servers for any information they can expose.
It provides two modes of access, `query` and `ping`, the differences of which are listed below in usage.
It provides three modes of access (`query`, `status` and `ping`), the differences of which are listed below in usage.
Usage
-----
@@ -10,15 +10,21 @@ Usage
```python
from mcstatus import MinecraftServer
server = MinecraftServer("localhost", 25565)
# If you know the host and port, you may skip this and use MinecraftServer("example.org", 1234)
server = MinecraftServer.lookup("example.org:1234")
# 'status' is supported by all Minecraft servers that are version 1.7 or higher.
status = server.status()
print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
# 'ping' is supported by all Minecraft servers that are version 1.7 or higher.
status, ping = server.ping_server()
print("The server has {0} players".format(status.players.online))
# It is included in a 'status' call, but is exposed separate if you do not require the additional info.
latency = server.ping()
print("The server replied in {0} ms".format(latency))
# 'query' has to be enabled in a servers' server.properties file.
# It may give more information than a ping, such as a full player list or mod information.
query = server.query_server()
query = server.query()
print("The server has the following players online: {0}".format(", ".join(query.players.names)))
```