r2/game-server/app.js
lightings ebfa604df2 ...
2023-05-10 12:45:55 +08:00

63 lines
1.5 KiB
JavaScript

var pomelo = require('pomelo');
const globalChannel = require('pomelo-globalchannel-plugin');
const dispatcher = require('./app/util/dispatcher');
const ChatService = require('./app/services/chatService');
/**
* Init app for client.
*/
var app = pomelo.createApp();
app.set('name', 'r2');
app.loadConfig('mysql', app.getBase() + '/config/mysql.json');
app.loadConfig('redis', app.getBase() + '/config/redis.json');
const redisConfig = pomelo.app.get("redis");
app.use(globalChannel, { globalChannel: {
host: redisConfig.host,
port: redisConfig.port,
db: '0'
}});
var chatRoute = function(session, msg, app, cb) {
var chatServers = app.getServersByType('chat');
if(!chatServers || chatServers.length === 0) {
cb(new Error('can not find chat servers.'));
return;
}
var res = dispatcher.dispatch(session.get('uid'), chatServers);
cb(null, res.id);
};
// app configuration
app.configure('production|development', function(){
app.set('connectorConfig',
{
connector : pomelo.connectors.hybridconnector,
heartbeat : 3,
useDict : true,
useProtobuf : true
});
app.enable('systemMonitor');
app.route('chat', chatRoute)
});
app.configure('production|development', 'chat', function(){
app.set('chatService', new ChatService(app));
});
app.configure('production|development', 'master', function() {
});
// start app
app.start();
process.on('uncaughtException', function (err) {
console.error(' Caught exception: ' + err.stack);
});