Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
NextZeus committed Feb 19, 2017
1 parent efa352c commit 5b3a774
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 129 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -66,6 +66,27 @@ Colorbox is our team's another open source project. It is a client side game eng
* Visit the [lordofpomelo](http://pomelo.netease.com/lordofpomelo)
* or you can visit [github:lordofpomelo](http://github.com/NetEase/lordofpomelo)to download the source and install it on your local machine.

## 注意事项
在log4js.json中,将所有log都关掉 否则connector-server 内存会一直飙升

```
log4js.json配置
"levels": {
"con-log": "OFF",
"rpc-log": "ERROR",
"forward-log": "ERROR",
"rpc-debug": "ERROR",
"crash-log": "ERROR",
"admin-log": "ERROR",
"pomelo": "ERROR",
"pomelo-admin": "ERROR",
"pomelo-rpc": "ERROR",
}
关闭con-log
```


## License
Expand Down
236 changes: 118 additions & 118 deletions game-server/app.js
Expand Up @@ -17,150 +17,150 @@ var app = pomelo.createApp();
app.set('name', 'lord of pomelo');

// configure for global
app.configure('production|development', function() {
app.before(pomelo.filters.toobusy());
app.enable('systemMonitor');
require('./app/util/httpServer');

//var sceneInfo = require('./app/modules/sceneInfo');
var onlineUser = require('./app/modules/onlineUser');
if(typeof app.registerAdmin === 'function'){
//app.registerAdmin(sceneInfo, {app: app});
app.registerAdmin(onlineUser, {app: app});
}
//Set areasIdMap, a map from area id to serverId.
if (app.serverType !== 'master') {
var areas = app.get('servers').area;
var areaIdMap = {};
for(var id in areas){
areaIdMap[areas[id].area] = areas[id].id;
}
app.set('areaIdMap', areaIdMap);
}
// proxy configures
app.set('proxyConfig', {
cacheMsg: true,
interval: 30,
lazyConnection: true
// enableRpcLog: true
});

// remote configures
app.set('remoteConfig', {
cacheMsg: true,
interval: 30
});

// route configures
app.route('area', routeUtil.area);
app.route('connector', routeUtil.connector);

app.loadConfig('mysql', app.getBase() + '/../shared/config/mysql.json');
app.filter(pomelo.filters.timeout());

/*
// master high availability
app.use(masterhaPlugin, {
zookeeper: {
server: '127.0.0.1:2181',
path: '/pomelo/master'
app.configure('production|development', function () {
app.before(pomelo.filters.toobusy());
app.enable('systemMonitor');
require('./app/util/httpServer');

//var sceneInfo = require('./app/modules/sceneInfo');
var onlineUser = require('./app/modules/onlineUser');
if (typeof app.registerAdmin === 'function') {
//app.registerAdmin(sceneInfo, {app: app});
app.registerAdmin(onlineUser, {app: app});
}
});
*/
//Set areasIdMap, a map from area id to serverId.
if (app.serverType !== 'master') {
var areas = app.get('servers').area;
var areaIdMap = {};
for (var id in areas) {
areaIdMap[areas[id].area] = areas[id].id;
}
app.set('areaIdMap', areaIdMap);
}
// proxy configures
app.set('proxyConfig', {
cacheMsg: true,
interval: 30,
lazyConnection: true
// enableRpcLog: true
});

// remote configures
app.set('remoteConfig', {
cacheMsg: true,
interval: 30
});

// route configures
app.route('area', routeUtil.area);
app.route('connector', routeUtil.connector);

app.loadConfig('mysql', app.getBase() + '/../shared/config/mysql.json');
app.filter(pomelo.filters.timeout());

/*
// master high availability
app.use(masterhaPlugin, {
zookeeper: {
server: '127.0.0.1:2181',
path: '/pomelo/master'
}
});
*/
});

// Configure for auth server
app.configure('production|development', 'auth', function() {
// load session congfigures
app.set('session', require('./config/session.json'));
app.configure('production|development', 'auth', function () {
// load session congfigures
app.set('session', require('./config/session.json'));
});

// Configure for area server
app.configure('production|development', 'area', function(){
app.filter(pomelo.filters.serial());
app.before(playerFilter());

//Load scene server and instance server
var server = app.curServer;
if(server.instance){
instancePool.init(require('./config/instance.json'));
app.areaManager = instancePool;
}else{
scene.init(dataApi.area.findById(server.area));
app.areaManager = scene;
/*
kill -SIGUSR2 <pid>
http://localhost:3272/inspector.html?host=localhost:9999&page=0
*/
/*
// disable webkit-devtools-agent
var areaId = parseInt(server.area);
if(areaId === 3) { // area-server-3
require('webkit-devtools-agent');
var express = require('express');
var expressSvr = express.createServer();
expressSvr.use(express.static(__dirname + '/devtools_agent_page'));
var tmpPort = 3270 + areaId - 1;
expressSvr.listen(tmpPort);
app.configure('production|development', 'area', function () {
app.filter(pomelo.filters.serial());
app.before(playerFilter());

//Load scene server and instance server
var server = app.curServer;
if (server.instance) {
instancePool.init(require('./config/instance.json'));
app.areaManager = instancePool;
} else {
scene.init(dataApi.area.findById(server.area));
app.areaManager = scene;
/*
kill -SIGUSR2 <pid>
http://localhost:3272/inspector.html?host=localhost:9999&page=0
*/
/*
// disable webkit-devtools-agent
var areaId = parseInt(server.area);
if(areaId === 3) { // area-server-3
require('webkit-devtools-agent');
var express = require('express');
var expressSvr = express.createServer();
expressSvr.use(express.static(__dirname + '/devtools_agent_page'));
var tmpPort = 3270 + areaId - 1;
expressSvr.listen(tmpPort);
}
*/
}
*/
}

//Init areaService
areaService.init();
//Init areaService
areaService.init();
});

app.configure('production|development', 'manager', function(){
var events = pomelo.events;
app.configure('production|development', 'manager', function () {
var events = pomelo.events;

app.event.on(events.ADD_SERVERS, instanceManager.addServers);
app.event.on(events.ADD_SERVERS, instanceManager.addServers);

app.event.on(events.REMOVE_SERVERS, instanceManager.removeServers);
app.event.on(events.REMOVE_SERVERS, instanceManager.removeServers);
});

// Configure database
app.configure('production|development', 'area|auth|connector|master', function() {
var dbclient = require('./app/dao/mysql/mysql').init(app);
app.set('dbclient', dbclient);
// app.load(pomelo.sync, {path:__dirname + '/app/dao/mapping', dbclient: dbclient});
app.use(sync, {sync: {path:__dirname + '/app/dao/mapping', dbclient: dbclient}});
app.configure('production|development', 'area|auth|connector|master', function () {
var dbclient = require('./app/dao/mysql/mysql').init(app);
app.set('dbclient', dbclient);
// app.load(pomelo.sync, {path:__dirname + '/app/dao/mapping', dbclient: dbclient});
app.use(sync, {sync: {path: __dirname + '/app/dao/mapping', dbclient: dbclient}});
});

app.configure('production|development', 'connector', function(){
var dictionary = app.components['__dictionary__'];
var dict = null;
if(!!dictionary){
dict = dictionary.getDict();
}

app.set('connectorConfig',
{
connector : pomelo.connectors.hybridconnector,
heartbeat : 30,
useDict : true,
useProtobuf : true,
handshake : function(msg, cb){
cb(null, {});
}
});
app.configure('production|development', 'connector', function () {
var dictionary = app.components['__dictionary__'];
var dict = null;
if (!!dictionary) {
dict = dictionary.getDict();
}

app.set('connectorConfig',
{
connector: pomelo.connectors.hybridconnector,
heartbeat: 30,
useDict: true,
useProtobuf: true,
handshake: function (msg, cb) {
cb(null, {});
}
});
});

app.configure('production|development', 'gate', function(){
app.set('connectorConfig',
{
connector : pomelo.connectors.hybridconnector,
useProtobuf : true
});
app.configure('production|development', 'gate', function () {
app.set('connectorConfig',
{
connector: pomelo.connectors.hybridconnector,
useProtobuf: true
});
});
// Configure for chat server
app.configure('production|development', 'chat', function() {
app.set('chatService', new ChatService(app));
app.configure('production|development', 'chat', function () {
app.set('chatService', new ChatService(app));
});

//start
app.start();

// Uncaught exception handler
process.on('uncaughtException', function(err) {
console.error(' Caught exception: ' + err.stack);
process.on('uncaughtException', function (err) {
console.error(' Caught exception: ' + err.stack);
});
21 changes: 14 additions & 7 deletions game-server/app/servers/connector/handler/entryHandler.js
Expand Up @@ -27,6 +27,7 @@ var pro = Handler.prototype;
* @return {Void}
*/
pro.entry = function(msg, session, next) {
console.log('entry: ',msg);
var token = msg.token, self = this;

if(!token) {
Expand All @@ -39,7 +40,8 @@ pro.entry = function(msg, session, next) {
function(cb) {
// auth token
self.app.rpc.auth.authRemote.auth(session, token, cb);
}, function(code, user, cb) {
},
function(code, user, cb) {
// query player info by user id
if(code !== Code.OK) {
next(null, {code: code});
Expand All @@ -53,13 +55,16 @@ pro.entry = function(msg, session, next) {

uid = user.id;
userDao.getPlayersByUid(user.id, cb);
}, function(res, cb) {
},
function(res, cb) {
// generate session and register chat status
players = res;
self.app.get('sessionService').kick(uid, cb);
}, function(cb) {
},
function(cb) {
session.bind(uid, cb);
}, function(cb) {
},
function(cb) {
if(!players || players.length === 0) {
next(null, {code: Code.OK});
return;
Expand All @@ -72,21 +77,23 @@ pro.entry = function(msg, session, next) {
session.set('playerId', player.id);
session.on('closed', onUserLeave.bind(null, self.app));
session.pushAll(cb);
}, function(cb) {
self.app.rpc.chat.chatRemote.add(session, player.userId, player.name,
channelUtil.getGlobalChannelName(), cb);
},
function(cb) {
self.app.rpc.chat.chatRemote.add(session, player.userId, player.name, channelUtil.getGlobalChannelName(), cb);
}
], function(err) {
if(err) {
next(err, {code: Code.FAIL});
return;
}
console.log('entry success!!!!');

next(null, {code: Code.OK, player: players ? players[0] : null});
});
};

var onUserLeave = function (app, session, reason) {
console.log('onUserLeave-reason: ', reason);
if(!session || !session.uid) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion game-server/app/servers/gate/handler/gateHandler.js
Expand Up @@ -27,5 +27,4 @@ Handler.prototype.queryEntry = function(msg, session, next) {

var res = dispatcher.dispatch(uid, connectors);
next(null, {code: Code.OK, host: res.host, port: res.clientPort});
// next(null, {code: Code.OK, host: res.pubHost, port: res.clientPort});
};
13 changes: 10 additions & 3 deletions game-server/config/log4js.json
Expand Up @@ -66,9 +66,16 @@
],

"levels": {
"rpc-log" : "ERROR",
"forward-log": "ERROR"
},
"con-log": "OFF",
"rpc-log": "ERROR",
"forward-log": "ERROR",
"rpc-debug": "ERROR",
"crash-log": "ERROR",
"admin-log": "ERROR",
"pomelo": "ERROR",
"pomelo-admin": "ERROR",
"pomelo-rpc": "ERROR"
},

"replaceConsole": true
}

0 comments on commit 5b3a774

Please sign in to comment.