-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMasterServer.py
101 lines (73 loc) · 5.05 KB
/
MasterServer.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
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
import httplib, urllib, re, sys, logging
from phpserialize import *
class MasterServer:
MASTERHOST = "masterserver.savage2.s2games.com"
MASTERURL = "/irc_updater/irc_requester.php"
MASTERSTAT = "188.40.92.72"
headers = {}
def __init__(self):
self.headers = {
"User-Agent": "PHP Script",
"Content-Type": "application/x-www-form-urlencoded"
}
def getStatistics (self, *args):
stub = "&account_id[%s]=%s"
lookup = ""
i = 0
for id in args:
lookup = lookup + (stub % (i, id))
i = i + 1
return self.decode (self.query ("f=get_all_stats%s" % lookup))
#Only used this to populate new ladder, but Iam leaving it in for historical purposes
def getName (self, *args):
stub = "&account_id[%s]=%s"
lookup = ""
i = 0
for id in args:
lookup = lookup + (stub % (i, id))
i = i + 1
return self.decode (self.query ("f=id2nick&account_id%s" % lookup))
def getAccount (self, nick):
stub = "&nickname[%s]=%s"
lookup = ""
return self.decode (self.query ("f=nick2id&nickname[0]=%s" % nick))
def getServer (self, login, lpass, broadcast, *args):
if broadcast == 2:
return self.decode (self.queryserver ("f=set_online&login=%s&pass=%s" % (login, lpass)))
if broadcast == 1:
return self.decode (self.queryserver ("f=set_online&pub=NA&login=%s&pass=%s" % (login, lpass)))
def decode (self, response):
return loads(response, object_hook=phpobject)
def query (self, params):
conn = httplib.HTTPConnection (self.MASTERHOST)
conn.request ("POST", self.MASTERURL, params, self.headers)
response = conn.getresponse()
if response.status <> 200:
return None
data = response.read()
conn.close()
#print params
#print data
return data
def queryserver (self, params):
url = "/irc_updater/svr_request_pub.php"
conn = httplib.HTTPConnection (self.MASTERHOST)
conn.request ("POST", url, params, self.headers)
response = conn.getresponse()
if response.status <> 200:
return None
data = response.read()
conn.close()
#print data
return data
if __name__ == '__main__':
#linestring = open('unsent_000046.txt', 'r').read()
ms = MasterServer()
#print ms.getStatistics(251700)
#print ms.getStatistics(251700,251701)
#ms.getName(309106)
"""
{'all_stats': {251700: {'demo': 1, 'overall_r': '1218', 'gold': '3771986', 'deaths': '14350', 'razed': '948', 'c_d_conns': '0', 'souls': '239', 'c_hp_repaired': '0', 'c_buffs': '238', 'c_secs': '5782', 'c_hp_healed': '7473', 'clan_img': 'png', 'c_winstreak': '0', 'earned_exp': '1815522', 'malphas': '2', 'lf': '0', 'bdmg': '4175764', 'c_gold': '263480', 'c_debuffs': '170', 'c_orders': '91', 'res': '457', 'c_losses': '2', 'c_exp': '10187', 'c_pdmg': '4446', 'c_wins': '2', 'c_kills': '17', 'total_secs': '1199039', 'revenant': '2', 'account_id': '251700', 'kills': '12685', 'cr_fk': '0.00', 'c_assists': '0', 'hp_repaired': '677835', 'npc': '906', 'clan_name': 'Heroes-of-Newerth', 'c_builds': '59', 'assists': '14052', 'c_swtch': '0', 'c_razed': '47', 'd_conns': '166', 'clan_tag': 'HoN', 'swtch': '1', 'level': '43', 'wins': '374', 'losses': '473', 'c_earned_exp': '9226', 'pdmg': '7915208', 'secs': '1199039', 'devourer': '2', 'karma': '78', 'exp': '1987781', 'hp_healed': '207573', 'sf': '118'}}}
{'all_stats': {251700: {'demo': 1, 'overall_r': '1218', 'gold': '3771986', 'deaths': '14350', 'razed': '948', 'c_d_conns': '0', 'souls': '239', 'c_hp_repaired': '0', 'c_buffs': '238', 'c_secs': '5782', 'c_hp_healed': '7473', 'clan_img': 'png', 'c_winstreak': '0', 'earned_exp': '1815522', 'malphas': '2', 'lf': '0', 'bdmg': '4175764', 'c_gold': '263480', 'c_debuffs': '170', 'c_orders': '91', 'res': '457', 'c_losses': '2', 'c_exp': '10187', 'c_pdmg': '4446', 'c_wins': '2', 'c_kills': '17', 'total_secs': '1199039', 'revenant': '2', 'account_id': '251700', 'kills': '12685', 'cr_fk': '0.00', 'c_assists': '0', 'hp_repaired': '677835', 'npc': '906', 'clan_name': 'Heroes-of-Newerth', 'c_builds': '59', 'assists': '14052', 'c_swtch': '0', 'c_razed': '47', 'd_conns': '166', 'clan_tag': 'HoN', 'swtch': '1', 'level': '43', 'wins': '374', 'losses': '473', 'c_earned_exp': '9226', 'pdmg': '7915208', 'secs': '1199039', 'devourer': '2', 'karma': '78', 'exp': '1987781', 'hp_healed': '207573', 'sf': '118'}, 251701: {'demo': 1, 'overall_r': '0', 'gold': '5071', 'deaths': '37', 'razed': '0', 'c_d_conns': '0', 'souls': '0', 'c_hp_repaired': '0', 'c_buffs': '0', 'c_secs': '0', 'c_hp_healed': '0', 'clan_img': None, 'c_winstreak': '0', 'earned_exp': '4330', 'malphas': '0', 'lf': '0', 'bdmg': '2946', 'c_gold': '0', 'c_debuffs': '0', 'c_orders': '0', 'res': '1', 'c_losses': '0', 'c_exp': '0', 'c_pdmg': '0', 'c_wins': '0', 'c_kills': '0', 'total_secs': '4571', 'revenant': '0', 'account_id': '251701', 'kills': '14', 'cr_fk': '0.00', 'c_assists': '0', 'hp_repaired': '18013', 'npc': '1', 'clan_name': None, 'c_builds': '0', 'assists': '19', 'c_swtch': '0', 'c_razed': '0', 'd_conns': '3', 'clan_tag': None, 'swtch': '0', 'level': '1', 'wins': '1', 'losses': '3', 'c_earned_exp': '0', 'pdmg': '8599', 'secs': '4571', 'devourer': '0', 'karma': '0', 'exp': '4664', 'hp_healed': '3872', 'sf': '43'}}}
"""