fix mcstatus properly
This commit is contained in:
parent
e5d55ba0ad
commit
6faf2022e8
|
@ -198,44 +198,58 @@ in
|
||||||
from mcstatus import JavaServer
|
from mcstatus import JavaServer
|
||||||
import signal
|
import signal
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import notify2
|
||||||
|
|
||||||
|
pvv = JavaServer.lookup("minecraft.pvv.ntnu.no")
|
||||||
|
dods = JavaServer.lookup("mc.dodsorf.as")
|
||||||
|
|
||||||
|
|
||||||
def see_players():
|
def getPlayers(server):
|
||||||
|
status = server.status()
|
||||||
|
players = getattr(getattr(status, "players"), "sample", [])
|
||||||
|
return players or []
|
||||||
|
|
||||||
|
|
||||||
|
def build_players(list, server):
|
||||||
result = ""
|
result = ""
|
||||||
if pvv_status is not None:
|
if len(list) > 0:
|
||||||
result += "PVV: "
|
result += server + ": "
|
||||||
for player in pvv_status.players.sample:
|
for player in list:
|
||||||
result += player.name + " "
|
result += player.name + " \n"
|
||||||
result += "\n"
|
return result
|
||||||
if dods_status is not None:
|
|
||||||
result += "DODS: "
|
|
||||||
for player in dods_status.players.sample:
|
|
||||||
result += player.name + " "
|
|
||||||
result += "\n"
|
|
||||||
|
|
||||||
|
|
||||||
signal.signal(signal.SIGUSR1, see_players)
|
def display_players(pvv, dods):
|
||||||
|
result = build_players(getPlayers(pvv), "PVV")
|
||||||
|
result += build_players(getPlayers(dods), "DODS")
|
||||||
|
return result
|
||||||
|
|
||||||
while True:
|
|
||||||
result = ""
|
|
||||||
try:
|
|
||||||
pvv = JavaServer.lookup("minecraft.pvv.ntnu.no")
|
|
||||||
pvv_status = pvv.status()
|
|
||||||
if pvv_status.players.online > 0:
|
|
||||||
result += ("P" + str(pvv_status.players.online))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
def peek(*_):
|
||||||
dods = JavaServer.lookup("mc.dodsorf.as")
|
result = display_players(pvv, dods)
|
||||||
dods_status = dods.status()
|
notify2.init('Minecraft Server Status')
|
||||||
if dods_status.players.online > 0:
|
n = notify2.Notification("Minecraft Server Status", result)
|
||||||
result += ("D" + str(dods_status.players.online))
|
n.show()
|
||||||
except:
|
main()
|
||||||
pass
|
|
||||||
|
|
||||||
print(result)
|
|
||||||
sleep(5)
|
signal.signal(signal.SIGUSR1, peek)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
result = ""
|
||||||
|
pvvs = getPlayers(pvv)
|
||||||
|
dodss = getPlayers(dods)
|
||||||
|
if len(pvvs) > 0:
|
||||||
|
result += "P" + str(len(pvvs))
|
||||||
|
if len(dodss) > 0:
|
||||||
|
result += "D" + str(len(dodss))
|
||||||
|
print(result, flush=True)
|
||||||
|
sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
'';
|
'';
|
||||||
click-left = "kill -USR1 %pid%";
|
click-left = "kill -USR1 %pid%";
|
||||||
# interval =
|
# interval =
|
||||||
|
|
Loading…
Reference in New Issue