Skip to content

Commit

Permalink
工具库 统一方到lordofpomelo项目中
Browse files Browse the repository at this point in the history
  • Loading branch information
NextZeus committed Mar 4, 2017
1 parent 5b3a774 commit 390e11a
Show file tree
Hide file tree
Showing 2,087 changed files with 111,078 additions and 77 deletions.
52 changes: 52 additions & 0 deletions game-server/admin/onlineUser.js
@@ -0,0 +1,52 @@
/**
* Created by lixiaodong on 17/3/4.
*/
'use strict';

var PomeloAdmin = require('pomelo-admin');

/**
* 获取在线人数
* @param data
* @param callback
*/
function onlineUser(data, callback) {
console.log("获取在线人数" + JSON.stringify(data));
var jsonData = {};
var client = new PomeloAdmin.adminClient({username: data.username, password: data.password});
client.connect('game-admin', data.host, data.port, function (errConnect, msgConnect) {
if (errConnect) {
jsonData.code = 1;
jsonData.message = '连接游戏服务器失败' + data.host + ":" + data.port;
console.log(JSON.stringify(errConnect));
callback(jsonData);
client.socket.disconnect();
} else {
//console.log('连接游戏服务器成功' + data.host + ":" + data.port);
client.request('onlineUser', null, function (errRequest, msgRequest) {
if (errRequest) {
jsonData.code = 1;
jsonData.message = '获取在线人数失败';
} else {
jsonData.code = 0;
jsonData.data = msgRequest;
}
console.log(JSON.stringify(jsonData));
callback(jsonData);
client.socket.disconnect();
process.exit(0);
});
}
});
}

var data = {
username: 'admin',
password: 'admin',
host: '127.0.0.1',
port: 3005
}

onlineUser(data, function (data) {
})

17 changes: 13 additions & 4 deletions game-server/app.js
Expand Up @@ -16,18 +16,27 @@ var sync = require('pomelo-sync-plugin');
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');
app.filter(pomelo.filters.time()); //开启conn日志,对应pomelo-admin模块下conn request
app.rpcFilter(pomelo.rpcFilters.rpcLog());//开启rpc日志,对应pomelo-admin模块下rpc request

// var sceneInfo = require('./app/modules/sceneInfo');
var onlineUser = require('./app/modules/onlineUser');
if (typeof app.registerAdmin === 'function') {
//app.registerAdmin(sceneInfo, {app: app});
// app.registerAdmin(sceneInfo, {app: app});
app.registerAdmin(onlineUser, {app: app});
}
});

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

require('./app/util/httpServer');

//Set areasIdMap, a map from area id to serverId.
if (app.serverType !== 'master') {
var areas = app.get('servers').area;
Expand Down
137 changes: 101 additions & 36 deletions game-server/app/modules/onlineUser.js
Expand Up @@ -3,51 +3,116 @@
* Copyright(c) 2012 fantasyni <fantasyni@163.com>
* MIT Licensed
*/
var logger = require('pomelo-logger').getLogger(__filename);
var utils = require('../util/utils');
// var logger = require('pomelo-logger').getLogger(__filename);
// var utils = require('../util/utils');
//
// module.exports = function(opts) {
// return new Module(opts);
// };
//
// module.exports.moduleId = 'onlineUser';
//
// var Module = function(opts) {
// opts = opts || {};
// this.app = opts.app;
// this.type = opts.type || 'pull';
// this.interval = opts.interval || 30;
// };
//
// Module.prototype.monitorHandler = function(agent, msg) {
// var connectionService = this.app.components.__connection__;
// if(!connectionService) {
// logger.error('not support connection: %j', agent.id);
// return;
// }
// var info = connectionService.getStatisticsInfo();
// agent.notify(module.exports.moduleId, info);
// };
//
// Module.prototype.masterHandler = function(agent, msg) {
// if(!msg) {
// // pull interval callback
// var list = agent.typeMap['connector'];
// if(!list || list.length === 0) {
// return;
// }
// agent.notifyByType('connector', module.exports.moduleId);
// return;
// }
//
// var data = agent.get(module.exports.moduleId);
// if(!data) {
// data = {};
// agent.set(module.exports.moduleId, data);
// }
//
// data[msg.serverId] = msg;
// };
//
// Module.prototype.clientHandler = function(agent, msg, cb) {
// utils.invokeCallback(cb, null, agent.get(module.exports.moduleId));
// };

module.exports = function(opts) {
return new Module(opts);
var async = require('async');

module.exports = function (opts) {
return new Module(opts);
};

module.exports.moduleId = 'onlineUser';

var Module = function(opts) {
opts = opts || {};
this.app = opts.app;
this.type = opts.type || 'pull';
this.interval = opts.interval || 5;
var Module = function (opts) {
opts = opts || {};
this.app = opts.app;
};

Module.prototype.monitorHandler = function(agent, msg) {
var connectionService = this.app.components.__connection__;
if(!connectionService) {
logger.error('not support connection: %j', agent.id);
return;
}
agent.notify(module.exports.moduleId, connectionService.getStatisticsInfo());
};
Module.prototype.monitorHandler = function (agent, msg, cb) {
var app = this.app;

Module.prototype.masterHandler = function(agent, msg) {
if(!msg) {
// pull interval callback
var list = agent.typeMap['connector'];
if(!list || list.length === 0) {
return;
}
agent.notifyByType('connector', module.exports.moduleId);
return;
}
var connection = app.components.__connection__;
if (!connection) {
cb({
serverId: agent.id,
body : 'error'
});
return;
}

var data = agent.get(module.exports.moduleId);
if(!data) {
data = {};
agent.set(module.exports.moduleId, data);
var connectionService = this.app.components.__connection__;
if(!connectionService) {
// logger.error('not support connection: %j', agent.id);
return;
}

data[msg.serverId] = msg;
var info = connectionService.getStatisticsInfo();
console.log('serverId: ' ,agent.id, ' info: ', info);
cb(null, {
serverId: agent.id,
body : info
});
};

Module.prototype.clientHandler = function(agent, msg, cb) {
utils.invokeCallback(cb, null, agent.get(module.exports.moduleId));
};
Module.prototype.clientHandler = function (agent, msg, cb) {
var app = this.app;
var servers = app.getServersByType('connector');
var onLineUser = {};
if(servers){
async.mapSeries(servers,function(server,callback){
agent.request(server.id, module.exports.moduleId, msg, function(err,info){
if(err){
cb(null,{body : 'err'});
return;
}
delete info.body.loginedList;
onLineUser[server.id] = info.body;
callback();
});
},function(err,res){
console.log('onLineUser: ', onLineUser);
cb(null,{
body : onLineUser
});
});
}else{
cb(null,{boyd : onLineUser});
}
};
19 changes: 9 additions & 10 deletions game-server/config/log4js.json
Expand Up @@ -64,17 +64,16 @@
"category":"admin-log"
}
],

"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": "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
Expand Down
4 changes: 3 additions & 1 deletion game-server/config/servers.json
Expand Up @@ -2,7 +2,9 @@
"development": {
"connector": [
{"id": "connector-server-1", "host": "127.0.0.1", "port": 3150, "clientPort": 3010, "frontend": true},
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort": 3011, "frontend": true}
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort": 3011, "frontend": true},
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort": 3012, "frontend": true},
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort": 3013, "frontend": true}
],
"area": [
{"id": "area-server-1", "host": "127.0.0.1", "port": 3250, "area": 1},
Expand Down
45 changes: 22 additions & 23 deletions game-server/package.json
Expand Up @@ -3,30 +3,29 @@
"version": "0.3.0",
"private": false,
"dependencies": {
"express": "2.5.2"
, "connect": ">=0.0.1"
, "socket.io": ">=0.9.6"
, "generic-pool": "*"
, "mysql": ">=2.0"
, "pomelo": "~2.2.5"
, "async": ">=0.0.1"
, "socket.io-client" : ">=0.9.6"
, "pomelo-aoi" : ">=0.3.4"
, "crc" : ">=0.0.1"
, "pomelo-bt": ">=0.0.1"
, "pomelo-pathfinding": ">=0.1.0"
, "pomelo-collection": ">=0.1.0"
, "pomelo-logger": "0.0.3"
, "pomelo-monitor": ">=0.3.3"
, "pomelo-sync-plugin": "0.0.1"
, "pomelo-masterha-plugin": "0.0.4"
, "underscore": "1.5.2"
, "node-zookeeper-client": "0.2.0"
, "webkit-devtools-agent" : "0.1.2"
"async": ">=0.0.1",
"connect": ">=0.0.1",
"crc": ">=0.0.1",
"express": "2.5.2",
"generic-pool": "*",
"mysql": ">=2.0",
"node-zookeeper-client": "0.2.0",
"pomelo": "~2.2.5",
"pomelo-aoi": ">=0.3.4",
"pomelo-bt": ">=0.0.1",
"pomelo-collection": ">=0.1.0",
"pomelo-logger": "0.0.3",
"pomelo-masterha-plugin": "0.0.4",
"pomelo-monitor": ">=0.3.3",
"pomelo-pathfinding": ">=0.1.0",
"pomelo-sync-plugin": "0.0.1",
"socket.io": ">=0.9.6",
"socket.io-client": ">=0.9.6",
"underscore": "1.5.2",
"webkit-devtools-agent": "0.1.2"
},
"devDependencies": {
"should": ">=0.0.1"
, "mocha": ">=0.0.1"
"should": ">=0.0.1",
"mocha": ">=0.0.1"
}
}

2 changes: 1 addition & 1 deletion game-server/scripts/logger.js
@@ -1 +1 @@
result = logger.info("hello");fd
result = logger.info("hello");
11 changes: 11 additions & 0 deletions pomelo-admin-web/.gitignore
@@ -0,0 +1,11 @@
.project
*/node-log.log
logs/*.log
!.gitignore
node_modules/*
.project
.settings/
**/*.svn
*.svn
*.sublime-project
*.sublime-workspace
22 changes: 22 additions & 0 deletions pomelo-admin-web/LICENSE
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2012 Netease, Inc. and other pomelo contributors

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.
14 changes: 14 additions & 0 deletions pomelo-admin-web/README.md
@@ -0,0 +1,14 @@
# pomelo-admin-web
pomelo-admin-web is a web console for [pomelo](https://github.com/NetEase/pomelo). it is based on [pomelo-admin](https://github.com/NetEase/pomelo-admin). it is just an web console example, you can implement your style like web console.

##Installation
```
npm install pomelo-admin-web
```
##Usage
just run
```
node app.js
```

open browser in your computer,and enjoy it

0 comments on commit 390e11a

Please sign in to comment.