UNPKG

@byte-fw/byte

Version:

<p align="center"> <img width="460" src="https://github.com/user-attachments/assets/62a88d31-c0a9-4140-bc98-571dee3cb733"> </p>

953 lines (885 loc) 25.5 kB
declare module "byte-server" { export type ByteExport = { classes: { InventorySlot: ExportedClass<typeof InventorySlot>; Inventory: typeof Inventory; PlayerInventory: ExportedClass<typeof PlayerInventory>; Player: ExportedClass<typeof Player>; User: ExportedClass<typeof User>; }; controllers: { CommandController: typeof CommandController; PlayerController: typeof PlayerController; PrivilegeController: typeof PrivilegeController; ServerAccessController: typeof ServerAccessController; DeferralManager: typeof DeferralManager; RPCController: typeof RPCController; }; utils: { EnvManager: typeof EnvManager; Logger: ExportedClass<typeof Logger>; }; database: { DB: typeof DB; getPlayersByDiscord(discordId: string): any; getPlayerFromDB(uuid: string): any; savePlayerToDB(discord: string, playerData: DBPlayerInfo): any; getDBPrivileges(): any; }; shared: ByteSharedExport; }; export class ExportedClass<T extends Class> { private prototype: any; constructor(prototype: T); /** * Returns a new instance of the wrapped class */ construct(...args: ConstructorParameters<T>): InstanceType<T>; /** * Used for accessing static methods of the wrapped class * @returns The object prototype of the wrapped class */ getClass(): T; } export class InventorySlot implements IObjectifiable<SlotData> { private item: any; private amount: any; private info: any; constructor(item: Item | undefined, amount: number, info: SlotInfo | undefined); getItem(): Item | undefined; getAmount(): number; getInfo(): SlotInfo | undefined; setItem(item: Item, amount?: number): void; setAmount(amount: number): void; setInfo(info?: SlotInfo): void; addAmount(amount: number): void; removeAmount(amount: number): void; getWeight(): number; toObject(): { item: string | undefined; amount: number; info: SlotInfo | undefined; }; } export class Inventory implements IObjectifiable<InventoryData> { protected slots: Array<InventorySlot>; protected maxWeight: number; constructor(data: Array<InventorySlot>, size: number, maxWeight: number); getTotalWeight(): number; getEmptySlot(): number; getSlotWithItem(item: Item): number; protected _addItem(item: Item, amount?: number, info?: SlotInfo | undefined): boolean; protected _removeItem(item: Item, amount?: number): boolean; getItemAmount(item: Item): number; protected _moveSlot(from: number, to: number, amount?: number): void; toObject(): Array<{ item: string | undefined; amount: number; info: SlotInfo | undefined; }>; } export class PlayerInventory extends Inventory { private src: any; constructor(src: number, data: Array<InventorySlot>, size: number, maxWeight: number); addItem(item: Item, amount?: number, info?: SlotInfo): boolean; removeItem(item: Item, amount?: number): boolean; moveSlot(from: number, to: number, amount?: number): void; private emitChanges: any; /** * @noSelf * */ static fromObject(src: number, data: Array<SlotData>, size: number, maxWeight: number): PlayerInventory; } export class Player extends User implements IObjectifiable<DBPlayerInfo> { private uuid: any; private data: any; private position: any; private jobs: any; private gangs: any; private inventory: any; private playerPedData: any; private isReady: any; constructor(src: number, uuid: UUID, playerData: PlayerData, inventory: PlayerInventory, position: Vector4, jobs: Array<PlayerJob>, gangs: Array<PlayerGang>, playerPedData: PedData); getUuid(): string; getData(): PlayerData; getInventory(): PlayerInventory; getPosition(): Vector4; getJobs(): Array<PlayerJob>; getGangs(): Array<PlayerGang>; hasJob(job: PlayerJob): boolean; hasGang(gang: PlayerGang): boolean; getJob(job: PlayerJob): PlayerJob | undefined; getGang(gang: PlayerGang): PlayerGang | undefined; getJobIndex(job: PlayerJob): number; getGangIndex(gang: PlayerGang): number; getPlayerPedData(): PedData; setData(data: PlayerData): void; setDataKey<K extends "birthdate" | "firstname" | "lastname" | "gender" | "nationality">(key: K, value: PlayerData[K]): void; setPosition(position: Vector4): void; setJobs(jobs: Array<PlayerJob>): void; addJob(job: PlayerJob): void; removeJob(job: PlayerJob): Result; setJob(job: PlayerJob): Result; setGangs(gangs: Array<PlayerGang>): void; addGang(gang: PlayerGang): void; removeGang(gang: PlayerGang): Result; setGang(gang: PlayerGang): Result; setPlayerPedData(data: PedData, syncWithClient?: boolean): void; /** * Emits a change to the client in order to update their local player's data. * @param key The key of the Player property that was changed. */ private emitChange: any; /** * Updates the player's position to the current position of their ped. */ updatePosition(): void; save(): TransactionResult<null>; toObject(): DBPlayerInfo; asString(): string; asJSON(): string; /** * Emits the PlayerReady event to the client and makes the client load the instance of the player. * It is used as a sort of login method. * **Should only be called once throught the player's lifecycle** * @param player The player to emit the event to. * @noSelf */ static emitPlayerReady(player: Player): void; /** * @noSelf * */ static fromObject(src: number, data: DBPlayerInfo): Player; } export class User extends ByteGameObject { private src: any; constructor(src: number); getIdentifier(identifier: string): string | undefined; getIdentifiers(): Record<string, string>; getPrivilege(): Privilege; hasPrivilege(target: Privilege): boolean; getSrc(): number; /** * @returns A string representation of the object. */ asString(): string; /** * @returns A JSON string representation of the object. */ asJSON(): string; } export class CommandController { static registerCommand(command: Command): void; } export class PlayerController { /** * @noSelf * */ private static instance: any; private players: any; private constructor(); getPlayer(src: number): Player; getPlayers(): Record<number, Player>; addPlayer(src: number, player: Player): void; removePlayer(src: number): void; savePlayersAsync(): void; onPlayerDropped(_reason: string): void; /** * @noSelf * */ static getInstance(): PlayerController; } export class PrivilegeController { /** * @noSelf * */ private static instance: any; private privilegedUsers: any; private constructor(); private reloadPrivileges: any; addPrivilege(discord: string, privilege: keyof typeof Privilege): void; removePrivilege(discord: string): void; getPrivilege(discordId: string): Privilege; hasPrivilege(privilege: Privilege, target: Privilege): boolean; /** * @noSelf * */ static getInstance(): PrivilegeController; } export class ServerAccessController { private static instance: any; private serverClosed: any; private constructor(); getServerClosed(): boolean; setServerClosed(closed: boolean): boolean; deferral: Deferral; /** * @noSelf * */ static getInstance(): ServerAccessController; } export class DeferralManager { private static deferrals: any; /** * Adds a deferral to the deferral queue. * @param name Unique name for the deferral. * @param deferral The deferral function to add. */ static addDeferral(name: string, deferral: Deferral): void; /** * Removes a deferral from the deferral queue. * @param name Unique name of the deferral to remove. */ static removeDeferral(name: string): void; /** * Gets a deferral function from the deferral queue. * @param name Unique name of the deferral to get. * @returns The deferral function if it exists, otherwise None. */ static getDeferral(name: string): Optional<Deferral>; /** * @param playerName Steam / Client name of the connecting player * @param setKickReason Function to set the kick reason (does not seem to work) * @param deferrals Deferral object provided by the Cfx.re framework */ static defer(playerName: string, setKickReason: KickFunction, deferrals: any): void; } export class RPCController { /** * @noSelf * */ private static instance: any; private promises: any; private procedures: any; private constructor(); /** * Registers a procedure that can be called from the client. * @template Args An array containing the types of the data returned by the procedure to the client. * @param procedure The name of the procedure to register. * @param callback The callback function to call when the procedure is called. */ registerProcedure<T extends Array<any> = any>(procedure: string, callback: RPCCallback<T>): void; /** * Deletes a procedure handler from the server. * @param procedure The name of the procedure to delete. */ deleteProcedure(procedure: string): void; /** * Calls a procedure on the client. * @param src The player source to call the procedure on. * @param procedure The name of the procedure to call. * @param args The arguments to pass to the client. * @returns A promise that resolves when the client responds. */ call<T extends Array<any> = any>(src: number, procedure: string, ...args: Array<any>): LuaMultiReturn<T>; /** * @noSelf * */ static getInstance(): RPCController; } export class EnvManager { private constructor(); static getMaxClient(): number | 48; static getGameBuild(): number | 1604; static getTags(): string | ""; static getSteamWebApiKey(): string | "none"; static getServerClosed(): boolean | true; static getDebug(): boolean | false; static getProduction(): boolean | false; } export class Logger { private module: any; constructor(module?: string); private log: any; info(...args: Array<any>): void; warn(...args: Array<any>): void; error(...args: Array<any>): void; debug(...args: Array<any>): void; } export class DB { static ready(cb: (this: void, result: Result<null, string>) => void): void; static readySync(): Result<null, string>; static query(query: string, args: Array<any>, cb: (this: void, result: Result<DBResult, string>) => void): void; static querySync(query: string, args: Array<any>): Result<DBResult, string>; } export type DBPlayerInfo = { uuid: string; data: DBPlayerData; jobs: Array<PlayerJob>; gangs: Array<PlayerGang>; position: Coords4; inventory: InventoryData; pedData: PedData; }; export type ByteSharedExport = { interfaces: {}; utils: { uuid(): string; parseVector2(coords: Coords2): Vector2; parseVector3(coords: Coords3): Vector3; parseVector4(coords: Coords4): Vector4; arrayGroupBy<T, K extends string | number | symbol>(arr: Array<T>, key: (i: T) => K): Record<K, Array<T>>; }; consts: { HEAD_BLEND_TEXTURE_AMOUNT: 45; OVERLAY_TEXTURE_AMOUNT: 45; MAX_TRACE_LENGTH: 7; }; XML: typeof XML; classes: { ByteGameObject: typeof ByteGameObject; ConfigController: typeof ConfigController; Item: ExportedClass<typeof Item>; Translator: ExportedClass<typeof Translator>; XMLSearchNode: ExportedClass<typeof XMLSearchNode>; EventNameController: ExportedClass<typeof EventNameController>; Debugger: ExportedClass<typeof Debugger>; TypeChecker: ExportedClass<typeof TypeChecker>; Optional: typeof Optional; ExportedClass: typeof ExportedClass; Result: { Ok<T, E>(value: T): any; EmptyOk<E>(): any; Err<E>(error?: E): any; }; Timestamp: ExportedClass<typeof Timestamp>; zones: { BoxZone: ExportedClass<typeof BoxZone>; CircleZone: ExportedClass<typeof CircleZone>; PolygonZone: ExportedClass<typeof PolygonZone>; }; }; }; /** * @noSelfInFile */ export type Class = new (...args: any) => any; /** * @noSelfInFile */ export interface IObjectifiable<T> { toObject(): T; } /** * @noSelfInFile */ export type SlotData = { item?: string; amount: number; info?: SlotInfo; }; export class Item { private name: any; private label: any; private description: any; private weight: any; private unique: any; constructor(name: string, label: string, description: string, weight: number, unique: boolean); getName(): string; getLabel(): string; getDescription(): string; getWeight(): number; getUnique(): boolean; asString(): string; } export type SlotInfo = { displayStrings?: Record<string, string>; [key: string]: any; }; export type InventoryData = Array<SlotData>; /** * @noSelfInFile */ export type UUID = string; export type PlayerData = ExcludeKey<DBPlayerData, "birthdate"> & { birthdate: Timestamp; }; export type PlayerJob = { name: string; grade: number; }; export type PlayerGang = { name: string; grade: number; }; export type PedData = { pedModel: number; components: Record<keyof typeof PedComponent, { drawable: number; texture: number; }>; faceFeatures: Record<keyof typeof FaceFeature, number>; props: Record<keyof typeof PedProps, { drawable: number; texture: number; }>; headOverlays: Record<keyof typeof PedHeadOverlay, PedHeadOverlayData>; headBlend: PedHeadBlendData; hairColor: number; highlightColor: number; }; /** * A result type that can be either an error or a value. * Tries to take the best of Go's and Rust's error handling. */ export type Result<T = Null, E = Null> = LuaMultiReturn<[error: true, value: E]> | LuaMultiReturn<[error: false, value: T]>; export type TransactionResult<T> = Result<T, Array<TransactionError>>; export class ByteGameObject { constructor(); /** * Clones the object. */ clone(): this; /** * Checks if the object is equal to another object. * @param other The object to compare to. * @returns `true` if the objects are equal, `false` otherwise. */ equals(other: this): boolean; /** * @returns A hash code for the object instance. */ hash(): number; /** * @returns `-1` if `this` is less than `other`, `0` if they are equal, `1` if `this` is greater than `other`. */ compare(other: this): -1 | 0 | 1; /** * @returns A string representation of the object. */ asString(): string; /** * @returns A JSON string representation of the object. */ asJSON(): string; } /** * @noSelfInFile */ export enum Privilege { NONE = 0, WHITELISTED = 1, SUPPORT = 2, MODERATOR = 3, ADMIN = 4, GOD = 5, } export type Command = { command: string; commandFn(this: void, src: number, args: Array<string>, raw: string): void; privilege?: Privilege; }; /** * Type of a deferral function that is called when a player is connecting. * If the result is an error, the player is kicked with the error message provided as the result error. */ export type Deferral = (src: number, playerName: string, setKickReason: KickFunction, deferrals: any) => Result<null, string>; export class Optional<T = any | undefined> { private value: any; private _isSome: any; private constructor(); /** * Returns the value as the not nullable type. * @returns The original value */ unwrap(): T; /** * @returns Where the wrapped value is null */ isSome(): boolean; /** * @noSelf * */ static Some<T_1>(value: T_1): Optional<T_1>; /** * @noSelf * */ static None<T_1>(): Optional<T_1>; } export type KickFunction = (this: void, reason: string) => void; /** * Type of a RPC function that can be called from the client. * @param src The player source that called the procedure. * @param cb The callback function to call when the procedure is done. */ export type RPCCallback<T extends Array<any> = any> = (this: void, src: number, cb: (this: void, ...args: T) => void, ...args: Array<any>) => any; export type DBResult = { rows: Array<any>; count: number; }; export type DBPlayerData = { firstname: string; lastname: string; /** * Unix timestamp */ birthdate: number; gender: PlayerGender; nationality: string; }; export type Coords4 = { x: number; y: number; z: number; w: number; }; /** * @noSelfInFile */ export type Coords2 = { x: number; y: number; }; export type Coords3 = { x: number; y: number; z: number; }; export class ConfigController { /** * @noSelf * */ private static instance: any; private items: any; private inventorySlots: any; private maxPlayerWeight: any; private locale: any; private constructor(); getItems(): Record<string, Item>; getInventorySlots(): number; getMaxPlayerWeight(): number; getLocale(): string; /** * @noSelf * */ static getInstance(): ConfigController; } export class Translator { private translations: any; private lang: any; constructor(lang: string, xml: XMLNode); get(key: string): string; } export class XMLSearchNode { private node: any; constructor(node: XMLChild); /** * Searches for all children nodes that match the search parameters * @param params The search parameters * @returns An array of `XMLSearchNode` objects that match the search parameters */ search(params: XMLSearchParams): Array<XMLSearchNode>; /** * Returns the node as a `XMLNode`. Useful for getting the attributes of the node. * @returns The node as a `XMLNode` */ asNode(): XMLNode; /** * @returns The inner text of the node (e.g. `<entry>text</entry> => "text"`) */ asText(): string; } export class EventNameController { private events: any; private logger: any; constructor(xmlNode: XMLSearchNode); get(key: string): EventName; } export class Debugger { private moduleName: any; private canContinue: any; constructor(moduleName: string); /** * Stops the execution of the code until the continue event is triggered. * @param id Unique identifier for the breakpoint * @param args Arguments to be displayed when the breakpoint is hit */ breakpoint(id: string, args?: any): void; /** * Similar to a breakpoint, but it doesn't stop the execution of the code, just logs the information. * @param id Unique identifier for the watchpoint * @param args Arguments to be displayed when the watchpoint is hit */ watchpoint(id: string, args?: any): void; } export class TypeChecker { private prototype: any; constructor(prototype: CheckedType); check(object: any): boolean; /** * @noSelf * */ private static checkR: any; /** * @noSelf * */ private static isObjectAnArray: any; } export class Timestamp { private timestamp: any; constructor(timestamp: number); private static secondsInAMinute: any; /** * @noSelf * */ private static secondsInAnHour: any; /** * @noSelf * */ private static secondsInADay: any; /** * @noSelf * */ private static daysPerMonth: any; /** * @noSelf * */ static isLeapYear(year: number): boolean; getTimestamp(): number; getSecond(): number; getMinute(): number; getHour(): number; getYear(): number; getMonth(): number; getDay(): number; } export class BoxZone extends ByteGameObject implements IZone { private id: any; private center: any; private width: any; private height: any; constructor(center: Vector2, width: number, height: number); getId(): string; getCenter(): Vector2; isPointInside(point: Vector2): boolean; /** * @returns A string representation of the object. */ asString(): string; } export class CircleZone extends ByteGameObject implements IZone { private id: any; private center: any; private radius: any; constructor(center: Vector2, radius: number); getId(): string; getCenter(): Vector2; isPointInside(point: Vector2): boolean; /** * @returns A string representation of the object. */ asString(): string; } export class PolygonZone extends ByteGameObject implements IZone { private id: any; private vertices: any; private readonly center: any; constructor(vertices: Array<Vector2>); getId(): string; getCenter(): Vector2; isPointInside(point: Vector2): boolean; /** * @returns A string representation of the object. */ asString(): string; } export type ExcludeKey<T, K> = Pick<T, Exclude<keyof T, K>>; export enum PedComponent { /** * HEAD */ COMP_HEAD = 0, /** * MASKS */ COMP_BERD = 1, /** * HAIR */ COMP_HAIR = 2, /** * GLOVES */ COMP_UPPR = 3, /** * PANTS */ COMP_LOWR = 4, /** * BAGS & PARACHUTES */ COMP_HAND = 5, /** * SHOES */ COMP_FEET = 6, /** * ACCESSORIES */ COMP_TEEF = 7, /** * T-SHIRTS */ COMP_ACCS = 8, /** * BODY ARMOR */ COMP_TASK = 9, /** * DECALS */ COMP_DECL = 10, /** * JACKETS */ COMP_JBIB = 11, } export enum FaceFeature { NOSE_WIDTH = 0, NOSE_PEAK = 1, NOSE_LENGTH = 2, NOSE_BONE_CURVE = 3, NOSE_TIP = 4, NOSE_BONE_TWIST = 5, EYEBROW_HEIGHT = 6, EYEBROW_DEPTH = 7, CHEEK_HEIGHT = 8, CHEEK_DEPTH = 9, CHEEK_WIDTH = 10, EYE_OPENING = 11, LIP_THICKNESS = 12, JAW_WIDTH = 13, JAW_ROUNDNESS = 14, CHIN_HEIGHT = 15, CHIN_LENGTH = 16, CHIN_ROUNDNESS = 17, CHIN_HOLE = 18, NECK_THICKNESS = 19, } export enum PedProps { /** * "p_head" */ ANCHOR_HEAD = 0, /** * "p_eyes" */ ANCHOR_EYES = 1, /** * "p_ears" */ ANCHOR_EARS = 2, /** * "p_mouth" */ ANCHOR_MOUTH = 3, /** * "p_lhand" */ ANCHOR_LEFT_HAND = 4, /** * "p_rhand" */ ANCHOR_RIGHT_HAND = 5, /** * "p_lwrist" */ ANCHOR_LEFT_WRIST = 6, /** * "p_rwrist" */ ANCHOR_RIGHT_WRIST = 7, /** * "p_lhip" */ ANCHOR_HIP = 8, /** * "p_lfoot" */ ANCHOR_LEFT_FOOT = 9, /** * "p_rfoot" */ ANCHOR_RIGHT_FOOT = 10, /** * "ph_lhand" */ ANCHOR_PH_L_HAND = 11, /** * "ph_rhand" */ ANCHOR_PH_R_HAND = 12, } export enum PedHeadOverlay { BLEMISHES = 0, FACIAL_HAIR = 1, EYEBROWS = 2, AGEING = 3, MAKEUP = 4, BLUSH = 5, COMPLEXION = 6, SUN_DAMAGE = 7, LIPSTICK = 8, MOLES = 9, CHEST_HAIR = 10, BODY_BLEMISHES = 11, ADD_BODY_BLEMISHES = 12, } export type PedHeadOverlayData = { overlayValue: number; firstColour: number; secondColour: number; overlayOpacity: number; }; export type PedHeadBlendData = { shapeFirst: number; shapeSecond: number; shapeThird: number; skinFirst: number; skinSecond: number; skinThird: number; shapeMix: number; skinMix: number; thirdMix: number; }; /** * @noSelfInFile */ export type Null = null | undefined; export type TransactionError = { query: string; params: Array<any>; error: string; }; export enum PlayerGender { MALE = 0, FEMALE = 1, UNKNOWN = 2, } /** * The search parameters for the XML search * @param tag The tag to search for (e.g. "entry" => `<entry>...</entry>`) * @param attrs The attributes to search for. If not provided, it will search for all tags with the given tag. */ export type XMLSearchParams = { tag: string; attrs?: { key: string; value: string; }; }; export type EventName = string; export type CheckedType = SimpleCheckedType | ComplexCheckedType; export interface IZone { getId(): UUID; getCenter(): Vector2; isPointInside(point: Vector2): boolean; } /** * @noSelfInFile */ export type SimpleCheckedType = "string" | "string?" | "string[]" | "string[]?" | "number" | "number?" | "number[]" | "number[]?" | "boolean" | "boolean?" | "boolean[]" | "boolean[]?" | "null" | "null[]" | "null[]?" | "undefined" | "undefined[]" | "undefined[]?"; export interface ComplexCheckedType { [key: string]: SimpleCheckedType | ComplexCheckedType; } }