-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.ts
38 lines (33 loc) · 1019 Bytes
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { contract, useTypes } from "@yannbcf/altv-rpc";
import { fromClientContract } from "./shared.ts";
import { z } from "zod";
import * as alt from "alt-server";
const $server = useTypes(alt);
// rpc.initContractRouter("server", fromClientContract, {
// on: alt.onClient,
// emit: alt.emitClient
// }, {
// notifyOtherPlayer: (args) => {
// const { player, otherPlayer } = args;
// console.log(player, otherPlayer);
// otherPlayer; // never type
// },
// });
const exFromClientContract = contract.extend("no_typecheck", fromClientContract, {
notifyOtherPlayer: {
args: z.object({
otherPlayer: $server.player
})
}
});
contract.setupRouter("server", exFromClientContract, {
on: alt.onClient,
off: alt.offClient,
emit: alt.emitClient
}, {
notifyOtherPlayer: (args) => {
const { player, otherPlayer } = args;
console.log(player, otherPlayer);
otherPlayer; // server side alt.Player type
},
});