Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

LordOfPomelo startup process

Charlie Crane edited this page Oct 31, 2013 · 3 revisions

LordOfPomelo's startup process is based on pomelo startup process. Before reading the following content, please read pomelo execution flow.

app.js is LordOfPomelo's entrance, it is responsible for all the servers' configuration, as well as loading and starting components. LordOfPomelo's startup process are divided into two steps: start the master server, start other servers respectively by the master server.

Component configuration and loading

LordOfPomelo uses many external components, these components are loaded at the server startup, providing various services: such as data statistic, routing function replacement, game scene initialization, etc.

LordOfPomelo uses a script-based statistics. These components collect server's running data and generate reports by running custom script. More specific functions, please see:

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

When LordOfPomelo is starting, it will load the configuration files for areas, to establish a mapping between areas and servers:

  //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);
	}

In order to get the correct routing in multiple area servers, LordOfPomelo loads custom routing component. By using the mapping information between scenes and servers, LordOfPomelo ensures that the player's requests are distributed to the corresponding area server:

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

In addition to the general configuration of the server, the "app.js" is also responsible for the initialization of different services: such as the global server's initialization, area server's initialization, as well as the pathfinding server's initialization. Different servers will do different initialization process according to the type of 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;
  }
  //Init areaService
  areaService.init();
});

Data synchronization plugin and MySql initialization:

// 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.use(sync, {sync: {path:__dirname + '/app/dao/mapping', dbclient: dbclient}});
}); 

Server startup

LordOfPomelo's startup process is using the startup mode of Pomelo framework, uses the master as a default component. The master component will be loaded and started in the "app.js" after "app.start()".

Master component is responsible for starting all other services. The startup process is divided into two phases: The first stage, the master service starts all other servers. After launching the server, the monitor component will connect to master's corresponding listener port, showing that the server's startup is completed. The second stage, after finishing all servers' startup, mater will call all "afterStart" interfaces on servers, to perform the work after starting.

Clone this wiki locally