-
Notifications
You must be signed in to change notification settings - Fork 2
/
pommcheat.py
181 lines (161 loc) · 6.3 KB
/
pommcheat.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/home/user/opt/bin/python2.6
# CHANGE THE ABOVE LINE TO THE LOCATION OF YOUR PYTHON EXECUTABLE!
class Point:
"""A simple x,y point that allows Point - Point subtraction"""
def __init__(self, x, y):
self.x, self.y = x, y
def __div__(self, p):
return Point(self.x / p.x, self.y / p.y)
def __mul__(self, p):
return Point(self.x * p.x, self.y * p.y)
def __sub__(self, p):
return Point(self.x - p.x, self.y - p.y)
import urllib, re, os, cgi, cgitb, json, sqlite3
mapURL = "http://howow.linebr.com/pomm/pomm_run.php"
# http://www.conquestofthehorde.com/components/pomm/pomm.php
# http://www.eyes-of-eternity.exano.net/components/pomm/pomm.php?rid=1
# http://wemilktaurens.site88.net/components/pomm/pomm.php
# http://litvivan.game-server.cc/wow/components/pomm/pomm.php
# http://213.141.140.82/wow/components/pomm/pomm.php
bracketRegex = "(\[.*\])"
MAP_WIDTH = 784.00
MAP_HEIGHT = 525.00
ZONE_RATIO_X = 11.02
ZONE_RATIO_Y = 6.68
CHARSET = 'utf8'
DATABASE = './pommcheat.db'
POINT_HTML = '''<a href="#"><img src="img/%s_point.gif" style="position: absolute; left: %spx; top: %spx;" '''
POINT_HTML += '''onmousemove="tip('%s', '%s', '<img src=\\'img/%d-%d.gif\\' style=\\'float: center;\\'/>'''
POINT_HTML += '''<img src=\\'img/%d.gif\\' style=\\'float: center;\\'/><br>%s<br>%s<br>%s');" onmouseout="h_tip();"'''
POINT_HTML += '''onclick="javascript:document.getElementById('charName').value='%s'; reset();" /></a>\n'''
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
conn = sqlite3.connect(DATABASE)
conn.row_factory = dict_factory
cur = conn.cursor()
def TranslatePoint(point, zone):
cur.execute('select parent, x_offset, y_offset from zones where name = ?', (zone, ))
zoneData = cur.fetchone()
if zoneData['parent'] is None:
cur.execute('select x, y from zones where name = ?', (zone, ))
dimension = cur.fetchone()
return Point(((point.x / 100) * dimension['x']), ((point.y / 100) * dimension['y']))
return TranslatePoint(point, zoneData['parent']) - Point(zoneData['x_offset'], zoneData['y_offset'])
def WebMapCoordsToZoneCoords2(zone, x, y):
# Coordinates are in proportion to the webmap, get them on a 100,100 scale
# and make them a Point while we're at it
position = Point(x * (100 / MAP_WIDTH), y * (100 / MAP_HEIGHT))
# Get the dimensions of the zone and scale to percentage
cur.execute('select x, y from zones where name = ?', (zone, ))
z = cur.fetchone()
zoneSize = Point(z['x'], z['y']) / Point(100, 100)
# Account for zone, continent, and 'world' offsets, divide by zone's size to get percentage
# Then multiple by zone mapsize to get pixel location
return (TranslatePoint(position, zone) / zoneSize) * Point(ZONE_RATIO_X, ZONE_RATIO_Y)
def parseQueryString():
"""Pull char and zone parameters from query string"""
qs = cgi.FieldStorage()
return({'char': qs.getvalue('char'), 'zone': qs.getvalue('zone')})
def parsePlayerData():
"""Pull player data from target server, format as valid JSON, return parsed JSON"""
try:
rawPlayerData = str(re.findall(bracketRegex, urllib.urlopen(mapURL).read())[0])
except:
print "exception!"
rawPlayerData = None
if rawPlayerData is not None:
fixedPlayerData = re.sub("'(\d+)'", '\g<1>', rawPlayerData).replace("\\'", "").replace("'", '"')
return json.loads(fixedPlayerData, 'latin1')
def getPlayersForZone(players, zone):
"""Filters player list by 'zone' attribute"""
player = filter(lambda p: p['zone'] != u'Unknown' and p['name'] != u'Dead', players)
if zone is None: return players
return filter(lambda p: p['zone'] == zone, players)
# Determine if the player is Horde
def isHorde(player):
return (int(player['race']) in (2, 5, 6, 8, 10))
# Get string name of race index
def getRace(race):
races = {1: 'Human',
2: 'Orc',
3: 'Dwarf',
4: 'Night Elf',
5: 'Undead',
6: 'Tauren',
7: 'Gnome',
8: 'Troll',
10: 'Blood Elf',
11: 'Draenei'}
if (race in races.keys()):
return races[race]
else:
return "RaceErr"
# Get string name of class index
def getClass(cl):
classes = {1: 'Warrior',
2: 'Paladin',
3: 'Hunter',
4: 'Rogue',
5: 'Priest',
7: 'Shaman',
8: 'Mage',
9: 'Warlock',
11: 'Druid'}
if (cl in classes.keys()):
return classes[cl]
else:
return "ClassErr"
# Generate the proper HTML for the zone <div>
def generateHTML(me, players, zone):
actualPlayers = [p for p in players if p['zone'] != u'Unknown' and p['name'] != u'Dead']
if zone is None: zone = "map"
else: zone = str(re.sub(r'\W', '', zone))
outHTML = "##" + zone + "##\n"
for p in actualPlayers:
try:
# translate the "POMM" coords to the zone
pCoords = Point(int(p['x']), int(p['y']))
if zone is not 'map': pCoords = WebMapCoordsToZoneCoords2(zone, pCoords.x, pCoords.y)
pName = p['name']
pRace = int(p['race'])
pRaceStr = getRace(pRace)
pGender = int(p['gender'])
pClass = int(p['cl'])
pClassStr = getClass(pClass)
pLevel = p['level']
# make the right point graphic and popup header style
if ((me is not None) and (pName == me)):
pStyle = "self"
elif (isHorde(p)):
pStyle = "h"
else:
pStyle = "a"
outHTML += POINT_HTML % (pStyle, pCoords.x, pCoords.y, pStyle, pName, pRace, pGender, pClass, pRaceStr, pClassStr, pLevel, pName)
except Exception, e:
print e, outHTML, "<h2>zone = '", zone, "'</h2>"
return outHTML.encode(CHARSET)
# Determine the "filter" zone from the parameters
def getZoneFromPlayer(char, players):
for p in players:
if (p['name'] == char):
return p['zone']
return None
# Main function!
def main():
print "Content-Type: text/html; charset=" + CHARSET + "\n\n"
# get either player name or zone
parameters = parseQueryString()
char, zone = parameters['char'], parameters['zone']
players = parsePlayerData()
players = filter(lambda p: p['zone'] != u'Unknown' and p['name'] != u'Dead', players)
if char is not None:
char = char.decode('latin1')
zone = getZoneFromPlayer(char, players)
if zone is not None:
players = filter(lambda p: p['zone'] == zone, players)
print generateHTML(char, players, zone)
conn.close()
main()