Home Backend Development PHP Tutorial Install nodejs+pomelo+webstrom on ubuntu

Install nodejs+pomelo+webstrom on ubuntu

Jul 29, 2016 am 09:02 AM
function module return var

https://github.com/NetEase/pomelo/wiki/pomelo%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D %97Click to open the link

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

If Cannot find module 'pomelo-logger' appears Just at /usr/webserver/new_pomelo/chatofpomelo-websocket# npm install pomelo-logger

If unknown module: "onlineUser" appears in the log. Add

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});
	}
});
Copy after login
to app.js and add the onlineUser file to game-server-->app-->Add onlineUser.js The content in

onlineUser.js is

/*!
 * Pomelo -- consoleModule onlineUser 
 * Copyright(c) 2012 fantasyni <fantasyni@163.com>
 * 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));
};
Copy after login
and add utils.js in game-server-->app->util

utils.js content is:

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

Copy after login
and then re-run app.js in game-server

The above introduces the installation of nodejs+pomelo+webstrom on ubuntu, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

Detailed explanation of the usage of return in C language

What does function mean? What does function mean? Aug 04, 2023 am 10:33 AM

What does function mean?

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

What is the execution order of return and finally statements in Java?

ModuleNotFoundError: How to solve Python module not found error? ModuleNotFoundError: How to solve Python module not found error? Jun 25, 2023 pm 09:30 PM

ModuleNotFoundError: How to solve Python module not found error?

Java9 new feature Module modular programming method Java9 new feature Module modular programming method May 19, 2023 pm 01:51 PM

Java9 new feature Module modular programming method

The role and examples of var keyword in PHP The role and examples of var keyword in PHP Jun 28, 2023 pm 08:58 PM

The role and examples of var keyword in PHP

18 Ways to Fix Audio Service Not Responding Issue on Windows 11 18 Ways to Fix Audio Service Not Responding Issue on Windows 11 Jun 05, 2023 pm 10:23 PM

18 Ways to Fix Audio Service Not Responding Issue on Windows 11

What is the purpose of the 'enumerate()' function in Python? What is the purpose of the 'enumerate()' function in Python? Sep 01, 2023 am 11:29 AM

What is the purpose of the 'enumerate()' function in Python?

See all articles