[+] get_online_players function.

[+] mcipc implementation
This commit is contained in:
Charles Le Maux 2024-07-14 22:05:32 +02:00
parent 49a5e04a1c
commit 37dc160a12

View File

@ -1,6 +1,8 @@
import subprocess import subprocess
import shlex import shlex
import time import time
import mcipc.query
import mcipc.query.client
class MinecraftServerManager: class MinecraftServerManager:
@ -61,6 +63,12 @@ class MinecraftServerManager:
if server_info['port'] == port: if server_info['port'] == port:
return server_id return server_id
return None return None
def get_online_players(self, port)->int:
with mcipc.query.Client('127.0.0.1', port) as client:
stats: mcipc.query.proto.FullStats = client.stats(full=True)
stats: int = stats.num_players
return stats
def set_cooldown(self, user_id): def set_cooldown(self, user_id):
expiry_timestamp = time.time() + 30 expiry_timestamp = time.time() + 30
@ -76,7 +84,7 @@ class MinecraftServerManager:
else: else:
del self.cooldowns[user_id] del self.cooldowns[user_id]
return False return False
if __name__ == "__main__": if __name__ == "__main__":
pass pass