Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dongdongcpk/cherry
a light-weight, scalable, distributed game server engine.
https://github.com/dongdongcpk/cherry
Last synced: 3 months ago
JSON representation
a light-weight, scalable, distributed game server engine.
- Host: GitHub
- URL: https://github.com/dongdongcpk/cherry
- Owner: dongdongcpk
- License: mit
- Created: 2017-03-30T02:11:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-01T03:03:18.000Z (over 7 years ago)
- Last Synced: 2024-07-03T18:28:40.837Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-star - cherry - weight, scalable, distributed game server engine. | dongdongcpk | 5 | (JavaScript)
README
# cherry-pit
cherry-pitπ is a light-weight, scalable, distributed game server engine.[δΈζζζ‘£](https://github.com/dongdongcpk/cherry/blob/master/doc/README-zh-cn.md)
## Installation
```
npm install cherry-pit -g
```
## Usage
### Initialization
```
cherry init
```
### Install dependencies
```
cd cherry
npm install
```
### Start server examples
```
npm run cherry-connector
npm run cherry-chat
npm run cherry-pk
```same as above:
```
node lib/connector.js 8080
node app.js chat
node app.js pk
```or start multi process:
```
node lib/connector.js 8080
node lib/connector.js 8081
node app.js chat
node app.js chat
node app.js pk
node app.js pk
```The same type of process will automatically achieve load balancing, you can also use pm2 for process management.
### Start client examples
```
node test/helper/wsClient2.js
node test/helper/wsClient1.js
```
### Configuration
`config/dev/config.json`, `busOptions` configuration reference [here](https://capriza.github.io/node-busmq/usage/), add your logical server type to `gameServerTypes`.```json
{
"busOptions": {
"driver": "ioredis",
"layout": "",
"redis": [
"redis://127.0.0.1:6379"
]
},
"gameServerTypes": [
"chat",
"pk"
]
}
```Add the service directory under `service/`.
```
βββ service
βΒ Β βββ chat
βΒ Β βΒ Β βββ chat.js
βΒ Β βββ pk
βΒ Β βββ pk.js
```
`service/chat/chat.js`, in the specific service directory to provide the interface.```js
function talk (gameServer, args) {
return args;
}function talk2all (gameServer, args) {
gameServer.broadcast(args[0]);
return;
}function talk2multi (gameServer, args) {
gameServer.multicast(...args);
return;
}module.exports = {
talk,
talk2all,
talk2multi
};
```
`app.js` is the entrance, import interface. The return value can be either promise or primitive type.```js
const chat = require('./service/chat/chat');
const pk = require('./service/pk/pk');let result;
try {
switch (serverType) {
case 'chat':
result = chat[func](gameServer, args);
break;
case 'pk':
result = pk[func](gameServer, args);
break;
}
}
catch (err) {
console.error(err);
}
```## API
### gameServer
#### Event: 'message'
* `msg` {String}#### gameServer.send(userId, msg)
* `userId` {String}
* `msg` {Number|String|Array|Object|Promise}#### gameServer.multicast(userIds, msg)
* `userIds` {Array}
* `msg` {Number|String|Array|Object|Promise}#### gameServer.broadcast(msg)
* `msg` {Number|String|Array|Object|Promise}## License
MIT LicenseCopyright (c) 2017 dongdonggun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.