mirror of
https://github.com/WorldEditAxe/eaglerproxy.git
synced 2024-11-23 22:16:04 -08:00
refactor + EaglerSkins#skinUrlFromUuid
This commit is contained in:
parent
006aac1b3f
commit
a78c1c98e8
|
@ -31,7 +31,7 @@ export function sendPluginChatMessage(
|
||||||
throw new Error("There must be one or more passed components!");
|
throw new Error("There must be one or more passed components!");
|
||||||
else {
|
else {
|
||||||
client.ws.send(
|
client.ws.send(
|
||||||
client.serializer.createPacketBuffer({
|
client.serverSerializer.createPacketBuffer({
|
||||||
name: "chat",
|
name: "chat",
|
||||||
params: {
|
params: {
|
||||||
message: JSON.stringify({
|
message: JSON.stringify({
|
||||||
|
|
|
@ -15,8 +15,6 @@ import { MineProtocol } from "./Protocol.js";
|
||||||
import { EaglerSkins } from "./skins/EaglerSkins.js";
|
import { EaglerSkins } from "./skins/EaglerSkins.js";
|
||||||
import { Util } from "./Util.js";
|
import { Util } from "./Util.js";
|
||||||
import { BungeeUtil } from "./BungeeUtil.js";
|
import { BungeeUtil } from "./BungeeUtil.js";
|
||||||
import { ConnectionState } from "../plugins/EagProxyAAS/types.js";
|
|
||||||
import { SCSyncUuidPacket } from "./packets/SCSyncUuidPacket.js";
|
|
||||||
|
|
||||||
const { createSerializer, createDeserializer } = pkg;
|
const { createSerializer, createDeserializer } = pkg;
|
||||||
|
|
||||||
|
@ -33,8 +31,10 @@ export class Player extends EventEmitter {
|
||||||
private _alreadyConnected: boolean = false;
|
private _alreadyConnected: boolean = false;
|
||||||
|
|
||||||
public translator?: BungeeUtil.PacketUUIDTranslator;
|
public translator?: BungeeUtil.PacketUUIDTranslator;
|
||||||
public serializer: any;
|
public serverSerializer: any;
|
||||||
public deserializer: any;
|
public clientSerializer: any;
|
||||||
|
public serverDeserializer: any;
|
||||||
|
public clientDeserializer: any;
|
||||||
private _kickMessage: string;
|
private _kickMessage: string;
|
||||||
|
|
||||||
constructor(ws: WebSocket, playerName?: string, serverConnection?: Client) {
|
constructor(ws: WebSocket, playerName?: string, serverConnection?: Client) {
|
||||||
|
@ -45,13 +45,25 @@ export class Player extends EventEmitter {
|
||||||
this.serverConnection = serverConnection;
|
this.serverConnection = serverConnection;
|
||||||
if (this.username != null)
|
if (this.username != null)
|
||||||
this.uuid = Util.generateUUIDFromPlayer(this.username);
|
this.uuid = Util.generateUUIDFromPlayer(this.username);
|
||||||
this.serializer = createSerializer({
|
this.serverSerializer = createSerializer({
|
||||||
state: states.PLAY,
|
state: states.PLAY,
|
||||||
isServer: true,
|
isServer: true,
|
||||||
version: "1.8.9",
|
version: "1.8.9",
|
||||||
customPackets: null,
|
customPackets: null,
|
||||||
});
|
});
|
||||||
this.deserializer = createDeserializer({
|
this.clientSerializer = createSerializer({
|
||||||
|
state: states.PLAY,
|
||||||
|
isServer: false,
|
||||||
|
version: "1.8.9",
|
||||||
|
customPackets: null,
|
||||||
|
});
|
||||||
|
this.serverDeserializer = createDeserializer({
|
||||||
|
state: states.PLAY,
|
||||||
|
isServer: true,
|
||||||
|
version: "1.8.9",
|
||||||
|
customPackets: null,
|
||||||
|
});
|
||||||
|
this.clientDeserializer = createSerializer({
|
||||||
state: states.PLAY,
|
state: states.PLAY,
|
||||||
isServer: true,
|
isServer: true,
|
||||||
version: "1.8.9",
|
version: "1.8.9",
|
||||||
|
@ -100,10 +112,10 @@ export class Player extends EventEmitter {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const parsed = this.deserializer.parsePacketBuffer(msg)?.data,
|
const parsed = this.serverDeserializer.parsePacketBuffer(msg)?.data,
|
||||||
translated = this.translator.translatePacketClient(
|
translated = this.translator.translatePacketClient(
|
||||||
parsed.params,
|
parsed.params,
|
||||||
parsed.name
|
parsed
|
||||||
),
|
),
|
||||||
packetData = {
|
packetData = {
|
||||||
name: translated[0],
|
name: translated[0],
|
||||||
|
@ -112,7 +124,12 @@ export class Player extends EventEmitter {
|
||||||
};
|
};
|
||||||
this.emit("vanillaPacket", packetData, "CLIENT", this);
|
this.emit("vanillaPacket", packetData, "CLIENT", this);
|
||||||
if (!packetData.cancel) {
|
if (!packetData.cancel) {
|
||||||
(this as any)._sendPacketToServer(msg);
|
(this as any)._sendPacketToServer(
|
||||||
|
this.clientSerializer.createPacketBuffer({
|
||||||
|
name: packetData.name,
|
||||||
|
params: packetData.params,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._logger.debug(
|
this._logger.debug(
|
||||||
|
@ -219,7 +236,7 @@ export class Player extends EventEmitter {
|
||||||
this._switchingServers = true;
|
this._switchingServers = true;
|
||||||
|
|
||||||
this.ws.send(
|
this.ws.send(
|
||||||
this.serializer.createPacketBuffer({
|
this.serverSerializer.createPacketBuffer({
|
||||||
name: "chat",
|
name: "chat",
|
||||||
params: {
|
params: {
|
||||||
message: `${Enums.ChatColor.GRAY}Switching servers...`,
|
message: `${Enums.ChatColor.GRAY}Switching servers...`,
|
||||||
|
@ -228,7 +245,7 @@ export class Player extends EventEmitter {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
this.ws.send(
|
this.ws.send(
|
||||||
this.serializer.createPacketBuffer({
|
this.serverSerializer.createPacketBuffer({
|
||||||
name: "playerlist_header",
|
name: "playerlist_header",
|
||||||
params: {
|
params: {
|
||||||
header: JSON.stringify({
|
header: JSON.stringify({
|
||||||
|
@ -338,10 +355,10 @@ export class Player extends EventEmitter {
|
||||||
);
|
);
|
||||||
const pckSeq = BungeeUtil.getRespawnSequence(
|
const pckSeq = BungeeUtil.getRespawnSequence(
|
||||||
packet,
|
packet,
|
||||||
this.serializer
|
this.serverSerializer
|
||||||
);
|
);
|
||||||
this.ws.send(
|
this.ws.send(
|
||||||
this.serializer.createPacketBuffer({
|
this.serverSerializer.createPacketBuffer({
|
||||||
name: "login",
|
name: "login",
|
||||||
params: packet,
|
params: packet,
|
||||||
})
|
})
|
||||||
|
@ -364,7 +381,7 @@ export class Player extends EventEmitter {
|
||||||
this.uuid
|
this.uuid
|
||||||
);
|
);
|
||||||
this.ws.send(
|
this.ws.send(
|
||||||
this.serializer.createPacketBuffer({
|
this.serverSerializer.createPacketBuffer({
|
||||||
name: "login",
|
name: "login",
|
||||||
params: packet,
|
params: packet,
|
||||||
})
|
})
|
||||||
|
@ -383,7 +400,7 @@ export class Player extends EventEmitter {
|
||||||
} else {
|
} else {
|
||||||
const translated = this.translator!.translatePacketServer(
|
const translated = this.translator!.translatePacketServer(
|
||||||
packet,
|
packet,
|
||||||
meta.name
|
meta
|
||||||
),
|
),
|
||||||
eventData = {
|
eventData = {
|
||||||
name: translated[0],
|
name: translated[0],
|
||||||
|
@ -393,9 +410,9 @@ export class Player extends EventEmitter {
|
||||||
this.emit("vanillaPacket", eventData, "SERVER", this);
|
this.emit("vanillaPacket", eventData, "SERVER", this);
|
||||||
if (!eventData.cancel) {
|
if (!eventData.cancel) {
|
||||||
this.ws.send(
|
this.ws.send(
|
||||||
this.serializer.createPacketBuffer({
|
this.serverSerializer.createPacketBuffer({
|
||||||
name: meta.name,
|
name: eventData.name,
|
||||||
params: packet,
|
params: eventData.params,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -425,6 +442,7 @@ interface PlayerEvents {
|
||||||
|
|
||||||
export declare interface Player {
|
export declare interface Player {
|
||||||
on<U extends keyof PlayerEvents>(event: U, listener: PlayerEvents[U]): this;
|
on<U extends keyof PlayerEvents>(event: U, listener: PlayerEvents[U]): this;
|
||||||
|
once<U extends keyof PlayerEvents>(event: U, listener: PlayerEvents[U]): this;
|
||||||
|
|
||||||
emit<U extends keyof PlayerEvents>(
|
emit<U extends keyof PlayerEvents>(
|
||||||
event: U,
|
event: U,
|
||||||
|
|
|
@ -36,6 +36,49 @@ export namespace EaglerSkins {
|
||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type MojangFetchProfileResponse = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
name: "textures";
|
||||||
|
value: string;
|
||||||
|
signature: string;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
type MojangTextureResponse = {
|
||||||
|
timestamp: number;
|
||||||
|
profileId: string;
|
||||||
|
profileName: string;
|
||||||
|
signatureRequired: boolean;
|
||||||
|
textures: {
|
||||||
|
SKIN: {
|
||||||
|
url: string;
|
||||||
|
metadata: {
|
||||||
|
model: "slim";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
CAPE: {
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function skinUrlFromUuid(uuid: string): Promise<string> {
|
||||||
|
const response = (await (
|
||||||
|
await fetch(
|
||||||
|
`https://sessionserver.mojang.com/session/minecraft/profile/${uuid}`
|
||||||
|
)
|
||||||
|
).json()) as unknown as MojangFetchProfileResponse;
|
||||||
|
const parsed = JSON.parse(
|
||||||
|
Buffer.from(response.properties[0].value, "base64").toString()
|
||||||
|
) as unknown as MojangTextureResponse;
|
||||||
|
console.log(parsed.textures.SKIN.url);
|
||||||
|
return parsed.textures.SKIN.url;
|
||||||
|
}
|
||||||
|
|
||||||
export function downloadSkin(skinUrl: string): Promise<Buffer> {
|
export function downloadSkin(skinUrl: string): Promise<Buffer> {
|
||||||
const url = new URL(skinUrl);
|
const url = new URL(skinUrl);
|
||||||
if (url.protocol != "https:" && url.protocol != "http:")
|
if (url.protocol != "https:" && url.protocol != "http:")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user