-
Notifications
You must be signed in to change notification settings - Fork 1
/
playRustIO.py
79 lines (60 loc) · 2.8 KB
/
playRustIO.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
import requests
import json
import playerDatabase
import watcherLogging
# This will be set in the config file so dont worry about it :-)
mainIpandPort = "192.168.1.1:28015"
# get all recent players with hyper links
def get_all_recent_player_info(serverIP, ServerPort):
global mainIpandPort
try:
resp = requests.get("http://" + serverIP + ':' +
ServerPort + "/recent.json", allow_redirects=True)
print("check for all player recent info Address" + str(mainIpandPort))
myList = []
playerCount = 0
# print(resp.content)
players = json.loads(resp.content)
for p in players:
myList.append('player=(' + p['name'] + ') id=(' + p['id'] + ')\n')
playerCount += 1
myList.append("Total recent players::{}" .format(playerCount) + '\n')
except Exception as e:
print("Error has occured in PlayRust.io request get_all_recent_player_info ::" + str(e))
watcherLogging.error_logs(
'Error has occured in PlayRust.io request get_all_recent_player_info ::' + str(e))
return myList
# check thise dictinary against values stored in the database and returns a dictionary of name changes if any
# key = playerID and Value = player name
def check_for_player_name_changes(serverIP, ServerPort):
global mainIpandPort
playerDbList = []
myReturnList = []
try:
resp = requests.get("http://" + serverIP + ':' +
ServerPort + "/recent.json", allow_redirects=True)
print("check for player name changes Address" + str(mainIpandPort))
#myDic = {}
# print(resp.content)
players = json.loads(resp.content)
for p in players:
playerDbList = playerDatabase.check_for_existing_player(p['id'])
if len(playerDbList) > 0:
for pData in playerDbList:
if pData[2] != p['name']:
# check if the name has changed
playerDatabase.update_player_name(p['id'], p['name'])
myReturnList.append(
"Player ::" + pData[1] + " Now Playing as ::" + p['name'] + '\n')
print("player changed name")
else:
# add new player to the database
playerDatabase.add_player_data(p['id'], p['name'], p['name'])
print("Added new player :: Id:" +
p['id'] + " Name:" + p['name'])
# add or check player in the database
except Exception as e:
print("Error has occured in PlayRust.io request check_for_player_name_changes ::" + str(e))
watcherLogging.error_logs(
'Error has occured in PlayRust.io request check_for_player_name_changes ::' + str(e))
return myReturnList