41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Server, ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js'
|
|
|
|
import {
|
|
Character,
|
|
GetCharacterRequest,
|
|
CreateCharacterRequest,
|
|
} from './proto/character'
|
|
|
|
import { characterManagerDefinition } from "./proto/character.grpc-server"
|
|
|
|
export function initCharacterService(server: Server) {
|
|
server.addService(characterManagerDefinition, {
|
|
createCharacter: createCharacter_Call,
|
|
getCharacter: getCharacter_Call,
|
|
})
|
|
}
|
|
|
|
function createCharacter_Call(call: ServerUnaryCall<CreateCharacterRequest, Character>, callback: sendUnaryData<Character>) {
|
|
callback(null, createCharacter(call.request))
|
|
}
|
|
|
|
function createCharacter(request: CreateCharacterRequest): Character {
|
|
return {
|
|
playerName: "test player",
|
|
characterName: "test character",
|
|
characterAlias: ["test alias"]
|
|
}
|
|
}
|
|
|
|
function getCharacter_Call(call: ServerUnaryCall<GetCharacterRequest, Character>, callback: sendUnaryData<Character>) {
|
|
callback(null, getCharacter(call.request))
|
|
}
|
|
|
|
function getCharacter(request: GetCharacterRequest): Character {
|
|
return {
|
|
playerName: "test player",
|
|
characterName: "test character",
|
|
characterAlias: ["test alias"]
|
|
}
|
|
}
|