Skip to content

Commit 219952c

Browse files
committed
minecraft premium account support
1 parent 655eeb1 commit 219952c

File tree

4 files changed

+111
-82
lines changed

4 files changed

+111
-82
lines changed

src/client/scripts/Setup.js

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { BlockBreak } from "./BlockBreak.js";
1515
import { BlockPlace } from "./BlockPlace.js";
1616
import { EventHandler } from "./EventHandler.js";
1717

18-
function Setup(game) {
18+
function Setup(game, cb) {
1919
game.canvas = document.querySelector("#c");
2020
game.pcanvas = document.querySelector("#c_player");
2121
game.renderer = new THREE.WebGLRenderer({
@@ -35,50 +35,54 @@ function Setup(game) {
3535
game.stats.showPanel(0);
3636
document.body.appendChild(game.stats.dom);
3737
game.distanceBasedFog = new DistanceBasedFog(game);
38-
UrlParams(game);
39-
console.warn(gpuInfo());
40-
game.socket = io({
41-
query: {
42-
nick: game.nick,
43-
server: game.server,
44-
port: game.serverPort,
45-
},
46-
});
47-
game.pii = new PlayerInInventory(game);
48-
game.bb = new BlockBreak(game);
49-
game.bp = new BlockPlace(game);
50-
game.world = new World(game);
51-
game.ent = new Entities(game);
52-
game.chat = new Chat(game);
53-
game.inv_bar = new InventoryBar(game);
54-
game.eh = new EventHandler(game);
55-
game.distanceBasedFog.addShaderToMaterial(game.world.material);
56-
var gui = new dat.GUI();
57-
game.params = {
58-
chunkdist: 3,
59-
};
60-
game.distanceBasedFog.farnear.x = (game.params.chunkdist - 1) * 16;
61-
game.distanceBasedFog.farnear.y = game.params.chunkdist * 16;
62-
gui.add(game.world.material, "wireframe").name("Wireframe").listen();
63-
var chunkDist = gui
64-
.add(game.params, "chunkdist", 0, 10, 1)
65-
.name("Render distance")
66-
.listen();
67-
chunkDist.onChange(function (val) {
68-
game.distanceBasedFog.farnear.x = (val - 1) * 16;
69-
game.distanceBasedFog.farnear.y = val * 16;
70-
console.log(val);
71-
});
72-
game.playerImpulse = function () {
73-
var to = {
74-
x: game.playerPos[0],
75-
y: game.playerPos[1] + game.headHeight,
76-
z: game.playerPos[2],
38+
UrlParams(game, (password) => {
39+
console.warn(gpuInfo());
40+
game.socket = io({
41+
query: {
42+
nick: game.nick,
43+
server: game.server,
44+
port: game.serverPort,
45+
password,
46+
premium: game.premium,
47+
},
48+
});
49+
game.pii = new PlayerInInventory(game);
50+
game.bb = new BlockBreak(game);
51+
game.bp = new BlockPlace(game);
52+
game.world = new World(game);
53+
game.ent = new Entities(game);
54+
game.chat = new Chat(game);
55+
game.inv_bar = new InventoryBar(game);
56+
game.eh = new EventHandler(game);
57+
game.distanceBasedFog.addShaderToMaterial(game.world.material);
58+
var gui = new dat.GUI();
59+
game.params = {
60+
chunkdist: 3,
7761
};
78-
new TWEEN.Tween(game.camera.position)
79-
.to(to, 100)
80-
.easing(TWEEN.Easing.Quadratic.Out)
81-
.start();
82-
};
62+
game.distanceBasedFog.farnear.x = (game.params.chunkdist - 1) * 16;
63+
game.distanceBasedFog.farnear.y = game.params.chunkdist * 16;
64+
gui.add(game.world.material, "wireframe").name("Wireframe").listen();
65+
var chunkDist = gui
66+
.add(game.params, "chunkdist", 0, 10, 1)
67+
.name("Render distance")
68+
.listen();
69+
chunkDist.onChange(function (val) {
70+
game.distanceBasedFog.farnear.x = (val - 1) * 16;
71+
game.distanceBasedFog.farnear.y = val * 16;
72+
console.log(val);
73+
});
74+
game.playerImpulse = function () {
75+
var to = {
76+
x: game.playerPos[0],
77+
y: game.playerPos[1] + game.headHeight,
78+
z: game.playerPos[2],
79+
};
80+
new TWEEN.Tween(game.camera.position)
81+
.to(to, 100)
82+
.easing(TWEEN.Easing.Quadratic.Out)
83+
.start();
84+
};
85+
cb();
86+
});
8387
}
8488
export { Setup };

src/client/scripts/UrlParams.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
var UrlParams = function (game) {
1+
import swal from "sweetalert";
2+
3+
var UrlParams = function (game, cb) {
24
var nameList = [
35
"Time",
46
"Past",
@@ -180,6 +182,7 @@ var UrlParams = function (game) {
180182
game.nick = new URL(document.location).searchParams.get("nick");
181183
game.server = new URL(document.location).searchParams.get("server");
182184
game.serverPort = new URL(document.location).searchParams.get("port");
185+
game.premium = new URL(document.location).searchParams.get("premium");
183186
var reload = false;
184187
if (game.nick === "" || game.nick === null) {
185188
reload = true;
@@ -193,8 +196,26 @@ var UrlParams = function (game) {
193196
reload = true;
194197
game.serverPort = "25565";
195198
}
199+
if (game.premium === "" || game.premium === null) {
200+
reload = true;
201+
game.premium = "false";
202+
}
196203
if (reload) {
197-
document.location.href = `?server=${game.server}&port=${game.serverPort}&nick=${game.nick}`;
204+
document.location.href = `?server=${game.server}&port=${game.serverPort}&nick=${game.nick}&premium=${game.premium}`;
205+
} else {
206+
if (game.premium === "true") {
207+
swal({
208+
text: "Enter password for premium account",
209+
content: "input",
210+
button: {
211+
text: "Login",
212+
},
213+
}).then((password) => {
214+
cb(password);
215+
});
216+
} else {
217+
cb(null);
218+
}
198219
}
199220
};
200221

src/client/scripts/index.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ import { Setup } from "./Setup.js";
77
class Game {
88
constructor() {
99
this.al = new AssetLoader(() => {
10-
this.init();
10+
if (PRODUCTION) {
11+
console.log("Running in production mode");
12+
} else {
13+
console.log("Running in development mode");
14+
}
15+
this.fov = {
16+
normal: 70,
17+
sprint: 85,
18+
};
19+
this.toxelSize = 27;
20+
this.dimension = null;
21+
this.flying = false;
22+
this.playerPos = [0, 0, 0];
23+
this.dimBg = {
24+
"minecraft:overworld": [165 / 255, 192 / 255, 254 / 255],
25+
"minecraft:the_end": [1 / 255, 20 / 255, 51 / 255],
26+
"minecraft:the_nether": [133 / 255, 40 / 255, 15 / 255],
27+
"minecraft:end": [1 / 255, 20 / 255, 51 / 255],
28+
"minecraft:nether": [133 / 255, 40 / 255, 15 / 255],
29+
};
30+
this.headHeight = 17;
31+
32+
Setup(this, () => {
33+
this.init();
34+
});
1135
});
1236
return;
1337
}
1438
init() {
15-
if (PRODUCTION) {
16-
console.log("Running in production mode");
17-
} else {
18-
console.log("Running in development mode");
19-
}
20-
this.fov = {
21-
normal: 70,
22-
sprint: 85,
23-
};
24-
this.toxelSize = 27;
25-
this.dimension = null;
26-
this.flying = false;
27-
this.playerPos = [0, 0, 0];
28-
this.dimBg = {
29-
"minecraft:overworld": [165 / 255, 192 / 255, 254 / 255],
30-
"minecraft:the_end": [1 / 255, 20 / 255, 51 / 255],
31-
"minecraft:the_nether": [133 / 255, 40 / 255, 15 / 255],
32-
"minecraft:end": [1 / 255, 20 / 255, 51 / 255],
33-
"minecraft:nether": [133 / 255, 40 / 255, 15 / 255],
34-
};
35-
this.headHeight = 17;
36-
37-
Setup(this);
38-
3939
this.socket.on("connect", () => {
4040
console.log("Connected to server!");
4141
$(".loadingText").text("Joining server...");

src/index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ io.sockets.on("connection", function (socket) {
4545
port: query.port,
4646
username: query.nick,
4747
version: version,
48+
password: query.premium === "true" ? query.password : undefined,
4849
});
4950
botByNick[query.nick] = bot;
5051
bot._client.on("map_chunk", function (packet) {
@@ -75,17 +76,20 @@ io.sockets.on("connection", function (socket) {
7576
socket.emit("kicked", reason);
7677
});
7778
bot.on("message", function (msg) {
78-
let message = msg.extra[0].text;
79+
console.log(JSON.stringify(msg));
80+
if (msg.extra != undefined) {
81+
let message = msg.extra[0].text;
7982

80-
const replacements = [
81-
[/&/g, "&"],
82-
[/</g, "&lt;"],
83-
[/>/g, "&gt;"],
84-
[/"/g, "&quot;"],
85-
];
86-
for (const replacement of replacements)
87-
message = message.replace(replacement[0], replacement[1]);
88-
msg.extra[0].text = message;
83+
const replacements = [
84+
[/&/g, "&amp;"],
85+
[/</g, "&lt;"],
86+
[/>/g, "&gt;"],
87+
[/"/g, "&quot;"],
88+
];
89+
for (const replacement of replacements)
90+
message = message.replace(replacement[0], replacement[1]);
91+
msg.extra[0].text = message;
92+
}
8993

9094
socket.emit("msg", convert.toHtml(msg.toAnsi()));
9195
});

0 commit comments

Comments
 (0)