}
var pomelo = require('pomelo');
/** */
// route configures
// filter configures
});process.on('uncaughtexception', function(err) );
注意:在webstorm下除錯,可能因為工作目錄的設定原因會導致應用的執行路徑問題,導致無法讀取配置檔案,所以需要根據實際情況修改如下
var opt =
opt.base 是你的game-server的實際目錄路徑,具體可以根據自己需要來定製
pomelo/lib/pomelo.js
};
/**
* * @module
*//**
*//**
* initialize the server.
* * - setup default configuration
* * @api private
*/ opts = opts || {};
this.loaded = ;
this.components = {};
this.settings = {}; // set,和get功能的容器
this.set('base', opts.base); //設定伺服器的工作目錄
this.defaultconfiguration(); //根據配置檔案,載入master,monitor等伺服器
};
/**
* * @api private
*/ var args = utils.argsinfo(process.argv);
this.loadservers(); //載入伺服器配置資訊
this.loadconfig('master', this.getbase() + '/config/master.json'); //載入mater伺服器配置資訊
this.processargs(args); //根據啟動引數設定伺服器配置
this.configlogger();
};
utils.argsinfo(process.argv); 獲取系統啟動引數,我們不妨看看到底有哪些引數支援
啟動game-server伺服器:>pomelo start [development | production] [--daemon]
/**
* setup enviroment.
* @api private
*/ this.set('env', args.env || process.env.node_env || 'development', true);
};
載入伺服器資訊,並且儲存在__servermap___記憶體下
/**
* load server info from configure file.
* * @api private
*/ this.loadconfig('servers', this.getbase() + '/config/servers.json');
var servers = this.get('servers');
var servermap = {}, slist, i, l, server;
for(var servertype in servers) ,,],
"chat":[,,
],"gate":[
] },
"production":,,],
"chat":[,,
],"gate":[
] }
}
工具函式,讀取json配置檔案,在這裡讀取的是master.json檔案
/**
* load configure json file to settings.
* * @param key environment key
* @param val environment value
* @return for chaining, or the setting value
* */
var env = this.get('env');
val = require(val);
if (val[env])
this.set(key, val);
};
master.json
,
"production":
}
根據程序讀取配置好的引數,配置伺服器。
var servertype = args.servertype || 'master';
var serverid = args.serverid || this.get('master').id;
this.set('main', args.main, true);
this.set('servertype', servertype, true);
this.set('serverid', serverid, true);
if(servertype !== 'master') else
};專案的日誌配置
if(process.env.pomelo_logger !== 'off')
};log4js.json
.log",
"filesize": 1048576,
"layout": ,
"backups": 5},,
.log",
"pattern": "connector",
"filesize": 1048576,
"layout":
,"backups": 5,
"category":"con-log"
},.log",
"filesize": 1048576,
"layout":
,"backups": 5,
"category":"rpc-log"
},.log",
"filesize": 1048576,
"layout":
,"backups": 5,
"category":"forward-log"
},,"backups": 5,
"category":"crash-log"}],
"levels": ,
"replaceconsole": true
}
pomelo原始碼分析(三)
param cb callback function if this.state state inited this.loaddefaultcomponents var self this this.optcomponents start function err api private var p...
pomelo原始碼分析(1)
首先我們來分析一下 at pinus.ts opts 繼續往下看 init opts let base opts.base process.cwd this set constants.reserved base base this base base defaultconfiguration th...
pomelo原始碼解析之元件Remote
首先提出問題 1.元件remote是什麼?2.remote的作用是什麼?remote模組是遠端通訊模組服務端監聽模組,作用是作為各個模組間通訊物件的存在。變數中儲存.return paths var paths var role master server should not come here ...