-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_players.py
92 lines (75 loc) · 2.82 KB
/
list_players.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#### CONFIG READER ####
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
SERVER_IP = str(config['default']['SERVER_IP'])
RCON_PORT = int(config['default']['RCON_PORT'])
RCON_PASSWORD = str(config['default']['RCON_PASSWORD'])
#### BEGIN REAL SCRIPT SHIT ####
from time import sleep
import sys
from datetime import datetime
import os
import logging
#logging.basicConfig(level=logging.DEBUG)
try:
from importlib.metadata import version
except:
logging.error('Missing module importlib_metadata. Install with: pip install importlib_metadata')
sys.exit(1)
try:
import rcon
from rcon.source import Client
rconVersion = version('rcon')
rconVersionNum = rconVersion.split('.')
rconVersionNum = [int(i) for i in rconVersionNum]
logging.debug(rconVersionNum[0])
logging.debug(rconVersionNum[1])
logging.debug(rconVersionNum[2])
if not (rconVersionNum[0] >= 2 and
rconVersionNum[1] >= 4 and
rconVersionNum[2] >= 6):
raise Exception
except Exception as e:
logging.debug(str(e))
logging.error('RCON Version: ' + rconVersion)
logging.error('Needs the dev rcon version! Palworld is dumb and needs the dev version currently. Install with:')
logging.error('pip install git+https://github.com/conqp/rcon.git')
sys.exit(1)
def parsePlayersList(playersString):
stringList = playersString.splitlines()
playersDict = {}
#remove header
stringList.pop(0)
logging.debug('stringList')
for playerEntry in stringList:
playerEntryListified = playerEntry.split(',')
logging.debug(playerEntryListified)
playersDict[playerEntryListified[0]] = {"playeruid": playerEntryListified[1], "steamid": playerEntryListified[2]}
#name,playeruid,steamid
#Kupie,4160040412,76561197993593793
return playersDict
def printAllPlayersToconsole(PlayersList):
PlayersStringList = []
print('Current Players: Name, UID, SteamID')
for PlayersDict in PlayersList:
PlayersStringList.append(PlayersDict)
playerInfo = PlayersDict + ', ' + PlayersList[PlayersDict]['playeruid'] + ', ' + PlayersList[PlayersDict]['steamid']
print(playerInfo)
PlayersList = []
def rconSendCommand(command: str, args: str = ''):
with Client(SERVER_IP, RCON_PORT, passwd=RCON_PASSWORD) as client:
#palworld broadcast doesn't handle spaces
#Palworld why Q.Q
#Also yoinked this from: https://github.com/gavinnn101/palworld_dedi_helper/blob/main/src/palworld_rcon/source_rcon.py
if command.lower() == "broadcast":
command = command + " " + args.replace(" ", "\x1F")
else:
command = command + " " + " ".join(args)
logging.debug('Sending command: ' + command)
return client.run(command, enforce_id=False)
def main():
PlayersList = parsePlayersList(rconSendCommand('ShowPlayers'))
printAllPlayersToconsole(PlayersList)
if __name__ == "__main__":
main()