-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
81 lines (72 loc) · 2.56 KB
/
server.py
File metadata and controls
81 lines (72 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from mcstatus import MinecraftServer
import json
def returnMCInfo(server):
try:
# 'status' is supported by all Minecraft servers that are version 1.7 or higher.
status = server.status()
print(f"The server has {status.players.online} players and replied in {status.latency} ms")
try:
# '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()
print(f"The server has the following players online: {', '.join(query.players.names)}")
serverInfo = {
"status": {
"players": {
"online": status.players.online,
"max": status.players.max
},
"latency": status.latency
},
"query": {
"players": {
"names": query.players.names,
"list": query.players.list
}
}
}
except:
serverInfo = {
"status": {
"players": {
"online": status.players.online,
"max": status.players.max
},
"latency": status.latency
},
"query": {
"players": {
"names": "The server doesn't allow querying.",
"list": ["NoQuery"]
}
},
"error": "The server doesn't allow querying, or something has gone wrong with the query."
}
except:
serverInfo = {"error": "The server may be offline.", "code": 503}
return serverInfo
return serverInfo
def getPlayers(query):
players = []
for player in query.players.names:
players.append(player)
return players
def toDir(status, server, query):
serverinfo = {
"status": {
"online": status.players.online,
"desc": status.description,
"version": status.version.name,
"protocol": status.version.protocol,
"players": {
"max": status.players.max,
"online": status.players.online,
},
},
"query": {
"players": {
"names": list(query.players.names),
},
},
}
return serverinfo