本文整理汇总了Python中mcstatus.MinecraftServer.query方法的典型用法代码示例。如果您正苦于以下问题:Python MinecraftServer.query方法的具体用法?Python MinecraftServer.query怎么用?Python MinecraftServer.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mcstatus.MinecraftServer
的用法示例。
在下文中一共展示了MinecraftServer.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import query [as 别名]
def index():
"""Index (and only) page of site."""
render_obj = []
message_objects = Message.query.filter_by(display=True).all()
server_objects = Server.query.all()
for server in server_objects:
address = server.address
port = server.port
conn = MinecraftServer(address, port)
try:
conn.ping()
# except ConnectionRefusedError:
# Commented out because for some reason on the production server,
# attempting to catch this error causes the site to break and display
# 'Internal Server Error'. Logs from such events say that
# 'ConnectionRefusedError' is undefined, although there seem to be no
# issues when testing locally.
except:
render_obj.append({
"address": address,
"port": port,
"modpack_version": server.modpack_version,
"client_config": server.client_config,
"status": "Offline",
})
else:
add_to_render = {}
q = conn.query()
motd = q.motd
players = {
"max": q.players.max,
"online": q.players.online,
"names": q.players.names,
}
jar_version = q.software.version
add_to_render.update({
"address": address,
"port": port,
"modpack_version": server.modpack_version,
"client_config": server.client_config,
"status": "Online",
"motd": motd,
"players": players,
"jar_version": jar_version,
})
render_obj.append(add_to_render)
return render_template(
"index.html",
servers=render_obj,
messages=message_objects,
)
示例2: query
# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import query [as 别名]
def query():
address = request.args.get("address")
port = int(request.args.get("port"))
conn = MinecraftServer(address, port)
try:
conn.ping()
# except ConnectionRefusedError:
# Commented out because for some reason on the production server,
# attempting to catch this error causes the site to break and display
# 'Internal Server Error'. Logs from such events say that
# 'ConnectionRefusedError' is undefined, although there seem to be no
# issues when testing locally.
except:
response = jsonify({
"status": "Offline",
"players_online": 0,
"player_names": None,
})
else:
q = conn.query()
response = jsonify({
"status": "Online",
"players_online": q.players.online,
"players_max": q.players.max,
"player_names": q.players.names,
})
return response
示例3: getMCStats
# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import query [as 别名]
def getMCStats():
global server_status
global server_status_time
server = MinecraftServer("localhost", 25565)
try:
javaProcess = getJavaProcess()
query = server.query()
status = server.status()
except (subprocess.CalledProcessError, socket.gaierror, ConnectionRefusedError, BrokenPipeError, socket.timeout):
if server_status is not None:
return {"online": server_status}
else:
return {"online": "offline"}
javaMemory = javaProcess.memory_info().rss
javaMemory = toSi(javaMemory, 1024)
javaCPU = javaProcess.cpu_percent()
size = subprocess.check_output("du -sh {}".format(PATH), shell=True)
size_rx = re.search("^(.*?)(.)\t", size.decode("UTF-8", errors="replace"))
size = size_rx.group(1) + " " + size_rx.group(2)
resp = query.raw
resp["online"] = "online"
resp["players"] = query.players.names
resp["latency"] = status.latency
resp["minecraft_RAM"] = javaMemory
resp["minecraft_CPU"] = javaCPU
resp["minecraft_HDD"] = size
if server_status == "stopping":
resp["online"] = server_status
return resp
示例4: check_upstate
# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import query [as 别名]
def check_upstate():
data = {}
# If the app has been started in debug mode, return dummy data.
if app.debug:
data["online"] = True
data["players_online"] = ["testname1", "testname2"]
data["players_max"] = 20
data["version"] = "CraftBukkit 1.8.8"
data["plugins"] = ["WorldEdit", "WorldGuard"]
return json.dumps(data)
# Otherwise, an actual server query should be made.
server = MinecraftServer("localhost", 25565)
try:
query = server.query()
data["online"] = True
data["players_online"] = query.players.names
data["players_max"] = query.players.max
data["version"] = query.software.brand
data["plugins"] = query.software.plugins
except:
data["online"] = False
return json.dumps(data)
示例5: MinecraftServer
# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import query [as 别名]
from mcstatus import MinecraftServer
# If you know the host and port, you may skip this and use MinecraftServer("example.org", 1234)
# server = MinecraftServer.lookup("bcsn.us:25565")
server = MinecraftServer("184.18.202.133:25565")
# '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.
# 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()
print("The server has the following players online: {0}".format(", ".join(query.players.names)))
示例6: get_query
# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import query [as 别名]
def get_query(mc_server, port=25565):
mc = MinecraftServer(mc_server, port)
query = mc.query()
return query.players.names