mirror of
https://github.com/Dinnerbone/mcstatus.git
synced 2026-04-06 12:01:24 +08:00
Changed MinecraftServer methods to use for loops
This commit is contained in:
@@ -33,24 +33,22 @@ class MinecraftServer:
|
|||||||
return MinecraftServer(host, port)
|
return MinecraftServer(host, port)
|
||||||
|
|
||||||
def ping(self, retries=3, **kwargs):
|
def ping(self, retries=3, **kwargs):
|
||||||
attempt = 0
|
|
||||||
connection = TCPSocketConnection((self.host, self.port))
|
connection = TCPSocketConnection((self.host, self.port))
|
||||||
exception = None
|
exception = None
|
||||||
while attempt < retries:
|
for attempt in range(retries):
|
||||||
try:
|
try:
|
||||||
pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
|
pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
|
||||||
pinger.handshake()
|
pinger.handshake()
|
||||||
return pinger.test_ping()
|
return pinger.test_ping()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception = e
|
exception = e
|
||||||
attempt += 1
|
else:
|
||||||
raise exception
|
raise exception
|
||||||
|
|
||||||
def status(self, retries=3, **kwargs):
|
def status(self, retries=3, **kwargs):
|
||||||
attempt = 0
|
|
||||||
connection = TCPSocketConnection((self.host, self.port))
|
connection = TCPSocketConnection((self.host, self.port))
|
||||||
exception = None
|
exception = None
|
||||||
while attempt < retries:
|
for attempt in range(retries):
|
||||||
try:
|
try:
|
||||||
pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
|
pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
|
||||||
pinger.handshake()
|
pinger.handshake()
|
||||||
@@ -59,13 +57,12 @@ class MinecraftServer:
|
|||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception = e
|
exception = e
|
||||||
attempt += 1
|
else:
|
||||||
raise exception
|
raise exception
|
||||||
|
|
||||||
def query(self, retries=3):
|
def query(self, retries=3):
|
||||||
attempt = 0
|
|
||||||
exception = None
|
exception = None
|
||||||
while attempt < retries:
|
for attempt in range(retries):
|
||||||
try:
|
try:
|
||||||
connection = UDPSocketConnection((self.host, self.port))
|
connection = UDPSocketConnection((self.host, self.port))
|
||||||
querier = ServerQuerier(connection)
|
querier = ServerQuerier(connection)
|
||||||
@@ -73,5 +70,5 @@ class MinecraftServer:
|
|||||||
return querier.read_query()
|
return querier.read_query()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception = e
|
exception = e
|
||||||
attempt += 1
|
else:
|
||||||
raise exception
|
raise exception
|
||||||
Reference in New Issue
Block a user