feat pure rpc example

This commit is contained in:
2024-10-28 10:28:56 +00:00
parent 67be91538b
commit e7e423adc6
38 changed files with 161 additions and 707 deletions
+7 -6
View File
@@ -1,13 +1,14 @@
{
"name": "rage-fw-example-server",
"version": "0.1.0",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"description": "Server side of rage-fw example",
"description": "Server side of Rage-FW example",
"scripts": {
"build": "esbuild src/index.ts --bundle --platform=node --target=node10.4 --outfile=../../server/packages/server/index.js"
},
"dependencies": {
"rpc": "workspace:^"
}
"@rage-fw/shared": "workspace:^",
"rage-fw-rpc": "file:../../../rage-framework/rpc"
},
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
}
+16 -7
View File
@@ -1,11 +1,20 @@
import { rpc } from 'rpc'
import { events } from '@rage-fw/shared'
import { rpc } from './lib'
rpc.register('playerJoin', async (player: PlayerMp) => {
console.log(`Connected: ${player.socialClub}`)
console.log(`[Server] ${player.socialClub} connected`)
})
rpc.register('customServerEvent', (player: PlayerMp, data) => {
console.log(player, data)
rpc.callClient(player, 'customClientEvent', ['server to client'])
})
rpc.register(
events.server.customServerEvent,
async (player: PlayerMp, args: string) => {
console.log(args)
const res = await rpc.callClient(
player,
events.client.customClientEvent,
['hello from server'],
)
console.log(res)
return 'response from server'
},
)
+5
View File
@@ -0,0 +1,5 @@
import { Rpc } from 'rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})