-
Notifications
You must be signed in to change notification settings - Fork 0
/
wurdbarfapi.coffee
82 lines (76 loc) · 2.49 KB
/
wurdbarfapi.coffee
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
myWurdBarf = ($http) ->
key: null
bf: null
token: null
gameToken: null
matchToken: null
register: {}
matchmaking: {}
cipherLogin: null
cipherRegister: null
cipherMatchmaking: null
cipherMatch: null
gameData: null
userData: {}
promise: null
server: "http://api.raedixgames.com"
initialize: (rootObject) ->
rootObject.promise = $http.get(rootObject.server + "/requestkey").success((data) ->
console.log data.key
rootObject.bf = new Blowfish(data.key)
)
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"
$http.defaults.transformRequest = [(data) ->
###
The workhorse; converts an object to x-www-form-urlencoded serialization.
@param {Object} obj
@return {String}
###
param = (obj) ->
query = ""
name = undefined
value = undefined
fullSubName = undefined
subName = undefined
subValue = undefined
innerObj = undefined
i = undefined
for name of obj
value = obj[name]
if value instanceof Array
i = 0
while i < value.length
subValue = value[i]
fullSubName = name + "[" + i + "]"
innerObj = {}
innerObj[fullSubName] = subValue
query += param(innerObj) + "&"
++i
else if value instanceof Object
for subName of value
subValue = value[subName]
fullSubName = name + "[" + subName + "]"
innerObj = {}
innerObj[fullSubName] = subValue
query += param(innerObj) + "&"
else query += encodeURIComponent(name) + "=" + encodeURIComponent(value) + "&" if value isnt `undefined` and value isnt null
(if query.length then query.substr(0, query.length - 1) else query)
(if angular.isObject(data) and String(data) isnt "[object File]" then param(data) else data)
]
sendLogin: (rootObject) ->
rootObject.promise = $http.post(rootObject.server + "/login/",
encdata: rootObject.cipherLogin
).success((data) ->
console.log data
data = rootObject.bf.decrypt(data.encdata) # decrypts encdata and makes it the default data object
try
data = JSON.parse(data)
catch err
data += "}"
data = JSON.parse(data)
if data.result is "Fail"
console.log data.error
else
rootObject.token = data.token
console.log rootObject.token
)