gm-api-sdk
v1.0.2
Published
用于GM后台API的SDK ...
Downloads
4
Readme
gm-api-sdk
用于GM后台API的SDK ...
安装
yarn add gm-api-sdk
使用
import { Protobuffer, Socket } from 'gm-api-sdk'
//定义配置
const options = {
path : './pb',
socket : 'socket.proto',
gmPB : 'gm.proto',
prefix : 'com.autorun'
}
const socket = new Socket('192.168.1.92:7015')
const protobuffer = new Protobuffer(options)
const { createPBBuffer, makeData, decode, gameMessage } = protobuffer
const data = makeData(createPBBuffer(2000, 'game.CS_GM_QUERY', { roleId: '000062' }))
const messageQuery = gameMessage('SC_GM_QUERY')
const sendPB = async (data) => {
try {
let buffer = await socket.send(data)
let msgBase = decode(buffer, messageQuery)
let { msghead, msgbody } = msgBase
console.log(JSON.stringify(msghead, null, 2))
console.log(JSON.stringify(msgbody, null, 2))
} catch (error) {
console.log('error', errer)
}
}
sendPB(data)
License
this repo is released under the MIT License.