當前位置: 首頁>>代碼示例>>Python>>正文


Python MinecraftServer.lookup方法代碼示例

本文整理匯總了Python中mcstatus.MinecraftServer.lookup方法的典型用法代碼示例。如果您正苦於以下問題:Python MinecraftServer.lookup方法的具體用法?Python MinecraftServer.lookup怎麽用?Python MinecraftServer.lookup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mcstatus.MinecraftServer的用法示例。


在下文中一共展示了MinecraftServer.lookup方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: query_command

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
    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,代碼行數:36,代碼來源:__init__.py

示例2: mcb

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:30,代碼來源:views.py

示例3: mcping

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:35,代碼來源:minecraft_ping.py

示例4: index

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:28,代碼來源:views.py

示例5: _init

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
def _init():
    config = configparser.ConfigParser()
    config.read("config.ini")
    hostname = config['DEFAULT']['server']

    server = MinecraftServer.lookup(hostname)
    return server
開發者ID:jfrederickson,項目名稱:mcstatus-rest,代碼行數:9,代碼來源:main.py

示例6: minecraft_test

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:10,代碼來源:monitoring.py

示例7: getStatus

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
 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,代碼行數:10,代碼來源:manager.py

示例8: minecraft_status

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:11,代碼來源:crapbot.py

示例9: query_server

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:11,代碼來源:app.py

示例10: get_players

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:12,代碼來源:minecraft.py

示例11: __call__

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
    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,代碼行數:12,代碼來源:commands.py

示例12: do_GET

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
    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,代碼行數:13,代碼來源:monitor.py

示例13: index

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
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,代碼行數:13,代碼來源:views.py

示例14: check

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
    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,代碼行數:15,代碼來源:minecraft.py

示例15: updateOnlineServers

# 需要導入模塊: from mcstatus import MinecraftServer [as 別名]
# 或者: from mcstatus.MinecraftServer import lookup [as 別名]
 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,代碼行數:15,代碼來源:Analyzer.py


注:本文中的mcstatus.MinecraftServer.lookup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。