-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·131 lines (97 loc) · 3.06 KB
/
index.js
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
const net = require('net')
const PacketReader = require('./src/network/PacketReader')
const PacketWriter = require('./src/network/PacketWriter')
const realm = require('./src/network/realm')
const proxy = require('./src/network/proxy')
const OpCodes = require('./src/constants/OpCodes')
const handler = require('./src/handlers')
const REALM_PORT = 9100
const PROXY_PORT = 9090
const WORLD_PORT = 8100
const CLIENT_VERSION = 3368
const realmServer = new net.Server()
realmServer.listen(REALM_PORT, function() {
console.log('realm', `listening on socket localhost:${REALM_PORT}`)
const proxyServer = new net.Server()
proxyServer.listen(PROXY_PORT, function() {
console.log('proxy', `listening on socket localhost:${PROXY_PORT}`)
})
proxyServer.on('connection', function(socket) {
console.log('proxy', 'A new connection has been established')
socket.on('data', function(chunk) {
console.log('proxy', 'data', chunk)
})
socket.on('error', function(err) {
console.log('proxy', 'error', err)
})
socket.on('timeout', function() {
console.log('proxy', 'timeout')
})
socket.on('close', function() {
console.log('proxy', 'close')
})
proxy(socket)
})
})
realmServer.on('connection', function(socket) {
console.log('realm', 'A new connection has been established')
socket.on('data', function(chunk) {
console.log('realm', 'data', chunk)
})
socket.on('error', function(err) {
console.log('realm', 'error', err)
})
socket.on('timeout', function() {
console.log('realm', 'timeout')
})
socket.on('close', function() {
console.log('realm', 'close')
})
realm(socket)
})
const worldServer = new net.Server()
worldServer.listen(WORLD_PORT, function() {
console.log(`world listening on socket localhost:${WORLD_PORT}`)
})
worldServer.on('connection', function(socket) {
console.log('world', 'A new connection has been established.')
const packetWriter = new PacketWriter(OpCodes.SMSG_AUTH_CHALLENGE)
packetWriter.writeUInt8(0)
packetWriter.writeUInt8(0)
packetWriter.writeUInt8(0)
packetWriter.writeUInt8(0)
packetWriter.writeUInt8(0)
packetWriter.writeUInt8(0)
socket.write(packetWriter.readDataToSend())
const world = {
send(packetWriter) {
console.log(
'world',
'send',
packetWriter.opcode,
OpCodes.getByUpCode(packetWriter.opcode)
)
socket.write(packetWriter.readDataToSend())
}
}
socket.on('data', function(buffer) {
console.log('world', 'data', buffer)
const packetReader = new PacketReader(buffer)
const opCode = OpCodes.getByUpCode(packetReader.opcode)
if (opCode) {
console.log('world', 'received OpCode', packetReader.opcode, opCode)
} else {
console.log('world', 'unknown OpCode', packetReader.opcode)
}
handler(packetReader, world)
})
socket.on('timeout', function() {
console.log('world', 'timeout')
})
socket.on('close', function() {
console.log('world', 'close')
})
socket.on('error', function(err) {
console.log('world', 'error', err)
})
})