mirror of
https://github.com/WorldEditAxe/eaglerproxy.git
synced 2024-11-21 13:06:05 -08:00
some refactoring
This commit is contained in:
parent
5888ef9654
commit
958a060115
15
classes.ts
15
classes.ts
|
@ -1,15 +0,0 @@
|
|||
import { Client } from "minecraft-protocol"
|
||||
import { WebSocket } from "ws"
|
||||
import { State } from "./types.js"
|
||||
|
||||
export class ProxiedPlayer {
|
||||
public username: string
|
||||
public uuid: string
|
||||
public clientBrand: string
|
||||
public state: State
|
||||
public ws: WebSocket
|
||||
public ip: string
|
||||
public remotePort: number
|
||||
public remoteConnection: Client
|
||||
public compressionThreshold: number
|
||||
}
|
3
meta.ts
3
meta.ts
|
@ -1,3 +0,0 @@
|
|||
export const BRANDING: Readonly<string> = Object.freeze("EaglerXProxy")
|
||||
export const VERSION: Readonly<string> = "1.0.0"
|
||||
export const NETWORK_VERSION: Readonly<string> = Object.freeze(BRANDING + "/" + VERSION)
|
66
motd.ts
66
motd.ts
|
@ -1,66 +0,0 @@
|
|||
import { randomUUID } from "crypto";
|
||||
import { WebSocket } from "ws";
|
||||
import { ProxiedPlayer } from "./classes.js";
|
||||
import { UUID } from "./types.js"
|
||||
|
||||
export type MotdPlayer = {
|
||||
name: string,
|
||||
id: UUID
|
||||
}
|
||||
|
||||
export type MotdJSONRes = {
|
||||
brand: string,
|
||||
cracked: true,
|
||||
data: {
|
||||
cache: true,
|
||||
icon: boolean,
|
||||
max: number,
|
||||
motd: [string, string],
|
||||
online: number,
|
||||
players: string[],
|
||||
},
|
||||
name: string,
|
||||
secure: false,
|
||||
time: ReturnType<typeof Date.now>,
|
||||
type: "motd",
|
||||
uuid: ReturnType<typeof randomUUID>,
|
||||
vers: string
|
||||
}
|
||||
|
||||
// a 16384 byte array
|
||||
export type MotdServerLogo = Int8Array
|
||||
|
||||
export function handleMotd(player: Partial<ProxiedPlayer>) {
|
||||
const names = []
|
||||
for (const [username, player] of PROXY.players) {
|
||||
if (names.length > 0) {
|
||||
names.push(`(and ${PROXY.players.size - names.length} more)`)
|
||||
break
|
||||
} else {
|
||||
names.push(username)
|
||||
}
|
||||
}
|
||||
|
||||
player.ws.send(JSON.stringify({
|
||||
brand: PROXY.brand,
|
||||
cracked: true,
|
||||
data: {
|
||||
cache: true,
|
||||
icon: PROXY.MOTD.icon ? true : false,
|
||||
max: PROXY.playerStats.max,
|
||||
motd: PROXY.MOTD.motd,
|
||||
online: PROXY.playerStats.onlineCount,
|
||||
players: names
|
||||
},
|
||||
name: PROXY.serverName,
|
||||
secure: false,
|
||||
time: Date.now(),
|
||||
type: "motd",
|
||||
uuid: PROXY.proxyUUID,
|
||||
vers: PROXY.MOTDVersion
|
||||
} as MotdJSONRes))
|
||||
if (PROXY.MOTD.icon) {
|
||||
player.ws.send(PROXY.MOTD.icon)
|
||||
}
|
||||
player.ws.close()
|
||||
}
|
Loading…
Reference in New Issue
Block a user