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

Start process for lordofpomelo

demon0925 edited this page Nov 9, 2012 · 3 revisions

Lordofpomelo is developed under Pomelo framework standard, the boot process adopt Pomelo's startup mode, please read the reference before reading this wiki [pomelo start link].

App.js is the entrance of lordofpomelo start process, its duty mainly includes three different parts: loading components, running the master server, start other servers.

Loading Components

In lordofpemelo, we use multiple components, these components loaded at start time, and provide extended functions, like: data statistics, routing, game initialization and so on.

In lordofpomelo we use script-based statistics method, by running custom scripts, the monitor module can collect servers' running data and information to generate reports.

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

Lordofpomelo startup also load area configuration to create the mapping between scenes and area servers.

	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 routing among the servers, lordofpomelo loaded custom routing components.It uses scene mapping to make sure players can be routed to correct area server.

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

In addition to the server generic configuration, app is also responsible for the initialization of the different services, such as global server initialization and the area server initialization, as well as path finding servers. The initialization process will be difference among different servers, depending on the type of the server.

app.configure('production|development', 'area', function(){
	var areaId = app.get('curServer').area;
	if(!areaId || areaId < 0) {
		throw new Error('load area config failed');
	}
	world.init(dataApi.area.all());
	area.init(dataApi.area.findById(areaId));
});

Path finding services and mysql initialization.

app.configure('production|development', 'path', function(){
	pathRemote.init();
});

app.configure('production|development', 'area|auth|connector|master', function() {
	var dbclient = require('./app/dao/mysql/mysql').init(app);
	app.load(pomelo.sync, {path:__dirname + '/app/dao/mapping', dbclient: dbclient});
});

Server startup

The Master component responsible for starting all other servers. The startup process is divided into two steps. First, master will start all other server via ssh command. After a server was started, the monitor component will connect to master, indicating that the server is booted. Second, after all the servers are booted, mater will invoke the afterStart interface of all the servers, to do after start job.

Clone this wiki locally