{"id":13671725,"url":"https://github.com/dongdongcpk/cherry","last_synced_at":"2025-04-27T18:31:37.282Z","repository":{"id":57197817,"uuid":"86648676","full_name":"dongdongcpk/cherry","owner":"dongdongcpk","description":"a light-weight, scalable, distributed game server engine.","archived":false,"fork":false,"pushed_at":"2017-05-01T03:03:18.000Z","size":23,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T06:17:30.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dongdongcpk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-30T02:11:25.000Z","updated_at":"2019-04-02T08:56:25.000Z","dependencies_parsed_at":"2022-09-16T13:11:12.686Z","dependency_job_id":null,"html_url":"https://github.com/dongdongcpk/cherry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongcpk%2Fcherry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongcpk%2Fcherry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongcpk%2Fcherry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongdongcpk%2Fcherry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dongdongcpk","download_url":"https://codeload.github.com/dongdongcpk/cherry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251187255,"owners_count":21549610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:17.190Z","updated_at":"2025-04-27T18:31:36.683Z","avatar_url":"https://github.com/dongdongcpk.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# cherry-pit\ncherry-pit🍒 is a light-weight, scalable, distributed game server engine.\n\n[中文文档](https://github.com/dongdongcpk/cherry/blob/master/doc/README-zh-cn.md)\n\n## Installation\n```\nnpm install cherry-pit -g\n```\n## Usage\n### Initialization\n```\ncherry init\n```\n### Install dependencies\n```\ncd cherry\nnpm install\n```\n### Start server examples\n```\nnpm run cherry-connector\nnpm run cherry-chat\nnpm run cherry-pk\n```\n\nsame as above:\n\n```\nnode lib/connector.js 8080\nnode app.js chat\nnode app.js pk\n```\n\nor start multi process:\n\n```\nnode lib/connector.js 8080\nnode lib/connector.js 8081\nnode app.js chat\nnode app.js chat\nnode app.js pk\nnode app.js pk\n```\n\nThe same type of process will automatically achieve load balancing, you can also use pm2 for process management.\n\n### Start client examples\n```\nnode test/helper/wsClient2.js\nnode test/helper/wsClient1.js\n```\n### Configuration\n`config/dev/config.json`, `busOptions` configuration reference [here](https://capriza.github.io/node-busmq/usage/), add your logical server type to `gameServerTypes`.\n\n```json\n{\n  \"busOptions\": {\n    \"driver\": \"ioredis\",\n    \"layout\": \"\",\n    \"redis\": [\n      \"redis://127.0.0.1:6379\"\n    ]\n  },\n  \"gameServerTypes\": [\n    \"chat\",\n    \"pk\"\n  ]\n}\n```\n\nAdd the service directory under `service/`.\n\n```\n├── service\n│   ├── chat\n│   │   └── chat.js\n│   └── pk\n│       └── pk.js\n```\n`service/chat/chat.js`, in the specific service directory to provide the interface.\n\n```js\nfunction talk (gameServer, args) {\n  return args;\n}\n\nfunction talk2all (gameServer, args) {\n  gameServer.broadcast(args[0]);\n  return;\n}\n\nfunction talk2multi (gameServer, args) {\n  gameServer.multicast(...args);\n  return;\n}\n\nmodule.exports = {\n  talk,\n  talk2all,\n  talk2multi\n};\n```\n`app.js` is the entrance, import interface. The return value can be either promise or primitive type.\n\n```js\nconst chat = require('./service/chat/chat');\nconst pk = require('./service/pk/pk');\n\nlet result;\ntry {\n  switch (serverType) {\n    case 'chat':\n      result = chat[func](gameServer, args);\n      break;\n    case 'pk':\n      result = pk[func](gameServer, args);\n      break;\n  }\n}\ncatch (err) {\n  console.error(err);\n}\n```\n\n## API\n### gameServer\n#### Event: 'message'\n* `msg` {String}\n\n#### gameServer.send(userId, msg)\n* `userId` {String}\n* `msg` {Number|String|Array|Object|Promise}\n\n#### gameServer.multicast(userIds, msg)\n* `userIds` {Array}\n* `msg` {Number|String|Array|Object|Promise}\n\n#### gameServer.broadcast(msg)\n* `msg` {Number|String|Array|Object|Promise}\n\n## License\nMIT License\n\nCopyright (c) 2017 dongdonggun\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongdongcpk%2Fcherry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdongdongcpk%2Fcherry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongdongcpk%2Fcherry/lists"}