gm-api-sdk

1.0.2 • Public • Published

gm-api-sdk

用于GM后台API的SDK ...

NPM Version NPM Downloads Gratipay

安装

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.

Readme

Keywords

none

Package Sidebar

Install

npm i gm-api-sdk

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • thondery