-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdofus.coffee
More file actions
185 lines (131 loc) · 4.51 KB
/
dofus.coffee
File metadata and controls
185 lines (131 loc) · 4.51 KB
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
182
183
184
185
###
Ce fichier est une partie du projet Dofus.coffee
Dofus.coffee est un logiciel libre : vous pouvez redistribué et/ou modifié
les sources sous les thermes de la General Public License (GNU) publié par
la Free Software Foundation, ou bien de la version 3 de la license ou tout
autre version antérieur.
Dofus.coffee est distribué dans la volonté d'être utile SANS AUCUNE GARANTIE,
néanmoins en aucun cas il ne doit pas ETRE UTILISE OU DISTRIBUE A DES FINS COMMERCIALES,
voir la General Public License (GNU) pour plus de détails.
Un copie de la General Public License (GNU) est distribué avec le logiciel Dofus.coffee
En cas contraire visitez : <http://www.gnu.org/licenses/>.
Dofus.coffee Copyright (C) 2010 NightWolf & Dofus.coffee Team — Tous droits réservés.
Créé par NightWolf
###
AUTH_ADRESS = "127.0.0.1"
AUTH_PORT = 444
DOFUS_VERSION = "1.29.1"
DATABASE_USER = "root"
DATABASE_PASSWORD = ""
DATABASE_DB = "arkalia_realm"
###
Network class
###
class AuthNetServer
constructor: (@ip, @port) ->
net = require('net')
@Server = net.createServer (event) =>
this.onConnection(event)
Start: () ->
@Server.listen(AUTH_PORT, AUTH_ADRESS)
onConnection: (event) ->
console.log('New input connection on authserver')
event.pipe(event);
client = new AuthNetClient(event)
class AuthNetClient
constructor: (@socket) ->
@state = 0
@encryptKey = GenerateString(32)
@socket.on 'close', (event) =>
this.onClose(event)
@socket.on 'data', (event) =>
this.onReceiveData(event)
@Send('HC' + @encryptKey)
Send: (packet) ->
console.log('Send packet => ' + packet)
@socket.write(packet + "\x00")
onReceiveData: (event) ->
data = CleanPacket(event.toString())
@handlePacket(x) for x in data
onClose: (event) ->
console.log('Client disconnected')
handlePacket: (packet) ->
if packet != "" and packet != "Af"
console.log('Received packet <= ' + packet)
switch @state
when 0
@checkVersion(packet)
when 1
@checkAccount(packet)
checkVersion: (packet) -> #Check client version
if packet == DOFUS_VERSION
@state = 1
else
@state = -1
@Send('AlEv' + DOFUS_VERSION)
checkAccount: (packet) -> #Check client account requested
@state = -1
data = packet.split('#1')
username = data[0]
password = data[1]
###
Client methods
###
class Account
constructor: () ->
@id = -1
@username = ""
@password = ""
GetMd5Password: (sipher) ->
@FindByUsername: (username, callback) ->
query = "SELECT * FROM accounts WHERE Username='" + username + "'"
account = null
MySQL.query(query).addListener 'row', (r) =>
account = new Account()
account.id = r.Id
account.username = r.Username
account.password = r.Password
callback.call(callback, account)
###
Utilities methods
###
UtilsHash = 'azertyuiopqsdfghjklmwxcvbn'
RandNumber = (min, max) ->
return Math.floor(Math.random() * (max - min + 1)) + min
GenerateString = (lenght) ->
rndStr = ""
rndStr += UtilsHash.charAt(RandNumber(0, 25)) for x in [1..lenght]
return rndStr
CleanPacket = (packet) ->
return packet.replace("\x0a", "").replace("\n", "").split("\x00")
###
Database Methods
###
ConnectDatabase = () ->
MySQL.auto_prepare = true;
MySQL.auth(DATABASE_DB, DATABASE_USER, DATABASE_PASSWORD);
console.log('Connected to database !')
###
Start Program Methods
###
AuthServer = null
MySQL = require 'mysql'
Main = () ->
WritePlatformInformations()
StartDatabaseServices()
StartNetWorkServices()
WritePlatformInformations = () ->
console.log("Your node.js details:")
console.log("Version: " + process.version)
console.log("Platform: " + process.platform)
console.log("Architecture: " + process.arch)
StartDatabaseServices = () ->
console.log('Starting database services ...')
MySQL = require('mysql-native').createTCPClient();
ConnectDatabase()
#MySQLProvider = mysql.createConnection({host : '127.0.0.1', user : 'root',password : '', })
StartNetWorkServices = () ->
console.log('Starting network services ...')
AuthServer = new AuthNetServer(AUTH_ADRESS, AUTH_PORT)
AuthServer.Start()
Main()#Need to start emulator