From a21e84416b5daac25145d8c60d88886c5ae8561a Mon Sep 17 00:00:00 2001 From: xLuxy <67131061+xLuxy@users.noreply.github.com> Date: Sun, 24 Sep 2023 10:04:01 +0200 Subject: [PATCH] shared: register RPC events --- client/js/events/rpc.js | 3 +++ server/js/events/rpc.js | 3 +++ types/client/index.d.ts | 10 ++++++++++ types/server/index.d.ts | 17 +++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 client/js/events/rpc.js create mode 100644 server/js/events/rpc.js diff --git a/client/js/events/rpc.js b/client/js/events/rpc.js new file mode 100644 index 000000000..817ef6ead --- /dev/null +++ b/client/js/events/rpc.js @@ -0,0 +1,3 @@ +const { Event } = requireBinding("shared/events.js"); + +Event.register(alt.Enums.EventType.SERVER_SCRIPT_RPC_ANSWER_EVENT, "ServerScriptRPCAnswer"); diff --git a/server/js/events/rpc.js b/server/js/events/rpc.js new file mode 100644 index 000000000..c7473c0e0 --- /dev/null +++ b/server/js/events/rpc.js @@ -0,0 +1,3 @@ +const { Event } = requireBinding("shared/events.js"); + +Event.register(alt.Enums.EventType.CLIENT_SCRIPT_RPC_EVENT, "PlayerScriptRPC"); diff --git a/types/client/index.d.ts b/types/client/index.d.ts index 131e70cf9..a9d27551f 100644 --- a/types/client/index.d.ts +++ b/types/client/index.d.ts @@ -1179,6 +1179,10 @@ declare module "@altv/client" { export function emitServerRPC(eventName: string, ...args: unknown[]): void; + // RPC related + export function onServerScriptRPCAnswer(callback: GenericEventCallback): altShared.Events.EventHandler; + export function onceServerScriptRPCAnswer(callback: GenericEventCallback): altShared.Events.EventHandler; + export function onKeyBoardEvent(callback: GenericEventCallback): altShared.Events.EventHandler; export function onceKeyBoardEvent(callback: GenericEventCallback): altShared.Events.EventHandler; export function onKeyUp(callback: GenericEventCallback): altShared.Events.EventHandler; @@ -1464,6 +1468,12 @@ declare module "@altv/client" { interface CustomClientEvent {} + interface ServerScriptRPCAnswer { + readonly answerID: number; + readonly answer: ReadonlyArray; + readonly answerError: string; + } + export type CustomEventCallback = (...params: T) => void | Promise; export type GenericEventCallback = (params: T) => void | Promise; export type GenericPlayerEventCallback = (params: T & { player: U }) => void | Promise; diff --git a/types/server/index.d.ts b/types/server/index.d.ts index 3fb8b5367..e6e5f2b31 100644 --- a/types/server/index.d.ts +++ b/types/server/index.d.ts @@ -815,6 +815,10 @@ declare module "@altv/server" { export function emitAllPlayersUnreliable(eventName: E, ...args: Parameters): void; export function emitAllPlayersUnreliable(eventName: Exclude, ...args: unknown[]): void; + // RPC related events + export function onPlayerScriptRPC(callback: GenericPlayerEventCallback): altShared.Events.EventHandler; + export function oncePlayerScriptRPC(callback: GenericPlayerEventCallback): altShared.Events.EventHandler; + // Server related events export function onServerStarted(callback: GenericEventCallback): altShared.Events.EventHandler; export function onceServerStarted(callback: GenericEventCallback): altShared.Events.EventHandler; @@ -1155,6 +1159,19 @@ declare module "@altv/server" { interface CustomServerEvent {} + interface PlayerScriptRPCEvent { + readonly name: string; + readonly args: ReadonlyArray; + readonly answerID: number; + readonly state: Enums.RPCEventState; + + willAnswer(): boolean; + answer(...args: unknown[]): void; + answerWithError(errorMessage: string): boolean; + getAnswer(): ReadonlyArray; + getAnswerError(): string; + } + export type EventContext = { readonly type: altShared.Enums.EventType; readonly isCancellable: boolean;