-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Pomelo 0.2到0.3升级指南
##servers.json配置文件的修改
随着Pomelo支持协议的增多,配置文件原先定义的wsPort
(代表websocket port)已不适用,现调整为clientPort
。并新增一个字段frontend来标识该服务器是否是前端服务器,前端服务器 必须 设置该字段为true,后端服务器可以不设置或设置成false。
以lordofpomelo为例,servers.js文件修改如下。
connector服务器配置:
"connector": [
{"id": "connector-server-1", "host": "127.0.0.1", "port": 3150, "clientPort": 3010, "frontend": true},
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort":3011, "frontend": true}
]
gate服务器配置:
"gate": [
{"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true}
]
服务器代码中有依赖到配置信息wsPort
的地方也需要做相应的调整。lordofpomelo中的gateHandler中的res.wsPort
需要改为res.clientPort
。
##connector配置
0.2中基于socket.io connector的服务器代码可以无需修改就能使用。
如要使用支持socket和websocket的connector,在app.js配置指定使用hybridconnector即可。使用例子如下:
app.configure('production|development', 'connector', function(){
app.set('connectorConfig', {
connector: pomelo.connectors.hybridconnector,
heartbeat: 3,
useDict: true,
useProtobuf: true,
checkClient: function(type, version) {
// check the client type and version then return true or false
},
handshake: function(msg, cb){
cb(null, {/* message pass to client in handshake phase */});
}
});
});
更详细的信息和多connector的共存请参考Pomelo 0.3新特性文档。
##route字典压缩配置 route字典压缩支持在传输过程中对route字段进行压缩,这一修改对用户是完全透明的,只要在app.js中打开可以启用,具体配置如下:
app.set('connectorConfig', {
connector: pomelo.connectors.hybridconnector,
heartbeat: 3,
useDict: true,
handshake: function(msg, cb){
cb(null, {/* message pass to client in handshake phase */});
}
});
其中“useDict:true”项就会打开字典压缩功能,之后所有的系统生成route在传输时就会自动进行压缩,而这一过程对用户是完全透明的。 对于用户自定义的route,需要在项目中加入/game-server/config/dictionary.json文件,在其中定义需要压缩的route,系统在传输时会自动进行替换,以lordofpomelo为例,dictionary.json的格式如下:
[
"onDropItem",
"onAttack",
"onDied",
"onMove",
"onUpgrage",
"onPickItem",
"onRevive",
"addEntities",
"onRemoveEntities",
"onPathCheckout"
]
##protobuf压缩配置
TODO
##web客户端build配置
TODO