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
npm install dogsvr
npm install dogsvr-cl-tsrpc
import * as dogsvr from 'dogsvr/main_thread';
import { TsrpcCL } from 'dogsvr-cl-tsrpc';
const connLayer: TsrpcCL = new TsrpcCL(3000);
const mainThreadInfo: dogsvr.MainThreadInfo =
{
workerThreadRunFile: "./test_svr_logic.js",
workerThreadNum: 2,
connLayer: connLayer,
}
dogsvr.startServer(mainThreadInfo);
- writing worker thread file
import * as dogsvr from 'dogsvr/worker_thread';
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));
})
pm2 start test_svr.js
pm2 trigger test_svr hotUpdate
Please see dogsvr-example-proj for more.
architecture
TODO