-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgt_net.py
72 lines (59 loc) · 2.05 KB
/
gt_net.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
import requests
import time
def get_info(ip=False, port=False):
'''
SERVER IP AND PORT
~~~~~~~~~~~~~~~~~~
>>> get_info(ip=True)
'213.179.209.168' <- String
>>> get_info(port=True)
'17197' <- String
>>> get_info(ip=True, port=True)
('213.179.209.168', '17195') <- Tuple
Works by using the UbiServices User-Agent for headers
"https://www.growtopia2.com/growtopia/server_data.php"
'User-Agent': 'UbiServices_SDK_2019.Release.27_PC64_unicode_static'
'''
url = "https://www.growtopia2.com/growtopia/server_data.php"
headers = {
'User-Agent': 'UbiServices_SDK_2019.Release.27_PC64_unicode_static'
}
response = requests.get(url, headers=headers)
if(ip==True and port==True):
return str(response.content)[9:24], str(response.content)[33:38]
elif(ip == True):
return str(response.content)[9:24]
elif(port == True):
return str(response.content)[33:38]
def usr_count():
'''
ONLINE USER COUNT
~~~~~~~~~~~~~
Returns online players for growtopia
will return incorrect value if player count goes over 100k
'''
url = "https://growtopiagame.com/detail"
response = requests.get(url)
#this is beyond stupid btw and i cba to fix it
return int(str(response.content)[18:23])
def server_status(monitoring = False):
'''
~~~~~~~~~~~~~~~~
Returns False If server is down
Returns True If server is up
Auto monitors server every 10 seconds if monitoring is True
Server is considered to be down if playercount is lower than 130, due to devs
(and server monitors?) showing up as online players
'''
while(monitoring == True):
#usually there are some devs working on the game at any point when server is 'down'
if(usr_count()<130):
return False
else:
return True
time.sleep(10)
else:
if(usr_count()<130):
return False
else:
return True