ubuntu安装nodejs+pomelo+webstrom
程序员文章站
2022-03-23 22:36:56
...
https://github.com/NetEase/pomelo/wiki/pomelo%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97点击打开链接
https://github.com/NetEase/pomelo/wiki/tutorial1--%E5%88%86%E5%B8%83%E5%BC%8F%E8%81%8A%E5%A4%A9
https://github.com/NetEase/pomelo/wiki/Home-in-Chinese#%E6%BC%94%E7%A4%BA
如果出现 Cannot find module 'pomelo-logger'就在 /usr/webserver/new_pomelo/chatofpomelo-websocket# npm install pomelo-logger
如果出现在日志中出现unknown module: "onlineUser".就在app.js中添加
app.configure('production|development', function() { app.enable('systemMonitor'); var onlineUser = require('./app/onlineUser/onlineUser'); if(typeof app.registerAdmin === 'function'){ //app.registerAdmin(sceneInfo, {app: app}); app.registerAdmin(onlineUser, {app: app}); } });并在game-server-->app中添加 onlineUser文件-->添加onlineUser.js
onlineUser.js中的内容为
/*! * Pomelo -- consoleModule onlineUser * Copyright(c) 2012 fantasyni并在game-server-->app->util中添加utils.js* MIT Licensed */ 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 || 5; }; 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.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)); };
utils.js内容为:
var utils = module.exports; // control variable of func "myPrint" var isPrintFlag = false; // var isPrintFlag = true; /** * Check and invoke callback function */ utils.invokeCallback = function(cb) { if(!!cb && typeof cb === 'function') { cb.apply(null, Array.prototype.slice.call(arguments, 1)); } }; /** * clone an object */ utils.clone = function(origin) { if(!origin) { return; } var obj = {}; for(var f in origin) { if(origin.hasOwnProperty(f)) { obj[f] = origin[f]; } } return obj; }; utils.size = function(obj) { if(!obj) { return 0; } var size = 0; for(var f in obj) { if(obj.hasOwnProperty(f)) { size++; } } return size; }; // print the file name and the line number ~ begin function getStack(){ var orig = Error.prepareStackTrace; Error.prepareStackTrace = function(_, stack) { return stack; }; var err = new Error(); Error.captureStackTrace(err, arguments.callee); var stack = err.stack; Error.prepareStackTrace = orig; return stack; } function getFileName(stack) { return stack[1].getFileName(); } function getLineNumber(stack){ return stack[1].getLineNumber(); } utils.myPrint = function() { if (isPrintFlag) { var len = arguments.length; if(len 然后在重新运行game-server中的app.js就可以了以上就介绍了ubuntu安装nodejs+pomelo+webstrom,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: php如何替换多个字符串
下一篇: javascript怎么清除cookie