0.2.0 • Published 3 months ago

dogsvr v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

dogsvr

dogsvr is a game server package based on nodejs, and makes writing game server easier for rapid development of small teams.

features

  • Adapt to multiple connection methods
  • User-defined protocol serialization
  • Hot update server logic

usage

  1. installing dogsvr
npm install dogsvr
npm install dogsvr-cl-tsrpc
  1. creating 2 files at least, one is main thread file, the other is worker thread file

  2. writing main thread file

import * as dogsvr from 'dogsvr/main_thread';
import { TsrpcCL } from 'dogsvr-cl-tsrpc';

const connLayer: TsrpcCL = new TsrpcCL(3000); // connection layer using tsrpc
const mainThreadInfo: dogsvr.MainThreadInfo =
{
    workerThreadRunFile: "./test_svr_logic.js", // worker thread file name
    workerThreadNum: 2,
    connLayer: connLayer,
}
dogsvr.startServer(mainThreadInfo);
  1. writing worker thread file
import * as dogsvr from 'dogsvr/worker_thread';

// register command handler
dogsvr.regCmdHandler(10001, async (reqMsg: dogsvr.Msg, innerReq: dogsvr.MsgBodyType) => {
    const req = JSON.parse(innerReq as string);

    const res = {res: "I am dog"};
    dogsvr.respondCmd(reqMsg, JSON.stringify(res));
})
  1. run server by pm2
pm2 start test_svr.js  #test_svr.js is main thread file
pm2 trigger test_svr hotUpdate  #hot update when any logic file has been changed

Please see dogsvr-example-proj for more.

architecture

TODO

0.2.0

3 months ago

0.1.3

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago

0.0.1

6 months ago