This commit is contained in:
q13x 2023-07-02 23:08:04 -07:00
parent 36d650d948
commit dd2d8ed1cd
2 changed files with 387 additions and 232 deletions

View File

@ -36,9 +36,7 @@ Remove all the folders in `src/plugins`.
#### IMPORTANT: READ ME BEFORE USING #### IMPORTANT: READ ME BEFORE USING
It is highly suggested that you use [Resent Client](https://reslauncher.vercel.app/) if you aren't already. It provides better performance, FPS, and will allow for a more stable connection to servers. **IMPORTANT:** Although the vanilla Eaglercraft client is a safe, modified copy of Minecraft AOT-compiled to JavaScript, I cannot guarantee that you **will not get flagged by all anticheats.** While gameplay and testing has shown to be relatively stable and free of anticheat flags, more testing is needed to derive a conclusion on whether or not using EaglerProxy with EagProxyAAS is safe.
**IMPORTANT:** Although both Resent Client and the vanilla Eaglercraft client are safe modified copies of Minecraft AOT-compiled to JavaScript, I cannot guarantee that you **will not get flagged by all anticheats.** While gameplay and testing has shown to be relatively stable and free of anticheat flags, more testing is needed to derive a conclusion on whether or not using EaglerProxy with EagProxyAAS is safe.
EaglerProxy and EagProxyAAS: EaglerProxy and EagProxyAAS:

View File

@ -1,263 +1,420 @@
import { ServerGlobals } from "./types.js" import { ServerGlobals } from "./types.js";
import * as Chunk from "prismarine-chunk" import * as Chunk from "prismarine-chunk";
import * as Block from "prismarine-block" import * as Block from "prismarine-block";
import * as Registry from "prismarine-registry" import * as Registry from "prismarine-registry";
import vec3 from "vec3" import vec3 from "vec3";
import { Client } from "minecraft-protocol" import { Client } from "minecraft-protocol";
import { ClientState, ConnectionState } from "./types.js" import { ClientState, ConnectionState } from "./types.js";
import { auth, ServerDeviceCodeResponse } from "./auth.js" import { auth, ServerDeviceCodeResponse } from "./auth.js";
const { Vec3 } = vec3 as any const { Vec3 } = vec3 as any;
const Enums = PLUGIN_MANAGER.Enums const Enums = PLUGIN_MANAGER.Enums;
const Util = PLUGIN_MANAGER.Util const Util = PLUGIN_MANAGER.Util;
const MAX_LIFETIME_CONNECTED = 10 * 60 * 1000, MAX_LIFETIME_AUTH = 5 * 60 * 1000, MAX_LIFETIME_LOGIN = 1 * 60 * 1000 const MAX_LIFETIME_CONNECTED = 10 * 60 * 1000,
const REGISTRY = Registry.default('1.8.8'), McBlock = (Block as any).default('1.8.8'), LOGIN_CHUNK = generateSpawnChunk().dump() MAX_LIFETIME_AUTH = 5 * 60 * 1000,
const logger = new PLUGIN_MANAGER.Logger("PlayerHandler") MAX_LIFETIME_LOGIN = 1 * 60 * 1000;
const REGISTRY = Registry.default("1.8.8"),
McBlock = (Block as any).default("1.8.8"),
LOGIN_CHUNK = generateSpawnChunk().dump();
const logger = new PLUGIN_MANAGER.Logger("PlayerHandler");
let SERVER: ServerGlobals = null let SERVER: ServerGlobals = null;
export function setSG(svr: ServerGlobals) { export function setSG(svr: ServerGlobals) {
SERVER = svr SERVER = svr;
} }
export function disconectIdle() { export function disconectIdle() {
SERVER.players.forEach(client => { SERVER.players.forEach((client) => {
if (client.state == ConnectionState.AUTH && (Date.now() - client.lastStatusUpdate) > MAX_LIFETIME_AUTH) { if (
client.gameClient.end("Timed out waiting for user to login via Microsoft") client.state == ConnectionState.AUTH &&
} else if (client.state == ConnectionState.SUCCESS && (Date.now() - client.lastStatusUpdate) > MAX_LIFETIME_CONNECTED) { Date.now() - client.lastStatusUpdate > MAX_LIFETIME_AUTH
client.gameClient.end(Enums.ChatColor.RED + "Please enter the IP of the server you'd like to connect to in chat.") ) {
client.gameClient.end(
"Timed out waiting for user to login via Microsoft"
);
} else if (
client.state == ConnectionState.SUCCESS &&
Date.now() - client.lastStatusUpdate > MAX_LIFETIME_CONNECTED
) {
client.gameClient.end(
Enums.ChatColor.RED +
"Please enter the IP of the server you'd like to connect to in chat."
);
} }
}) });
} }
export function handleConnect(client: ClientState) { export function handleConnect(client: ClientState) {
client.gameClient.write('login', { client.gameClient.write("login", {
entityId: 1, entityId: 1,
gameMode: 2, gameMode: 2,
dimension: 0, dimension: 0,
difficulty: 1, difficulty: 1,
maxPlayers: 1, maxPlayers: 1,
levelType: 'flat', levelType: "flat",
reducedDebugInfo: false reducedDebugInfo: false,
}) });
client.gameClient.write('map_chunk', { client.gameClient.write("map_chunk", {
x: 0, x: 0,
z: 0, z: 0,
groundUp: true, groundUp: true,
bitMap: 0xFFFF, bitMap: 0xffff,
chunkData: LOGIN_CHUNK chunkData: LOGIN_CHUNK,
}) });
client.gameClient.write('position', { client.gameClient.write("position", {
x: 0, x: 0,
y: 65, y: 65,
z: 8.5, z: 8.5,
yaw: -90, yaw: -90,
pitch: 0, pitch: 0,
flags: 0x01 flags: 0x01,
}) });
client.gameClient.write('playerlist_header', { client.gameClient.write("playerlist_header", {
header: JSON.stringify({ header: JSON.stringify({
text: ` ${Enums.ChatColor.GOLD}EaglerProxy Authentication Server ` text: ` ${Enums.ChatColor.GOLD}EaglerProxy Authentication Server `,
}), }),
footer: JSON.stringify({ footer: JSON.stringify({
text: `${Enums.ChatColor.GOLD}Please wait for instructions.` text: `${Enums.ChatColor.GOLD}Please wait for instructions.`,
}) }),
}) });
onConnect(client) onConnect(client);
} }
export function awaitCommand(client: Client, filter: (msg: string) => boolean): Promise<string> { export function awaitCommand(
client: Client,
filter: (msg: string) => boolean
): Promise<string> {
return new Promise<string>((res, rej) => { return new Promise<string>((res, rej) => {
const onMsg = packet => { const onMsg = (packet) => {
if (filter(packet.message)) { if (filter(packet.message)) {
client.removeListener('chat', onMsg) client.removeListener("chat", onMsg);
client.removeListener('end', onEnd) client.removeListener("end", onEnd);
res(packet.message) res(packet.message);
} }
} };
const onEnd = () => rej("Client disconnected before promise could be resolved") const onEnd = () =>
client.on('chat', onMsg) rej("Client disconnected before promise could be resolved");
client.on('end', onEnd) client.on("chat", onMsg);
}) client.on("end", onEnd);
});
} }
export function sendMessage(client: Client, msg: string) { export function sendMessage(client: Client, msg: string) {
client.write('chat', { client.write("chat", {
message: JSON.stringify({ text: msg }), message: JSON.stringify({ text: msg }),
position: 1 position: 1,
}) });
} }
export function sendMessageWarning(client: Client, msg: string) { export function sendMessageWarning(client: Client, msg: string) {
client.write('chat', { client.write("chat", {
message: JSON.stringify({ message: JSON.stringify({
text: msg, text: msg,
color: 'yellow' color: "yellow",
}), }),
position: 1 position: 1,
}) });
} }
export function sendMessageLogin(client: Client, url: string, token: string) { export function sendMessageLogin(client: Client, url: string, token: string) {
client.write('chat', { client.write("chat", {
message: JSON.stringify({ message: JSON.stringify({
text: "Please go to ", text: "Please go to ",
color: Enums.ChatColor.RESET, color: Enums.ChatColor.RESET,
extra: [ extra: [
{ {
text: url, text: url,
color: 'gold', color: "gold",
clickEvent: { clickEvent: {
action: "open_url", action: "open_url",
value: url value: url,
}, },
hoverEvent: { hoverEvent: {
action: "show_text", action: "show_text",
value: Enums.ChatColor.GOLD + "Click to open me in a new window!" value: Enums.ChatColor.GOLD + "Click to open me in a new window!",
} },
}, },
{ {
text: " and login via the code " text: " and login via the code ",
}, },
{ {
text: token, text: token,
color: 'gold', color: "gold",
hoverEvent: { hoverEvent: {
action: "show_text", action: "show_text",
value: Enums.ChatColor.GOLD + "Click me to copy to chat to copy from there!" value:
Enums.ChatColor.GOLD +
"Click me to copy to chat to copy from there!",
}, },
clickEvent: { clickEvent: {
action: "suggest_command", action: "suggest_command",
value: token value: token,
} },
}, },
{ {
text: "." text: ".",
} },
] ],
}), }),
position: 1 position: 1,
}) });
} }
export function updateState(client: Client, newState: 'AUTH' | 'SERVER', uri?: string, code?: string) { export function updateState(
client: Client,
newState: "AUTH" | "SERVER",
uri?: string,
code?: string
) {
switch (newState) { switch (newState) {
case 'AUTH': case "AUTH":
if (code == null || uri == null) throw new Error("Missing code/uri required for title message type AUTH") if (code == null || uri == null)
client.write('playerlist_header', { throw new Error(
"Missing code/uri required for title message type AUTH"
);
client.write("playerlist_header", {
header: JSON.stringify({ header: JSON.stringify({
text: ` ${Enums.ChatColor.GOLD}EaglerProxy Authentication Server ` text: ` ${Enums.ChatColor.GOLD}EaglerProxy Authentication Server `,
}), }),
footer: JSON.stringify({ footer: JSON.stringify({
text: `${Enums.ChatColor.RED}${uri}${Enums.ChatColor.GOLD} | Code: ${Enums.ChatColor.RED}${code}` text: `${Enums.ChatColor.RED}${uri}${Enums.ChatColor.GOLD} | Code: ${Enums.ChatColor.RED}${code}`,
}) }),
}) });
break break;
case 'SERVER': case "SERVER":
client.write('playerlist_header', { client.write("playerlist_header", {
header: JSON.stringify({ header: JSON.stringify({
text: ` ${Enums.ChatColor.GOLD}EaglerProxy Authentication Server ` text: ` ${Enums.ChatColor.GOLD}EaglerProxy Authentication Server `,
}), }),
footer: JSON.stringify({ footer: JSON.stringify({
text: `${Enums.ChatColor.RED}/join <ip> [port]` text: `${Enums.ChatColor.RED}/join <ip> [port]`,
}) }),
}) });
break break;
} }
} }
export async function onConnect(client: ClientState) { export async function onConnect(client: ClientState) {
try { try {
client.state = ConnectionState.AUTH client.state = ConnectionState.AUTH;
client.lastStatusUpdate = Date.now() client.lastStatusUpdate = Date.now();
sendMessageWarning(client.gameClient, `WARNING: This proxy allows you to connect to any 1.8.9 server. Gameplay has shown no major issues, but please note that EaglercraftX may flag some anticheats while playing.`) sendMessageWarning(
await new Promise(res => setTimeout(res, 2000)) client.gameClient,
sendMessageWarning(client.gameClient, `WARNING: It is highly suggested that you turn down settings and use Resent Client, as gameplay tends to be very laggy and unplayable on low powered devices.`) `WARNING: This proxy allows you to connect to any 1.8.9 server. Gameplay has shown no major issues, but please note that EaglercraftX may flag some anticheats while playing.`
await new Promise(res => setTimeout(res, 2000)) );
sendMessageWarning(client.gameClient, `WARNING: You will be prompted to log in via Microsoft to obtain a session token necessary to join games. Any data related to your account will not be saved and for transparency reasons this proxy's source code is available on Github.`) await new Promise((res) => setTimeout(res, 2000));
await new Promise(res => setTimeout(res, 2000)) sendMessageWarning(
client.gameClient,
`WARNING: It is highly suggested that you turn down settings, as gameplay tends to be very laggy and unplayable on low powered devices.`
);
await new Promise((res) => setTimeout(res, 2000));
sendMessageWarning(
client.gameClient,
`WARNING: You will be prompted to log in via Microsoft to obtain a session token necessary to join games. Any data related to your account will not be saved and for transparency reasons this proxy's source code is available on Github.`
);
await new Promise((res) => setTimeout(res, 2000));
client.lastStatusUpdate = Date.now() client.lastStatusUpdate = Date.now();
let errored = false, savedAuth let errored = false,
const authHandler = auth(), codeCallback = (code: ServerDeviceCodeResponse) => { savedAuth;
updateState(client.gameClient, 'AUTH', code.verification_uri, code.user_code) const authHandler = auth(),
sendMessageLogin(client.gameClient, code.verification_uri, code.user_code) codeCallback = (code: ServerDeviceCodeResponse) => {
} updateState(
authHandler.once('error', err => { client.gameClient,
if (!client.gameClient.ended) client.gameClient.end(err.message) "AUTH",
errored = true code.verification_uri,
code.user_code
);
sendMessageLogin(
client.gameClient,
code.verification_uri,
code.user_code
);
};
authHandler.once("error", (err) => {
if (!client.gameClient.ended) client.gameClient.end(err.message);
errored = true;
});
if (errored) return;
authHandler.on("code", codeCallback);
await new Promise((res) =>
authHandler.once("done", (result) => {
savedAuth = result;
res(result);
}) })
if (errored) return );
authHandler.on('code', codeCallback) sendMessage(
await new Promise(res => authHandler.once('done', result => { client.gameClient,
savedAuth = result Enums.ChatColor.BRIGHT_GREEN + "Successfully logged into Minecraft!"
res(result) );
}))
sendMessage(client.gameClient, Enums.ChatColor.BRIGHT_GREEN + "Successfully logged into Minecraft!")
client.state = ConnectionState.SUCCESS client.state = ConnectionState.SUCCESS;
client.lastStatusUpdate = Date.now() client.lastStatusUpdate = Date.now();
updateState(client.gameClient, 'SERVER') updateState(client.gameClient, "SERVER");
sendMessage(client.gameClient, `Provide a server to join. ${Enums.ChatColor.GOLD}/join <ip> [port]${Enums.ChatColor.RESET}.`) sendMessage(
let host: string, port: number client.gameClient,
`Provide a server to join. ${Enums.ChatColor.GOLD}/join <ip> [port]${Enums.ChatColor.RESET}.`
);
let host: string, port: number;
while (true) { while (true) {
const msg = await awaitCommand(client.gameClient, msg => msg.startsWith("/join")), parsed = msg.split(/ /gi, 3) const msg = await awaitCommand(client.gameClient, (msg) =>
if (parsed.length < 2) sendMessage(client.gameClient, `Please provide a server to connect to. ${Enums.ChatColor.GOLD}/join <ip> [port]${Enums.ChatColor.RESET}.`) msg.startsWith("/join")
else if (parsed.length > 3 && isNaN(parseInt(parsed[2]))) sendMessage(client.gameClient, `A valid port number has to be passed! ${Enums.ChatColor.GOLD}/join <ip> [port]${Enums.ChatColor.RESET}.`) ),
parsed = msg.split(/ /gi, 3);
if (parsed.length < 2)
sendMessage(
client.gameClient,
`Please provide a server to connect to. ${Enums.ChatColor.GOLD}/join <ip> [port]${Enums.ChatColor.RESET}.`
);
else if (parsed.length > 3 && isNaN(parseInt(parsed[2])))
sendMessage(
client.gameClient,
`A valid port number has to be passed! ${Enums.ChatColor.GOLD}/join <ip> [port]${Enums.ChatColor.RESET}.`
);
else { else {
host = parsed[1] host = parsed[1];
if (parsed.length > 3) port = parseInt(parsed[2]) if (parsed.length > 3) port = parseInt(parsed[2]);
port = port ?? 25565 port = port ?? 25565;
break break;
} }
} }
try { try {
await PLUGIN_MANAGER.proxy.players.get(client.gameClient.username).switchServers({ await PLUGIN_MANAGER.proxy.players
.get(client.gameClient.username)
.switchServers({
host: host, host: host,
port: port, port: port,
version: "1.8.8", version: "1.8.8",
username: savedAuth.selectedProfile.name, username: savedAuth.selectedProfile.name,
auth: 'mojang', auth: "mojang",
keepAlive: false, keepAlive: false,
session: { session: {
accessToken: savedAuth.accessToken, accessToken: savedAuth.accessToken,
clientToken: savedAuth.selectedProfile.id, clientToken: savedAuth.selectedProfile.id,
selectedProfile: { selectedProfile: {
id: savedAuth.selectedProfile.id, id: savedAuth.selectedProfile.id,
name: savedAuth.selectedProfile.name name: savedAuth.selectedProfile.name,
} },
}, },
skipValidation: true, skipValidation: true,
hideErrors: true hideErrors: true,
}) });
} catch (err) { } catch (err) {
if (!client.gameClient.ended) { if (!client.gameClient.ended) {
client.gameClient.end(Enums.ChatColor.RED + `Something went wrong whilst switching servers: ${err.message}`) client.gameClient.end(
Enums.ChatColor.RED +
`Something went wrong whilst switching servers: ${err.message}`
);
} }
} }
} catch (err) { } catch (err) {
if (!client.gameClient.ended) { if (!client.gameClient.ended) {
logger.error(`Error whilst processing user ${client.gameClient.username}: ${err.stack || err}`) logger.error(
client.gameClient.end(Enums.ChatColor.YELLOW + "Something went wrong whilst processing your request. Please reconnect.") `Error whilst processing user ${client.gameClient.username}: ${
err.stack || err
}`
);
client.gameClient.end(
Enums.ChatColor.YELLOW +
"Something went wrong whilst processing your request. Please reconnect."
);
} }
} }
} }
export function generateSpawnChunk(): Chunk.PCChunk { export function generateSpawnChunk(): Chunk.PCChunk {
const chunk = new (Chunk.default(REGISTRY))(null) as Chunk.PCChunk const chunk = new (Chunk.default(REGISTRY))(null) as Chunk.PCChunk;
chunk.initialize(() => new McBlock(REGISTRY.blocksByName.air.id, REGISTRY.biomesByName.plains.id, 0)) chunk.initialize(
chunk.setBlock(new Vec3(8, 64, 8), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) () =>
chunk.setBlock(new Vec3(8, 67, 8), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) new McBlock(
chunk.setBlock(new Vec3(7, 65, 8), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) REGISTRY.blocksByName.air.id,
chunk.setBlock(new Vec3(7, 66, 8), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) REGISTRY.biomesByName.plains.id,
chunk.setBlock(new Vec3(9, 65, 8), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) 0
chunk.setBlock(new Vec3(9, 66, 8), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) )
chunk.setBlock(new Vec3(8, 65, 7), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) );
chunk.setBlock(new Vec3(8, 66, 7), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) chunk.setBlock(
chunk.setBlock(new Vec3(8, 65, 9), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) new Vec3(8, 64, 8),
chunk.setBlock(new Vec3(8, 66, 9), new McBlock(REGISTRY.blocksByName.barrier.id, REGISTRY.biomesByName.plains.id, 0)) new McBlock(
chunk.setSkyLight(new Vec3(8, 66, 8), 15) REGISTRY.blocksByName.barrier.id,
return chunk REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(8, 67, 8),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(7, 65, 8),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(7, 66, 8),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(9, 65, 8),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(9, 66, 8),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(8, 65, 7),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(8, 66, 7),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(8, 65, 9),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setBlock(
new Vec3(8, 66, 9),
new McBlock(
REGISTRY.blocksByName.barrier.id,
REGISTRY.biomesByName.plains.id,
0
)
);
chunk.setSkyLight(new Vec3(8, 66, 8), 15);
return chunk;
} }