-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-handler-old.py
73 lines (51 loc) · 1.6 KB
/
json-handler-old.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
import json
import sys
from mod_python import Session
from mod_python import util
from mod_python import apache
#our files
import db
#TODO Sanitize inputs
def getWorldData(data):
cursor = db.cursor()
cursor.execute("select worldName, worldSizeX, worldSizeY, worldSizeZ, \
worldWrapX, worldWrapY, worldSeaLevel \
from worldData where worldId = %s", (data['worldId'],))
row = cursor.fetchone()
if row == None:
print "Did not find worldData record, exiting."
sys.exit(1)
self.lengthX = row["worldSizeX"]
self.lengthY = row["worldSizeY"]
self.wrapX = True if row["worldWrapX"] == 1 else False
self.wrapY = True if row["worldWrapY"] == 1 else False
cursor.close()
def index(req):
session = Session.Session(req)
#try:
#session['hits'] += 1
#except:
#session['hits'] = 1
req.content_type = 'text/plain'
data = util.FieldStorage(req)
if 'callback' not in data:
msg = "Not called with jsonp callback"
apache.log_error(msg)
req.write(msg)
elif 'function' not in data:
msg = "Not called with a function"
apache.log_error(msg)
req.write(msg)
elif data['function'] == 'getLocation':
req.write(data['callback'] +'({"userX":0, "userY":0, "userZ":0})');
elif data['function'] == 'getWorldData':
getWorldData(data)
else:
msg = "Not a recognized function: " + data['function']
apache.log_error(msg)
req.write(msg)
##req.write("Hits: %d\n" % session['hits'])
#req.write(data['callback'] +'({"data":"fjkdlskkk"})');
#apache.log_error("Callback: " + str(data))
session.save()
return None