当前位置: 首页>>代码示例>>Python>>正文


Python MinecraftServer.status方法代码示例

本文整理汇总了Python中mcstatus.MinecraftServer.status方法的典型用法代码示例。如果您正苦于以下问题:Python MinecraftServer.status方法的具体用法?Python MinecraftServer.status怎么用?Python MinecraftServer.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mcstatus.MinecraftServer的用法示例。


在下文中一共展示了MinecraftServer.status方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_latency_or_offline

# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import status [as 别名]
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,代码行数:14,代码来源:main.py

示例2: bot_online

# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import status [as 别名]
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,代码行数:23,代码来源:python-telegram-mcstatus-bot.py

示例3: getMCStats

# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import status [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
开发者ID:zeroflow,项目名称:AMMD,代码行数:38,代码来源:ammd.py

示例4: MinecraftServer

# 需要导入模块: from mcstatus import MinecraftServer [as 别名]
# 或者: from mcstatus.MinecraftServer import status [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)))
开发者ID:SimpleAOB,项目名称:MCSZ,代码行数:21,代码来源:ping.py


注:本文中的mcstatus.MinecraftServer.status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。