⏲️ kbengine.xml配置
kbengine.xml配置
在这一节中,我们会对引擎kbengine.xml的配置进行详解。该配置文件是引擎核心配置文件,其中包括IP、端口、网卡环境、数据库等。该配置文件位于{项目资产库}/res/server/kbengine.xml
中(在引擎内置配置文件夹下有类似文件:kbengine_default.xml
,并作为引擎配置的默认值),通过修改项目资产库下的kbengine.xml
使配置继承或者叫做覆盖。这样不会破坏引擎的默认设置,在你更新引擎时也不会产生冲突,以及在多个逻辑项目时不会影响到其他的项目设置。

本节内容概要
kbengine_default.xml中的所有配置解释
- 基本配置1(包含gameUpdateHertz、bitsPerSecondToClient等)
- 基本配置2(包含shutdown_time、thread_pool、email_service_config等)
- Channel通道配置
- 服务器各app通用配置字段
- Loginapp配置(默认端口20013)
- Baseapp配置(默认端口20015)
- Cellapp配置
- Logger配置
- DBMgr配置(默认使用Mysql,则端口3306)
- Interfaces配置(默认端口30099)
- Machine配置(默认端口20099)
- Bots配置,在压力测试或内部调试时可以使用bot进行测试。可参考调试章节
更多实例参考:
- 如何在kbengine.xml中进行配置继承或覆盖
- 如何在多网卡下进行配置
- 如何自定义IP、端口
- 如何部署多组KBE服务器
总览:
在某种意义上,{项目资产库}/res/server/kbengine.xml
(以下简称kbengine.xml)文件作为引擎默认配置文件kbengine_default.xml
的子集,在最小assets中没有多少内容。那我们先来看一下kbengine_default.xml
中的部分内容:
1. 基本配置1:
<root>
<!-- 游戏逻辑处理频率HZ(Update frequency process, HZ)-->
<gameUpdateHertz> 10 </gameUpdateHertz>
<!-- 每秒发送到客户端的带宽限制(bit)
(The data sent to the client, the second bandwidth limit (bit))
--><!-- Type: Integer -->
<bitsPerSecondToClient> 20000 </bitsPerSecondToClient>
<!-- 非0则不优化, 不带包长信息的包强制都携带长度信息, 某些情况下方便某些前端对接协议。
那什么样的包不带长度信息? 所有能够预先计算出包大小的且永远不变的包不带长度信息,
如果有可变字符串参数则一定需要带长度信息
(Non-0 is not optimized, Force all packets contain length information, Some convenient docking protocol client.
What of data packet length information does not? All packages can be calculated in advance
and never change the size of the package with no length information.)
-->
<packetAlwaysContainLength> 0 </packetAlwaysContainLength>
<!-- 是否需要将任何接收和发送的包以文本输出到log中提供调试
(Whether the contents of the log output packet)
debug_type:
0: 不输出(Not output)
1: 16进制输出(16 hexadecimal output)
2: 字符流输出(Stringstream output)
3: 10进制输出(10 hexadecimal output)
use_logfile:
是否独立一个log文件来记录包内容,文件名通常为
(Whether the use of other log files ? such as:)
appname_packetlogs.log
disable_msgs:
关闭某些包的输出
(Some messages are not output)
-->
<trace_packet>
<debug_type> 0 </debug_type>
<use_logfile> false </use_logfile>
<disables>
<item>Encrypted::packets</item>
<item>Baseappmgr::updateBaseapp</item>
...
...
<item>Client::onUpdateData_xyz_ypr</item>
</disables>
</trace_packet>
<!-- 是否输出entity的创建, 脚本获取属性, 初始化属性等调试信息, 以及def信息
(Whether the output the logs: create the entity, Script get attributes,
Initialization attributes information, Def information.)
-->
<debugEntity> 0 </debugEntity>
<publish>
<!-- 发布状态, 可在脚本中获取该值。 KBEngine.publish()
(apps released state, This value can be obtained in the script. KBEngine.publish())
Type: Integer8
0 : debug
1 : release
其他自定义(Other custom)
-->
<state> 0 </state>
<!-- 脚本层发布的版本号
(Script layer released version number)
-->
<script_version> 0.1.0 </script_version>
</publish>
...
...
</root>
gameUpdateHertz
: int,游戏逻辑处理频率HZ,即每秒执行的次数。该值越高服务器CPU消耗就越大,请根据业务需求决定。bitsPerSecondToClient
: int,每秒发送到客户端的带宽限制(bit)。如果超过该设定值,则会分批进行发送。packetAlwaysContainLength
: int,packet包是否总是包含长度信息。非0则不优化,会强制所有包都包含长度信息。如果有可变字符串参数则一定需要带长度信息。那什么样的包可以不带长度信息呢?所有能够预先计算出包大小的且永远不变的包不带长度信息。trace_packet
: 跟踪包的调试,在该标签下可以对任何接收和发送的包进行trace调试的配置。
其中:
debug_type
是debug
类型:
0
: 不输出(Not output);1
: 16进制输出(16 hexadecimal output);2
: 字符流输出(Stringstream output);3
: 10进制输出(10 hexadecimal output)。
use_logfile
:是否独立一个log文件来记录包内容。不使用文件记录,则false,否则true。当为true时,可在日志配置中查看packet的log配置
disables
:关闭某些包的输出。每个要关闭的包,在一个item标签内写入包对应的名字(罗列的包名请查看上方XML)。
debugEntity
: int,是否输出entity的创建, 脚本获取属性, 初始化属性调试信息, 以及def信息。publish
: 发布时相关的配置信息。
提示
state
:发布状态,可在api中通过KBEngine.publish()获得。
0
: debug1
: release
script_version
:脚本层发布的版本号。在登录引擎时会验证客户端上的脚本版本号和服务器端的版本号。
2. 基本配置2:
<root>
...
<!-- 关服倒计时(秒) (Countdown to shutdown the server(seconds))
-->
<shutdown_time> 30.0 </shutdown_time>
<!-- 关闭服务器的时候, 如果有未完成的任务, 服务器需要等待任务结束。
每Tick(秒)检查一次
(Shutdown the server, if you have not completed the task, the server needs to wait for the end of the mission.
Time(seconds) for each waiting.)
-->
<shutdown_waittick> 1.0 </shutdown_waittick>
<!-- callback默认超时时间(秒)
(The callback: default timeout(seconds))
-->
<callback_timeout> 300.0 </callback_timeout>
<thread_pool>
<!-- 默认超时时间(秒)
(default timeout(seconds))
-->
<timeout> 300.0 </timeout>
<init_create> 1 </init_create>
<pre_create> 2 </pre_create>
<max_create> 8 </max_create>
</thread_pool>
<!-- Email服务, 提供账号验证, 密码找回等等。
(Email services, providing the account verification, password recovery, etc.)
-->
<email_service_config>server/email_service_defaults.xml</email_service_config>
...
</root>
shutdown_time
: float,关服倒计时(秒)。关服时,服务器会通知客户端,并发送倒计时剩余的秒数。shutdown_waittick
: float,关闭服务器的时候,如果有未完成的任务,服务器需要等待任务结束,该字段表明每多少秒检查一次。callback_timeout
: float,callback默认超时时间(秒)。如果超过该值,则系统认为已经超时。thread_pool
: 线程池的配置。其中:
提示
timeout
:float,默认超时时间(秒):init_create
:int,初始化线程池时,创建的线程数量pre_create
:int,预创建的线程数量。max_create
:int,最大可创建的线程数量。
email_service_config
: string,Email服务的配置文件地址。Email服务可以提供账号验证, 密码找回等功能。
3. Channel通道配置:
<root>
...
<channelCommon>
<!-- 最后一次通信时间超过此时间则被认定为超时通道, 服务器将踢出该通道
(If long (configurable value) no communication, channel will be kicked out of the server.)
-->
<timeout>
<internal> 60.0 </internal>
<external> 60.0 </external>
</timeout>
<!-- socket读写缓冲大小
(socket send/recv buffer size)
-->
<readBufferSize>
<internal> 16777216 </internal> <!-- 16M -->
<external> 0 </external> <!-- 系统默认(system default) -->
</readBufferSize>
<writeBufferSize>
<internal> 16777216 </internal> <!-- 16M -->
<external> 0 </external> <!-- 系统默认(system default) -->
</writeBufferSize>
<!-- 发送与接收窗口溢出值,0无限制
(the value of the send/receive window overflow, 0 is unlimited)
-->
<windowOverflow>
<send>
<!-- 一个tick内发送的字节数溢出限制
(A tick, the value of the sent window overflow, 0 is unlimited)
-->
<tickSentBytes>
<internal> 0 </internal>
<external> 0 </external>
</tickSentBytes>
<messages>
<critical> 1024 </critical>
<internal> 65535 </internal>
<external> 512 </external>
</messages>
<bytes>
<internal> 0 </internal>
<external> 1048576 </external>
</bytes>
</send>
<receive>
<messages>
<critical> 24 </critical>
<internal> 65535 </internal>
<external> 32 </external>
</messages>
<bytes>
<internal> 0 </internal>
<external> 2048 </external>
</bytes>
</receive>
</windowOverflow>
<!-- 加密通信,只对外部通道
(Encrypted communication, channel-external only)
可选择的加密方式(Optional encryption):
0: 无加密(No Encryption)
1: Blowfish
2: RSA (res\key\kbengine_private.key)
-->
<encrypt_type> 1 </encrypt_type>
</channelCommon>
...
</root>
通道都分为internal内部和external外部。内部表示内网间的内部通讯,外部表示对接外部连接的用户或第三方接口。
timeout
: float,超时时间(秒)。最后一次通信时间超过此时间则被认定为超时通道, 服务器将踢出该通道。readBufferSize
: int,socket读缓冲的大小(bit)。0值表示系统默认的值。writeBufferSize
: int,socket写缓冲的大小(bit)。0值表示系统默认的值。windowOverflow
: 发送与接收窗口溢出值配置。0值表示无限制。其中:
提示
tickSentBytes
:int,一个tick内发送的字节数溢出限制messages
:int,消息的数量溢出限制messages
.critical:int,警告值,如果超出该值,则开始警告。bytes
:int,字节数溢出限制。
encrypt_type
: int,是否加密通过以及加密类型(只对外部通道external)。
提示
0
:无加密(No Encryption)1
:Blowfish2
:RSA (在res\key\kbengine_private.key下可以配置RSA的KEY)
4. 服务器各app通用配置字段:
<root>
...
<!-- 脚本入口模块, 相当于main函数
(Entry module, like the main-function)
-->
<entryScriptFile> kbemain </entryScriptFile>
<!-- 指定接口地址,可配置网卡名、MAC、IP
(Interface address specified, configurable NIC/MAC/IP)
-->
<internalInterface> </internalInterface>
<externalInterface> </externalInterface>
<!-- Telnet服务, 如果端口被占用则向后尝试32001..
(Telnet service, if the port is occupied backwards to try 32001)
-->
<telnet_service>
<port> 32000 </port>
<password> pwd123456 </password>
<!-- 命令默认层
(layer of default the command)
-->
<default_layer> python </default_layer>
</telnet_service>
...
</root>
entryScriptFile
: string,脚本入口模块, 相当于main函数。internalInterface
: string,指定内部的接口地址,可配置网卡名、MAC、IP。当有多网卡时,需要明确指定是哪个网卡。见如何:多网卡的配置externalInterface
: string,指定外部的接口地址,可配置网卡名、MAC、IP。当有多网卡时,需要明确指定是哪个网卡。telnet_service
: Telnet服务的配置。Telnet是内部通讯的一种方式,使得服务器之间可以通过该服务进行快速的通讯。其中:
提示
port
:int,telnet服务的端口,如果该端口被占用则向后递增尝试,如32000被占用,会尝试32001.password
:string,密码default_layer
:string,命令默认层。一般保持默认配置即可。
5. Loginapp配置:
<root>
...
<loginapp>
...
<!-- 强制指定外部IP地址或者域名,在某些网络环境下,可能会使用端口映射的方式来访问局域网内部的KBE服务器,那么KBE在当前
的机器上获得的外部地址是局域网地址,此时某些功能将会不正常。例如:账号激活邮件中给出的回调地址, 登录baseapp。
注意:服务端并不会检查这个地址的可用性,因为无法检查。
(Forced to specify an external IP-address or Domain-name, In some server environment, May use the port mapping to access KBE,
So KBE on current machines on the external IP address may be a LAN IP address, Then some functions will not normal.
For example: account activation email address given callback.
Note: the availability of server does not check the address, because cannot check)
-->
<externalAddress> </externalAddress> <!-- Type: String -->
<!-- 暴露给客户端的端口范围
(Exposed to the client port range)
-->
<externalPorts_min> 20013 </externalPorts_min> <!-- Type: Integer -->
<externalPorts_max> 0 </externalPorts_max> <!-- Type: Integer -->
<!-- 加密登录信息
(The encrypted user login information)
可选择的加密方式(Optional encryption):
0: 无加密(No Encryption)
1: Blowfish
2: RSA (res\key\kbengine_private.key)
-->
<encrypt_login> 2 </encrypt_login>
<!-- listen监听队列最大值
(listen: Maximum listen queue)
-->
<SOMAXCONN> 128 </SOMAXCONN>
<!-- 账号的类型 (Account types)
1: 普通账号 (Normal Account)
2: email账号(需要激活) (Email Account, Note: activation required.)
3: 智能账号(自动识别Email, 普通号码等) (Smart Account (Email or Normal, etc.))
-->
<account_type> 3 </account_type>
<!-- http回调接口,处理认证、密码重置等
(注意:http_cbhost一般会被引擎替换为externalInterface或者externalAddress,仅第一个loginapp才会开启这个服务)
(Http-callback interface, handling authentication, password reset, etc.)
-->
<http_cbhost> localhost </http_cbhost>
<http_cbport> 21103 </http_cbport>
...
</loginapp>
...
</root>
externalAddress
: string,外部ip地址或域名的配置。在某些网络环境下,可能会使用端口映射的方式来访问局域网内部的KBE服务器,那么KBE在当前 的机器上获得的外部地址是局域网地址,此时某些功能将会不正常。例如:账号激活邮件中给出的回调地址、登录baseapp等。 注意:服务端并不会检查这个地址的可用性,因为无法检查。externalPorts_min
: int,暴露给客户端的端口范围的最小值。externalPorts_max
: int,暴露给客户端的端口范围的最大值,0表示无限制。encrypt_login
: int,加密登录信息的方式。其中:
提示
0
: 无加密(No Encryption)1
: Blowfish2
: RSA (在res\key\kbengine_private.key
下可以配置RSA的KEY)
SOMAXCONN
: int,listen监听队列最大值。account_type
: int,账号的类型。其中:
提示
1
: 普通账号(Normal Account)2
: email账号(需要激活)3
: 智能账号(自动识别Email还是普通账号等)。根据用户的账号字符串智能匹配。
http_cbhost
: http回调接口的host,可以处理认证、密码重置等。
注意
http_cbhost
一般会被引擎替换为externalInterface
或者externalAddress
,仅第一个loginapp
才会开启这个服务
http_cbport
: http回调接口的port端口
6. Baseapp配置:
<root>
...
<baseapp>
...
<!-- 强制指定外部IP地址或者域名,在某些网络环境下,可能会使用端口映射的方式来访问局域网内部的KBE服务器,那么KBE在当前
的机器上获得的外部地址是局域网地址,此时某些功能将会不正常。例如:账号激活邮件中给出的回调地址, 登录baseapp。
注意:服务端并不会检查这个地址的可用性,因为无法检查。
(Forced to specify an external IP-address or Domain-name, In some server environment, May use the port mapping to access KBE,
So KBE on current machines on the external IP address may be a LAN IP address, Then some functions will not normal.
For example: account activation email address given callback.
Note: the availability of server does not check the address, because cannot check)
-->
<externalAddress> </externalAddress> <!-- Type: String -->
<!-- 暴露给客户端的端口范围
(Exposed to the client port range)
-->
<externalPorts_min> 20015 </externalPorts_min> <!-- Type: Integer -->
<externalPorts_max> 20019 </externalPorts_max> <!-- Type: Integer -->
<!-- 自动存档的时间周期(秒)
(Automatic archiving time period(secs))
-->
<archivePeriod> 300 </archivePeriod> <!-- Type: Float -->
<!-- 自动备份的时间(秒)
(Automatic backup time period(secs))
-->
<backupPeriod> 300 </backupPeriod> <!-- Type: Float -->
<!-- 是否备份未定义的属性
(Whether backup undefined property)
-->
<backUpUndefinedProperties> 0 </backUpUndefinedProperties> <!-- Type: Boolean -->
<!-- 负载平衡滤波器指标值
(Load balancing Smoothing Bias value)
-->
<loadSmoothingBias> 0.01 </loadSmoothingBias>
<!-- 资源下载带宽限制
(Download bandwidth limits)
-->
<downloadStreaming>
<bitsPerSecondTotal> 1000000 </bitsPerSecondTotal> <!-- Type: Int -->
<bitsPerSecondPerClient> 100000 </bitsPerSecondPerClient> <!-- Type: Int -->
</downloadStreaming>
<!-- entityID分配器,进入溢出范围则请求获取新的ID资源
(The entityID allocator, enter the overflow area will get the new ID's)
-->
<ids>
<criticallyLowSize> 1000 </criticallyLowSize> <!-- Type: Integer -->
</ids>
<!-- 当灾难发生后,baseapp进行灾难恢复时,每次恢复entity的数量
(When after the disaster, When baseapp recovery, Each time the number of recovery entity's)
-->
<entityRestoreSize> 32 </entityRestoreSize>
<!-- 程序的性能分析
(Analysis of program performance)
-->
<profiles>
<!-- 如果设置为true,引擎启动时就会开始记录相关profile信息, 进程退出后将导出一份报告
(if is true, Engine start is completed, start to record profile information,
Process exit will export a report.)
-->
<cprofile> false </cprofile>
<pyprofile> false </pyprofile>
<eventprofile> false </eventprofile>
<networkprofile> false </networkprofile>
</profiles>
<!-- listen监听队列最大值
(listen: Maximum listen queue)
-->
<SOMAXCONN> 128 </SOMAXCONN>
<!-- 服务端关闭过程的参数
(Parameter server shutdown process)
-->
<shutdown>
<!-- 每秒销毁base的数量
(The destroy of the per-seconds base's)
-->
<perSecsDestroyEntitySize> 100 </perSecsDestroyEntitySize>
</shutdown>
<respool>
<!-- 缓冲区大小也等于资源大小, 在这个KB大小范围以内的资源才可以进入资源池
(Buffer size is equal to the size of resources,
Less than the buffer resources before they can enter the resource pool)
-->
<buffer_size> 1024 </buffer_size>
<!-- 资源池中的资源超过这个时间未被访问则销毁(秒)
(Resources have not been accessed overtime will be destroyed (s))
-->
<timeout> 600 </timeout>
<!-- 资源池检查tick(秒)
(Resource pool check tick (secs))
-->
<checktick>60</checktick>
</respool>
...
</baseapp>
...
</root>
externalAddress
: string,外部ip地址或域名的配置。在某些网络环境下,可能会使用端口映射的方式来访问局域网内部的KBE服务器,那么KBE在当前 的机器上获得的外部地址是局域网地址,此时某些功能将会不正常。例如:账号激活邮件中给出的回调地址、登录baseapp等。
注意
注意:服务端并不会检查这个地址的可用性,因为无法检查。
externalPorts_min
: int,暴露给客户端的端口范围的最小值。externalPorts_max
: int,暴露给客户端的端口范围的最大值,0表示无限制。archivePeriod
: float,自动存档的时间周期(秒)。baseapp有自动存档的功能,该值可以指明一个时间周期,单位秒。backupPeriod
: float,自动备份的时间(秒)。baseapp有自动备份的功能,该值可以指明一个时间周期,单位秒。backUpUndefinedProperties
: bool,是否备份未定义的属性。0表示不备份,1表示备份loadSmoothingBias
: float,负载平衡滤波器指标值。该值用于负载均衡判断时的一个指标,详情见《进阶-负载均衡》一文。downloadStreaming
: 资源下载带宽限制的配置。其中:
提示
bitsPerSecondTotal
:int,每秒总共的带宽限制,单位bit。bitsPerSecondPerClient
:int,每秒每个client的带宽限制,单位bit。
ids
: entityID分配器的配置,进入溢出范围时会请求获取新的ID资源。其中
提示
criticallyLowSize
:int,溢出值。当id分配达到该值时,就会请求新的id资源。
entityRestoreSize
: int,entity一次可恢复的数量。当灾难发生后,baseapp进行灾难恢复时,每次恢复entity的数量。profiles
: 程序的性能分析配置。下方都是bool类型的参数,如果设置为true,引擎启动时就会开始记录相关profile信息, 进程退出后将导出一份报告。其中:
提示
cprofile
: cpu profilepyprofile
: Python的profileeventprofile
: 事件系统的profile。networkprofile
: 网络相关的profile。
SOMAXCONN
: int,listen监听队列最大值。shutdown
: 服务端关闭过程的参数配置。其中:
提示
perSecsDestroyEntitySize
:int,每秒销毁entity的数量。
respool
: 资源池的配置,资源池可以有效的控制资源的循环利用情况,节约服务器的内存、cpu等资源。其中
提示
buffer_size
:int,缓冲区大小,即资源大小,在这个大小范围以内的资源才可以进入资源池。timeout
:int,超时设置,单位秒。资源池中的资源超过这个时间未被访问则销毁(秒) 。checktick
:int,资源池检查tick(秒)。
7. Cellapp配置:
<root>
...
<cellapp>
...
<!-- 默认View半径, 脚本中可以改变它
(Default View radius, the script can change it)
-->
<defaultViewRadius>
<radius> 80.0 </radius>
<hysteresisArea> 5.0 </hysteresisArea>
</defaultViewRadius>
<!-- 优化EntityID,View范围内实体数小于255个, EntityID传输到client时使用1字节别名ID
(Optimization EntityID,View the Entity is less than 255,
use an aliasID(1byte) transmitted to the client)
-->
<aliasEntityID> true </aliasEntityID>
<!-- 优化Entity属性和方法在广播时所消耗的带宽,Entity客户端属性或者客户端方法不超过255时,
方法uid和属性uid传输到client时使用1字节别名ID
(Entity client (property or a method) is less than 256, using 1 byte transmission.)
-->
<entitydefAliasID>true</entitydefAliasID>
<!-- entityID分配器,进入溢出范围则请求获取新的ID资源
(The entityID allocator, enter the overflow area will get the new ID's)
-->
<ids>
<criticallyLowSize> 1000 </criticallyLowSize> <!-- Type: Integer -->
</ids>
<!-- 程序的性能分析
(Analysis of program performance)
-->
<profiles>
<!-- 如果设置为true,引擎启动时就会开始记录相关profile信息, 进程退出后将导出一份报告
(if is true, Engine start is completed, start to record profile information,
Process exit will export a report.)
-->
<cprofile> false </cprofile>
<pyprofile> false </pyprofile>
<eventprofile> false </eventprofile>
<networkprofile> false </networkprofile>
</profiles>
<!-- 负载平衡滤波器指标值
(Load balancing Smoothing Bias value)
-->
<loadSmoothingBias> 0.01 </loadSmoothingBias>
<ghostDistance> 500.0 </ghostDistance>
<ghostingMaxPerCheck> 64 </ghostingMaxPerCheck> <!-- Type: Integer -->
<!-- ghost更新频率
(Update frequency process)
-->
<ghostUpdateHertz> 30 </ghostUpdateHertz> <!-- Type: Integer -->
<!-- 是否使用坐标系统, 如果设置为false, 那么View、Trap、 Move等功能将不可用
(Whether the use of coordinate-system, if is false,
View, Trap, Move and other functions will not be available)
-->
<coordinate_system>
<enable> true </enable>
<!-- 是否管理y轴? 注:管理y轴,则View、Trap等功能有了高度,当space内的实体较少时比较好用,
否则y轴的管理会带来一些消耗
(is maintenance Y axis? Note: Management y axis, View、Trap and other functions with the height,
When the entity space within little more useful when, Otherwise,
the management of the y-axis will produce some consumption
-->
<rangemgr_y> false </rangemgr_y>
<!-- 实体位置停止发生改变后,引擎继续向客户端更新tick次的位置信息,为0则总是更新。
(After stopping to change the position/direction,
the engine continued to update client information(position/direction) ticks
If 0, then always update)
-->
<entity_posdir_additional_updates> 2 </entity_posdir_additional_updates>
</coordinate_system>
<!-- 服务端关闭过程的参数
(Parameter server shutdown process)
-->
<shutdown>
<!-- 每秒销毁有base部分的entity的数量
(In per-seconds, The destruction of the number of entity's(has base))
-->
<perSecsDestroyEntitySize> 100 </perSecsDestroyEntitySize>
</shutdown>
<!-- 谁是观察者? 玩家就是观察者,观察到的信息会同步给客户端。
开发者可以设计为NPC/Monster在被观察时才激活AI,这样可以减少服务端的CPU消耗。参考Entity.onWitnessed
(Who is witness? Player is witness, The observed information will be synchronized to the client.
Developers can be designed to: Activation (NPC / Monster) AI was observed when, This can reduce server CPU consumption.
see also: Entity.onWitnessed.
)
-->
<witness>
<!-- 当一个实体不再被观察者观察之后,实体并不会马上恢复为未被观察状态,在timeout(秒)时间范围内没有再次被观察则重置状态
(When the observer to stop observing entity, Entity does not recovery immediately to the initial-state,
Not observed before timeout again, the recovery state.)
-->
<timeout> 15 </timeout> <!-- Type: Integer -->
</witness>
</cellapp>
...
</root>
defaultViewRadius
: 默认View半径设置。但脚本中可以改变它,参考API-Entity.setViewRadius。
提示
radius
:float,View区域的半径。hysteresisArea
:float,View区域的滞后区域大小。合理的设定滞后区域将能够降低View碰撞的敏感度从而提高CPU执行效率。 一个实体进入另一个实体的View必须跨越View半径区域,但实体离开View区域则需要移出View半径区域包括滞后区域。
aliasEntityID
: bool,是否优化EntityID。如果为true时,当View范围内实体数小于255个, EntityID传输到client时使用1字节别名ID。entitydefAliasID
: bool,是否优化Entity属性和方法在广播时所消耗的带宽。如果为true时,当Entity客户端属性或者客户端方法不超过255时, 方法uid和属性uid传输到client时使用1字节别名IDids
: entityID分配器的配置,进入溢出范围时会请求获取新的ID资源。其中:
提示
criticallyLowSize
:int,溢出值。当id分配达到该值时,就会请求新的id资源。
profiles
: 程序的性能分析配置。下方都是bool类型的参数,如果设置为true,引擎启动时就会开始记录相关profile信息, 进程退出后将导出一份报告。其中:
提示
cprofile
: cpu profilepyprofile
: Python的profileeventprofile
: 事件系统的profile。networkprofile
: 网络相关的profile。
loadSmoothingBias
: float,负载平衡滤波器指标值。该值用于负载均衡判断时的一个指标,详情见《进阶-负载均衡》一文ghostDistance
: float,幽灵的距离。ghostingMaxPerCheck
: int,每次进行幽灵检查时最大的数量。ghostUpdateHertz
: int,ghost更新频率。coordinate_system
: 坐标系统的配置。其中:
提示
enable
:bool,是否开启。如果设置为false, 那么View、Trap、 Move等功能将不可用。rangemgr_y
:bool,是否管理y轴。如果管理y轴,则View、Trap等功能有了高度,当space内的实体较少时比较好用, 否则y轴的管理会带来一些消耗。entity_posdir_additional_updates
:int,实体位置停止发生改变后,引擎继续向客户端更新位置信息的次数。如果为0则总是更新。
shutdown
: 服务端关闭过程的参数配置。其中:
提示
perSecsDestroyEntitySize
:int,每秒销毁entity的数量。
witness
: 观察者的参数配置。谁是观察者? 玩家就是观察者,观察到的信息会同步给客户端。其中:
提示
timeout
:int,当一个实体不再被观察者观察之后,实体并不会马上恢复为未被观察状态,在timeout(秒)时间范围内没有再次被观察则重置状态。
8. Logger配置:
<root>
...
<logger>
...
<!-- 单个app(baseapp, cellapp, 等等..)进程上, 一个tick最多缓存的log数量
(The number of single-process(baseapp, cellapp, etc..), The number of log a tick buffer.)
-->
<tick_max_buffered_logs> 131070 </tick_max_buffered_logs>
<!-- 单个app(baseapp, cellapp, 等等..)进程上, 一个tick同步给logger的log数量
(The number of single-process(baseapp, cellapp, etc..), A tick synchronization to the number of logger)
-->
<tick_sync_logs> 0 </tick_sync_logs>
...
</logger>
...
</root>
tick_max_buffered_logs
: int,单个app(baseapp, cellapp, 等等..)进程上, 一个tick最多缓存的log数量。tick_sync_logs
: int,单个app(baseapp, cellapp, 等等..)进程上, 一个tick同步给logger的log数量。0表示全部同步。
9. DBMgr配置:
<root>
...
<dbmgr>
...
<!-- debug模式下可输出读写操作信息
(Debug mode can output the read and write informations)
-->
<debug> false </debug>
<!-- 是否检查defs-MD5
(Check whether the defs-MD5)
-->
<allowEmptyDigest> false </allowEmptyDigest> <!-- Type: Boolean -->
<!-- Interfaces进程的地址(参考interfaces中地址配置)
(Address of Interfaces process)
-->
<InterfacesServiceAddr>
<!-- 如果enable为false则相关数据不转发到Interfaces进程
注意:如果为true,dbmgr认为数据将由interfaces交给第三方平台处理
-->
<enable> true </enable>
<host> localhost </host>
<port> 30099 </port>
</InterfacesServiceAddr>
<!-- 数据库接口
(database interfaces)
-->
<databaseInterfaces>
<!-- 数据库接口名称 (可以定义多个不同的接口,但至少存在一个default)
(Database interface name)
-->
<default>
<!-- 如果为true,则为纯净的数据库,引擎不创建实体表
(If true is pure database, engine does not create the entity table)
-->
<pure> false </pure>
<!-- 数据库类型 (mysql、redis)
(Database type(mysql, redis))
-->
<type> mysql </type> <!-- Type: String -->
<!-- 数据库地址
(Database address)
-->
<host> localhost </host> <!-- Type: String -->
<port> 0 </port> <!-- Type: Integer -->
<!-- 数据库账号验证
(Database auth)
-->
<auth>
<username> kbe </username> <!-- Type: String -->
<password> pwd123456 </password> <!-- Type: String -->
<!-- 为true则表示password是加密(rsa)的, 可防止明文配置
(is true, password is RSA)
-->
<encrypt> true </encrypt>
</auth>
<!-- 数据库名称
(Database name)
-->
<databaseName> kbe </databaseName> <!-- Type: String -->
<!-- 数据库允许的连接数
(Number of connections allowed by the database)
-->
<numConnections> 5 </numConnections> <!-- Type: Integer -->
<!-- 字符编码类型
(Character encoding type)
-->
<unicodeString>
<characterSet> utf8 </characterSet> <!-- Type: String -->
<collation> utf8_bin </collation> <!-- Type: String -->
</unicodeString>
</default>
</databaseInterfaces>
<!-- 账号系统
(Account system)
-->
<account_system>
<!-- 账号Entity的名称
(Name of AccountEntity)
-->
<accountEntityScriptType> Account </accountEntityScriptType>
<!-- 新账号默认标记(可组合,填写时按十进制格式)
(Default flags a new account, Can be combined, Fill in decimal format when)
常规标记(normal flag) = 0x00000000
锁定标记(lock flag) = 0x000000001
未激活标记(normal flag) = 0x000000002
-->
<accountDefaultFlags> 0 </accountDefaultFlags> <!-- Type: Integer -->
<!-- 新账号默认过期时间(秒, 引擎会加上当前时间)
(New account default expiration time (seconds, the engine will add the current time))
-->
<accountDefaultDeadline> 0 </accountDefaultDeadline> <!-- Type: Integer -->
<!-- 账号找回密码相关
(Account reset password)
-->
<account_resetPassword>
<!-- 是否开放重设密码
(Whether open reset password)
-->
<enable> false </enable>
</account_resetPassword>
<!-- 账号注册相关
(Account registration)
-->
<account_registration>
<!-- 是否开放注册
(Whether open registration)
-->
<enable> false </enable>
<!-- 登录合法时游戏数据库找不到游戏账号则自动创建
(When logged in, the game database can not find the game account is automatically created)
-->
<loginAutoCreate> false </loginAutoCreate>
</account_registration>
</account_system>
<!-- entityID分配器,进入溢出范围则请求获取新的ID资源
(The entityID allocator, enter the overflow area will get the new ID's)
-->
<ids>
<increasing_range> 2000 </increasing_range> <!-- Type: Integer -->
</ids>
</dbmgr>
...
</root>
debug
: bool,是否debug模式。在debug模式下可输出读写操作信息。allowEmptyDigest
: bool,是否检查defs-MD5。InterfacesServiceAddr
: Interfaces服务进程的地址配置(参考interfaces中地址配置):
提示
enable
:bool,是否开启。如果enable为false则相关数据不转发到Interfaces进程;如果为true,dbmgr认为数据将由interfaces交给第三方平台处理。host
:string,Interfaces的host地址。port
:int,Interfaces的端口。
databaseInterfaces
: 数据库接口的配置,数据库接口名称 (可以定义多个不同的接口,但至少存在一个default)。其中每个接口都包含如下:
提示
pure
:bool,如果为true,则为纯净的数据库,引擎不创建实体表;否则会创建实体表。type
:string,数据库类型 (mysql、redis)。host
:string,数据库连接的地址。port
:int,数据库连接的端口。0表示会使用对应数据库类型的默认端口,如mysql是3306。auth
:数据库账号验证的配置。auth.username
:string,用户名。连接数据库时的账号验证。auth.password
:string,密码。连接数据库时的密码验证。auth.encrypt
:bool,是否加密。为true则表示password是加密(rsa)的, 可防止明文配置。databaseName
:string,数据库名称。numConnections
:int,数据库允许的连接数。unicodeString
:字符编码类型配置。请参考Mysql或redis数据库的相关配置unicodeString.characterSet
:string,字符集。unicodeString.collation
:string,排序规则。
account_system
: 账号系统的配置。其中:
提示
accountEntityScriptType
:string,账号Entity的名称。注意:该配置就是与默认资产库中Account.py对应,如需修改时请对应修改项目资产库中的账户实体名。accountDefaultFlags
:int,新账号默认标记(可组合,填写时按十进制格式)。如:常规标记(normal flag) = 0x00000000,锁定标记(lock flag) = 0x000000001,未激活标记(unactive flag) = 0x000000002accountDefaultDeadline
:int,新账号默认过期时间(秒), 引擎会加上当前时间。account_resetPassword
:账号找回密码相关。enable:是否开启密码重置功能。account_registration
:账号注册相关的配置。account_registration
.enable:bool,是否开放注册。account_registration
.loginAutoCreate:bool,登录合法时游戏数据库找不到游戏账号则自动创建。
ids
: entityID分配器的配置,进入溢出范围时会请求获取新的ID资源。其中:
提示
increasing_range
:int,当本地id资源只剩该值时去管理器请求新的id资源。
10. Interfaces配置:
<root>
...
<interfaces>
...
<!-- interfaces的地址,多组游戏服务端可以共用一个interfaces
(interfaces address, multiple gameserver can share a interfaces)
-->
<host> localhost </host>
<port> 30099 </port>
<!-- 订单超时(秒)
(Orders timeout(seconds))
-->
<orders_timeout> 3600 </orders_timeout>
<!-- listen监听队列最大值
(listen: Maximum listen queue)
-->
<SOMAXCONN> 128 </SOMAXCONN>
...
...
</interfaces>
...
</root>
host
: string,interfaces的地址,多组游戏服务端可以共用一个interfaces。port
: int,interfaces的地址端口。orders_timeout
: int,订单超时(秒)SOMAXCONN
: int,listen监听队列最大值。
11. Machine配置:
<root>
<machine>
<!-- 暴露给客户端的端口范围
(Exposed to the tools port range)
-->
<externalPorts_min> 20099 </externalPorts_min> <!-- Type: Integer -->
<externalPorts_max> 0 </externalPorts_max> <!-- Type: Integer -->
<!-- 服务组使用多台硬件组成网络,在某些网络环境由于路由器的设置不允许UDP广播造成跨物理机组网不成功时
可在此填入所有相关物理机的地址,引擎将会向具体的地址发送探测包来完成组网。
(When the network is composed of a plurality of hardware, the specific network address is detected.)
-->
<addresses>
<!--<item> 127.0.0.1 </item>-->
<!--<item> 192.168.10.18 </item>-->
</addresses>
</machine>
</root>
externalPorts_min
: int,暴露给客户端的端口范围的最小值。externalPorts_max
: int,暴露给客户端的端口范围的最大值,0表示无限制。addresses
: 服务组使用多台硬件组成网络,在某些网络环境由于路由器的设置不允许UDP广播造成跨物理机组网不成功时 可在此填入所有相关物理机的地址,引擎将会向具体的地址发送探测包来完成组网。
提示
item
:string,一个具体的物理机地址。
12. Bots配置:
bots是机器人的意思,用来模拟客户端的行为以及和服务器的通讯,这在调试或压力测试时非常有用,可参考调试章节。本小节只会对配置细节进行阐述,先来看配置文件:
<root>
...
<bots>
<!-- 对应baseapp的externalAddress的解决方案,当externalAddress强制下发公网IP提供登陆时,
如果局域网内部使用机器人测试也走公网IP和流量可能会不合适,此时可以设置为true,登陆时强制直接使用内网环境。
Corresponding to baseapp->externalAddress solution, when externalAddress mandatory release of the public network to provide landing IP,
If the use of robot within the LAN test also take the public network IP and traffic may be inappropriate, can be set to true,
when landing forced to use the internal network environment. -->
<forceInternalLogin> false </forceInternalLogin>
<!-- loginapp地址
(loginapp address)
-->
<host> localhost </host> <!-- Type: String -->
<port> 20013 </port> <!-- Type: Integer -->
<!-- 在Entity初始化时是否触发属性的set_*事件 -->
<isOnInitCallPropertysSetMethods> true </isOnInitCallPropertysSetMethods>
<!-- 默认启动进程后自动添加这么多个机器人
(After starting the process, automatically add some robots)
totalCount : 添加总数量 (Add the total-number)
tickTime : 每次添加所用时间(s) (Interval time-secs)
tickCount : 每次添加数量 (Each time you add the number of)
-->
<defaultAddBots>
<totalCount> 10 </totalCount> <!-- Type: Integer -->
<tickTime> 0.1 </tickTime> <!-- Type: Float -->
<tickCount> 5 </tickCount> <!-- Type: Integer -->
</defaultAddBots>
<!-- 机器人账号相关
(about bots-accounts)
-->
<account_infos>
<!-- 机器人账号名称的前缀
(The account name prefix)
-->
<account_name_prefix> bot_ </account_name_prefix>
<!-- 机器人账号名称的后缀递增, 0使用随机数递增, 否则按照填写的数递增
注意:想让机器人每次登陆使用相同的账号请设置固定的bots程序启动时的cid参数,具体参考服务器启动脚本,机器人账号由"前缀+cid+后缀组成"。
(The account name suffix, 0 is the use of random number, Otherwise, use account_name_suffix_inc and increasing.)
-->
<account_name_suffix_inc> 0 </account_name_suffix_inc><!-- Type: Integer -->
</account_infos>
...
</bots>
...
</root>
forceInternalLogin
: bool,是否强制内网下进行登录。这是对应baseapp的externalAddress的解决方案,当externalAddress强制下发公网IP提供登陆时, 如果局域网内部使用机器人测试也走公网IP和流量可能会不合适,此时可以设置为true,登陆时强制直接使用内网环境。host
: string,要登录的loginapp地址。port
: int,要登录的loginapp 端口。isOnInitCallPropertysSetMethods
: bool,是否在初始化时调用属性set的方法。在Entity初始化时是否触发属性的set_*事件。defaultAddBots
: 默认启动进程后自动添加的机器人参数配置:
提示
totalCount
:int,添加的机器人总数量。tickTime
:float,每次添加的时间间隔(s)。tickCount
:int,每次添加数量。
account_infos
: 机器人账号相关配置:
提示
account_name_prefix
:string,机器人账号名称的前缀。account_name_suffix_inc
:int,机器人账号名称的后缀递增, 0:使用随机数递增, 否则按照填写的数递增。注意:想让机器人每次登陆使用相同的账号请设置固定的bots程序启动时的cid参数,具体参考服务器启动配置,机器人账号由”前缀+cid+后缀组成”。