本文整理汇总了Python中mcstatus.MinecraftServer类的典型用法代码示例。如果您正苦于以下问题:Python MinecraftServer类的具体用法?Python MinecraftServer怎么用?Python MinecraftServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MinecraftServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: index
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,
)
开发者ID:tlake,项目名称:mc_site,代码行数:56,代码来源:mc_site.py
示例2: query
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
开发者ID:tlake,项目名称:mc_site,代码行数:29,代码来源:mc_site.py
示例3: get_latency_or_offline
def get_latency_or_offline(server_ip):
print("Checking server " + server_ip)
# noinspection PyBroadException
try:
server = MinecraftServer(server_ip)
# MinecraftServer.lookup(server_ip)
latency = server.status(retries=1).latency
print("Server " + server_ip + " is online (latency: " + str(latency) + "ms)")
return True, latency
except Exception as e:
print("Server " + server_ip + " is offline " + str(e))
return False, str(e)
开发者ID:paolo565,项目名称:MinecraftDnsSwitcher,代码行数:12,代码来源:main.py
示例4: mcb
def mcb():
# Look up server
server = MinecraftServer.lookup('98.244.54.58:25565')
ip = '{}:{}'.format(server.host, server.port)
# Ping the server
stat = None
rawinfo = None
players = None
try:
ping = server.ping()
except Exception as e:
return 'Server is down :('
else:
stat = 1
if stat == 1:
# Get query info
rawinfo = server.query().raw
players = server.query().players.names
return render_template('mcb.html',
stat=stat,
pnum=int(rawinfo['numplayers']),
names=players,
ver=rawinfo['version'],
ip=ip)
开发者ID:ndiquattro,项目名称:quattsweb,代码行数:28,代码来源:views.py
示例5: _init
def _init():
config = configparser.ConfigParser()
config.read("config.ini")
hostname = config['DEFAULT']['server']
server = MinecraftServer.lookup(hostname)
return server
开发者ID:jfrederickson,项目名称:mcstatus-rest,代码行数:7,代码来源:main.py
示例6: query_command
def query_command(self, protocol, caller, source, command, raw_args,
parsed_args):
if len(parsed_args) < 1:
caller.respond("Usage: {CHARS}mcquery <address[:port]>")
address = parsed_args[0]
target = source
if isinstance(source, User):
target = caller
try:
q = MinecraftServer.lookup(address)
status = q.status()
except Exception as e:
target.respond("Error retrieving status: %s" % e)
self.logger.exception("Error retrieving status")
return
servername = status.description
if isinstance(servername, dict):
servername = servername.get("text", "<Unknown server name>")
done = ""
done += "[%s] %s | " % (status.version.name, servername)
done += "%s/%s " % (status.players.online, status.players.max)
if "plugins" in status.raw:
done += "| %s plugins" % len(status.raw["plugins"])
target.respond(done)
if protocol.can_flood and status.players.sample:
players = ", ".join([x.name for x in status.players.sample])
target.respond("Players: %s" % players)
开发者ID:UltrosBot,项目名称:Ultros-contrib,代码行数:34,代码来源:__init__.py
示例7: mcping
def mcping(text):
"""<server[:port]> - gets info about the Minecraft server at <server[:port]>"""
try:
server = MinecraftServer.lookup(text)
except (IOError, ValueError) as e:
return e
try:
s = server.status()
except socket.gaierror:
return "Invalid hostname"
except socket.timeout:
return "Request timed out"
except ConnectionRefusedError:
return "Connection refused"
except ConnectionError:
return "Connection error"
except (IOError, ValueError) as e:
return "Error pinging server: {}".format(e)
if isinstance(s.description, dict):
description = format_colors(" ".join(s.description["text"].split()))
else:
description = format_colors(" ".join(s.description.split()))
if s.latency:
return "{}\x0f - \x02{}\x0f - \x02{:.1f}ms\x02" " - \x02{}/{}\x02 players".format(
description, s.version.name, s.latency, s.players.online, s.players.max
).replace("\n", "\x0f - ")
else:
return "{}\x0f - \x02{}\x0f" " - \x02{}/{}\x02 players".format(
description, s.version.name, s.players.online, s.players.max
).replace("\n", "\x0f - ")
开发者ID:CrushAndRun,项目名称:Cloudbot-Fluke,代码行数:33,代码来源:minecraft_ping.py
示例8: index
def index(request):
# Get the server
server = MinecraftServer.lookup("www.yourServerHere.com:25565")
# Get the status and query data, requires two calls to get everything.
status = server.status()
query = server.query()
# Create the object to store all the server data.
req = {}
req['playerCount'] = status.players.online
req['maxPlayers'] = status.players.max
req['playerNames'] = query.players.names
req['version'] = query.software.version;
req['motd'] = query.motd;
req['map'] = query.map;
# Package the requested data into the callback for JSONP
callback = request.GET.get('callback', '')
response = json.dumps(req)
response = callback + '(' + response + ');'
return HttpResponse(response, content_type="application/json")
开发者ID:metapod,项目名称:minecraft-status,代码行数:26,代码来源:views.py
示例9: minecraft_test
def minecraft_test(server_info, extra):
try:
server = MinecraftServer.lookup(server_info)
server.status()
return True
except Exception as e:
print e
return False
开发者ID:ISUSec,项目名称:cdc_monitor,代码行数:8,代码来源:monitoring.py
示例10: getStatus
def getStatus(self):
prop = self.getProperties()
port = prop["server-port"]
host = prop["server-ip"]
if not host:
host = "127.0.0.1"
print(port, host)
return MinecraftServer.lookup(host + ":" + port).status()
开发者ID:thomas15v,项目名称:mcwrapper,代码行数:8,代码来源:manager.py
示例11: query_server
def query_server(server):
"""Query the minecraft server"""
server = MinecraftServer.lookup(server)
try:
response = server.query()
except socket.timeout:
return None
else:
return response
开发者ID:chooper,项目名称:minecraftstatus-api,代码行数:9,代码来源:app.py
示例12: minecraft_status
def minecraft_status (bot, msg):
server = MinecraftServer.lookup("minecraft.westsixth.net:25565")
query = server.query()
if not query.players.names:
bot.say(msg.channel, "Nobody is on :-(")
bot.say(msg.channel, "The server is running version {0} at the moment.".format("".join(query.software.version)))
else:
bot.say(msg.channel, "The following people are on: {0}".format(", ".join(query.players.names)))
bot.say(msg.channel, "The server is running version {0} at the moment.".format("".join(query.software.version)))
开发者ID:erichensley,项目名称:crapbot,代码行数:9,代码来源:crapbot.py
示例13: get_players
def get_players(address):
if not address:
return []
print "Connecting to {}".format(address)
server = MinecraftServer.lookup(address)
resp = server.status()
try:
return [p.name for p in resp.players.sample]
except TypeError:
return []
开发者ID:pickleinc,项目名称:realmsbot,代码行数:10,代码来源:minecraft.py
示例14: __call__
async def __call__(self, client, message):
ip = message.content.split(' ')[1]
server = MinecraftServer.lookup(ip)
try:
status = server.status()
await client.send_message(message.channel, '**{0}**: {1} players online. Running {2}'.format(
ip, status.players.online, status.version.name))
except socket.gaierror:
await client.send_message(message.channel, 'Cannot reach server.')
开发者ID:bcbwilla,项目名称:bcbbot-discord,代码行数:10,代码来源:commands.py
示例15: do_GET
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
if self.path.translate(None, "/") in Config.keys():
server = MinecraftServer.lookup(Config[self.path.translate(None, "/")])
status = server.status()
result = {'online': status.players.online, 'latency': status.latency}
self.wfile.write(json.dumps(result))
else:
self.wfile.write("Failed")
开发者ID:ToXiiKD34th,项目名称:ComputerCraft,代码行数:11,代码来源:monitor.py
示例16: index
def index(request):
try:
server = MinecraftServer.lookup(settings.MC_HOST)
status = server.status()
query = server.query()
except:
status = None
query = None
user = Account.objects.all()
top_m = Fe.objects.order_by("-money").exclude(name__contains="-")
return render(request, "portal/index.html", {"status": status, "query": query, "top_m": top_m, "user": user})
开发者ID:theballkyo,项目名称:minecraft-web-py,代码行数:11,代码来源:views.py
示例17: bot_online
def bot_online(bot, update, args):
"""Ónline function to check status of a Minecraft server"""
try:
chat_id = update.message.chat_id
address = args[0]
server = MinecraftServer(address)
status = server.status()
bot.sendMessage(
chat_id=chat_id,
text=("{0} ({1}) v{2} {3}ms Players online {4}/{5}".format(
status.description,
address,
status.version.name,
status.latency,
status.players.online,
status.players.max
)))
except IndexError:
bot.sendMessage(chat_id=chat_id, text=onlinetext)
except OSError:
bot.sendMessage(chat_id=chat_id, text=onlinetext)
开发者ID:Landrash,项目名称:python-telegram-mcstatus-bot,代码行数:21,代码来源:python-telegram-mcstatus-bot.py
示例18: check
def check(self, textkey, data, config):
server = MinecraftServer.lookup("localhost:25565")
srv = server.status()
players = srv.players.online
latency = server.ping()
if textkey == 'players':
return players
elif textkey == 'latency':
return latency
return 0
开发者ID:CoryPulm,项目名称:minecraft-panopta-plugin,代码行数:13,代码来源:minecraft.py
示例19: updateOnlineServers
def updateOnlineServers(self):
connection = sqlite3.connect("servers.db")
cursor = connection.cursor()
ports = AnalyzeData.getPorts()
for x in ports:
name="node" + str(x)
try:
server = MinecraftServer.lookup("127.0.0.1:" + str(x))
status = server.ping()
except timeout:
cursor.execute("UPDATE server_running SET running=? WHERE name=?", (False,name))
connection.commit()
connection.close()
开发者ID:Huhnmonster,项目名称:McPyCloud,代码行数:13,代码来源:Analyzer.py
示例20: index
def index():
# Server IPs
lobby_ip = '50.116.56.173:25565'
# Fetch Server Data
server = MinecraftServer.lookup(lobby_ip)
status = server.status()
# latency = server.ping()
# query = server.query()
lobby_players = status.players.online
return render_template("index.html", count=lobby_players)
开发者ID:Ruinsane,项目名称:Hub,代码行数:15,代码来源:Hub.py
注:本文中的mcstatus.MinecraftServer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论