当前位置:Gxlcms > PHP教程 > ubuntu安装nodejs+pomelo+webstrom

ubuntu安装nodejs+pomelo+webstrom

时间:2021-07-01 10:21:17 帮助过:8人阅读

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 
 * 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));
};
并在game-server-->app->util中添加utils.js

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 <= 0) {
      return;
    }
    var stack = getStack();
    var aimStr = '\'' + getFileName(stack) + '\' @' + getLineNumber(stack) + ' :\n';
    for(var i = 0; i < len; ++i) {
      aimStr += arguments[i] + ' ';
    }
    console.log('\n' + aimStr);
  }
};
// print the file name and the line number ~ end

然后在重新运行game-server中的app.js就可以了

以上就介绍了ubuntu安装nodejs+pomelo+webstrom,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行