mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] get_online_players function.
[+] mcipc implementation
This commit is contained in:
parent
49a5e04a1c
commit
37dc160a12
@ -1,6 +1,8 @@
|
||||
import subprocess
|
||||
import shlex
|
||||
import time
|
||||
import mcipc.query
|
||||
import mcipc.query.client
|
||||
|
||||
|
||||
class MinecraftServerManager:
|
||||
@ -61,6 +63,12 @@ class MinecraftServerManager:
|
||||
if server_info['port'] == port:
|
||||
return server_id
|
||||
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):
|
||||
expiry_timestamp = time.time() + 30
|
||||
@ -76,7 +84,7 @@ class MinecraftServerManager:
|
||||
else:
|
||||
del self.cooldowns[user_id]
|
||||
return False
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user