-
Notifications
You must be signed in to change notification settings - Fork 0
/
Proxy.js
195 lines (183 loc) · 5.42 KB
/
Proxy.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
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
186
187
188
189
190
191
192
193
194
195
const mc = require("minecraft-protocol");
const states = mc.states;
const hostile = require("hostile");
const chalk = require("chalk");
class Proxy {
constructor(username, password, auth, port, hypixelmods) {
this.username = username;
this.password = password;
this.auth = auth || "mojang";
this.port = port || 25566;
this.hypixelmods = hypixelmods || false;
}
start = () => {
const srv = mc.createServer({
"online-mode": true,
host: "localhost",
port: this.port,
keepAlive: false,
version: "1.8.9",
});
const data = {
username: this.username,
password: this.password,
auth: this.auth,
hypixelmods: this.hypixelmods,
};
if (data.hypixelmods) {
console.log(
chalk.yellowBright(
"Keep in mind, you must run as administrator for hypixel mods to work."
)
);
hostile.set("127.0.0.1", "hypixel.net.hypixel.io");
console.log(chalk.greenBright("[+] Added Hypixel Line To Host File"));
console.log(chalk.greenBright("!IMPORTANT! Join hypixel.net.hypixel.io"));
}
console.log(chalk.greenBright("[+] Proxy has been started."));
srv.on("login", function (client) {
console.log(client.profile.properties);
const addr = client.socket.remoteAddress;
console.log("Incoming connection", "(" + addr + ")");
let endedClient = false;
let endedTargetClient = false;
client.on("end", function () {
endedClient = true;
console.log("Connection closed by client", "(" + addr + ")");
if (!endedTargetClient) {
targetClient.end("End");
}
});
client.on("error", function (err) {
endedClient = true;
console.log("Connection error by client", "(" + addr + ")");
console.log(err.stack);
if (!endedTargetClient) {
targetClient.end("Error");
}
});
const targetClient = mc.createClient({
host: "hypixel.net",
port: 25565,
username: data.username,
keepAlive: false,
password: data.password,
auth: data.auth,
version: "1.8.9",
});
client.on("packet", function (data, meta) {
if (targetClient.state === states.PLAY && meta.state === states.PLAY) {
if (!endedTargetClient) {
targetClient.write(meta.name, data);
}
}
});
targetClient.on("packet", function (data, meta) {
if (meta.name === "custom_payload" && data.channel === "MC|Brand") {
data.data = Buffer.from(
"<XeBungee (git:XeBungee-Bootstrap:1.16-R0.5-SNAPSHOT:a2e1df4)"
);
}
if (meta.state === states.PLAY && client.state === states.PLAY) {
if (!endedClient) {
client.write(meta.name, data);
if (meta.name === "login") {
}
if (meta.name === "set_compression") {
client.compressionThreshold = data.threshold;
}
}
}
});
const bufferEqual = require("buffer-equal");
targetClient.on("raw", function (buffer, meta) {
if (client.state !== states.PLAY || meta.state !== states.PLAY) {
return;
}
const packetData =
targetClient.deserializer.parsePacketBuffer(buffer).data.params;
const packetBuff = client.serializer.createPacketBuffer({
name: meta.name,
params: packetData,
});
if (!bufferEqual(buffer, packetBuff)) {
console.log(
"client<-server: Error in packet " + meta.state + "." + meta.name
);
console.log("received buffer", buffer.toString("hex"));
console.log("produced buffer", packetBuff.toString("hex"));
console.log("received length", buffer.length);
console.log("produced length", packetBuff.length);
}
});
client.on("raw", function (buffer, meta) {
if (meta.state !== states.PLAY || targetClient.state !== states.PLAY) {
return;
}
const packetData =
client.deserializer.parsePacketBuffer(buffer).data.params;
const packetBuff = targetClient.serializer.createPacketBuffer({
name: meta.name,
params: packetData,
});
if (!bufferEqual(buffer, packetBuff)) {
console.log(
"client->server: Error in packet " + meta.state + "." + meta.name
);
console.log("received buffer", buffer.toString("hex"));
console.log("produced buffer", packetBuff.toString("hex"));
console.log("received length", buffer.length);
console.log("produced length", packetBuff.length);
}
});
targetClient.on("end", function () {
endedTargetClient = true;
console.log("Connection closed by server", "(" + addr + ")");
if (!endedClient) {
client.end("End");
}
});
targetClient.on("error", function (err) {
endedTargetClient = true;
console.log("Connection error by server", "(" + addr + ") ", err);
console.log(err.stack);
if (!endedClient) {
client.end("Error");
}
});
});
async function exitHandler(evtOrExitCodeOrError) {
try {
if (data.hypixelmods) {
return await undoHosts();
}
console.log(chalk.redBright("[+] Proxy has been stopped."));
} catch (e) {
console.error("EXIT HANDLER ERROR", e);
}
process.exit(isNaN(+evtOrExitCodeOrError) ? 1 : +evtOrExitCodeOrError);
}
[
"beforeExit",
"uncaughtException",
"unhandledRejection",
"SIGHUP",
"SIGINT",
"SIGQUIT",
"SIGILL",
"SIGTRAP",
"SIGABRT",
"SIGBUS",
"SIGFPE",
"SIGUSR1",
"SIGSEGV",
"SIGUSR2",
"SIGTERM",
].forEach((evt) => process.on(evt, exitHandler));
async function undoHosts() {
hostile.remove("127.0.0.1", "hypixel.net.hypixel.io");
console.log(chalk.redBright("[+] Removed Hypixel Line From Host File"));
}
};
}
module.exports = Proxy;