KBE实践——登录案例
2024-09-06 00:25:47
目录
服务器
```
void maini(){
printf("hello world");
}
```
最小资产库创建
entity配置
实体的Python实现
创建第一个空间Space
让entity进入空间Space
客户端(unity)
生成客户端SDK
实现Client部分验证
验证测试
====================================正文=====================================
服务器
最小资产库创建
- 运行文件“new_assets.bat”,生成最小资产库“server_assets”,更名为“first_assets"
entity配置
- entity声明
```
void main(){
printf("shit");
}
```hasClient 表示这个实体有客户端
- entity配置
- 新建def配置文件,配置文件名称规定为(实体名称.def)
- 添加方法声明
<root>
<!-- Cell上的方法 -->
<CellMethods>
<Broadcast>
<!--Exposed 表示此方法暴漏给客户端调用-->
<Exposed/>
<Arg> UNICODE </Arg>
</Broadcast>
</CellMethods> <!-- 客户端上的方法 -->
<ClientrMethods>
<onEnter>
</onEnter> <SendMsgToServer>
<Arg> UNICODE </Arg>
</SendMsgToServer>
</ClientrMethods>
</root>{项目资产库}\scripts\entity_defs\PlayerEntity.def
- entity声明
entity的 Python实现
- 名称规则(实体名.py)
- base文件夹下的部分
# -*- coding utf-8 -*-
import KBEngine
from KBEDebug import * class FirstPlayer(KBEngine.Proxy):
#base部分的实现
def __init__(self):
KBEngine.Entity.__init__(self){资产库}\base\FirstPlayer.py
- cell文件夹下的部分
# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import * class FirstEntity(KBEngine.Entity):
def __init__(self):
KBEngine.Entity.__init__(self)
#这里是FirstEntity的cell,当其Cell创建完毕时,通知其自身的客户端的onEnter函数
self.client.onEnter() def SendMsgToServer(self, callerID, content):
INFO_MSG("FirstPlay-SendMsgToServer")
#广播给所有客户端
self.allClient.Broadcast(str(self.id) + ":" + content){资产库}\scripts\cell\FirstPlayer.py
- entity何时创建?
教程采用:使用账户入口对第一个enetity进行创建,只添加一句:<accountEntityScriptType> FirstEntity </accountEntityScriptType><dbmgr>
<account_system>
<accountEntityScriptType> PlayerEntity </accountEntityScriptType>{项目资产库}/res/server/kbengine.xml
Space配置
- entity声明和def文件配置
<root>
<PlayerEntity hasClient="true"></PlayerEntity>
<!-- 添加下面这行 -->
<WorldSpace></WorldSpace>
</root>{资产库}\scripts\entities.xml
<root>
<!-- BaseApp上的远程方法 -->
<BaseMethods>
</BaseMethods>
<!-- CellApp上的远程方法 -->
<CellMethods>
</CellMethods>
</root>{资产库}\scripts\entity_defs\WorldSpace.def
- entity声明和def文件配置
Space的 Python实现
- 名称规则(空间名.py)
- base部分
# -*- coding-utf8 -*-
import KBEngine
from KBEDebug import * class WorldSpace(KBEngine.Space):
# WorldSpace的base部分,这是一个实体,并不是Space本身,Space位于内存中,我们通过这个实体关联并控制Space
def __init__(self):
KBEngine.Space.__init__(self)
# 在全局变量globaldata字典中保存Space
KBEngine.globalData["WorldSpace"] = self{资产库}\scripts\base\WorldSpace.py
- cell部分
import KBEngine class WorldSpace(KBEngine.Space):
def __init__(self):
KBEngine.Space.__init__(self)
pass{资产库}\scripts\cell\WoldSpace.py
- space何时创建
教程采用:Baseapp就绪时创建Space空间,在baseapp就绪后加载空间spacedef onBaseAppReady(isBootstrap):
"""
KBEngine method.
baseapp已经准备好了
@param isBootstrap: 是否为第一个启动的baseapp
@type isBootstrap: BOOL
"""
INFO_MSG('onBaseAppReady: isBootstrap=%s, appID=%s, bootstrapGroupIndex=%s, bootstrapGlobalIndex=%s' % \
(isBootstrap, os.getenv("KBE_COMPONENTID"), os.getenv("KBE_BOOTIDX_GROUP"), os.getenv("KBE_BOOTIDX_GLOBAL")))
#添加此句以使得space在baseapp启动后就加载进来
KBEngine.createEntityLocally("WorldSpace", {}){资产库}\scripts\base\kbemain.py
验证空间Space是否加载成功
- 开始验证:打开guiconsole(......\kbengine-2.4.\kbe\tools\server\guiconsole)选择baseapp,然后选中debug便签,输入Python语句:KBEngine.entities.items(),Ctrl+Enter执行语句,输出结果如下:
- 错误警告
我们可能需要设置一下用户账户和密码,位置在{资产库}res\server\kbengine.xml: root -> dbmgr -> databaseInterfaces -> default -> auth
注意2(9个窗口一个都不能少)
折叠的代码中所有的实例名称(PlayerEntity 或者 FIrstPlayer 选一个统一)都需要统一,我上面没有再修改,吐槽博客园的编辑器 (¬︿¬☆)
- 开始验证:打开guiconsole(......\kbengine-2.4.\kbe\tools\server\guiconsole)选择baseapp,然后选中debug便签,输入Python语句:KBEngine.entities.items(),Ctrl+Enter执行语句,输出结果如下:
让entity进入空间Space
- 我们再次打开之前的文件({项目资产库}/scripts/base/PlayerEntity.py)
- 添加一个回调和函数,onClientEnabled ,因为我们的PlayerEntity继承了Proxy,所以当客户端可用时,这个函数会被执行,此时我们选择让entity进入空间
客户端(unity)
生成客户端SDK
- 配置SDK生成工具
实现Client部分验证
验证测试
最新文章
- MongoDB数据实体中的ObjectId序列化成json的一个小坑
- shell简单用法笔记(一)
- Dijkstra算法初步 - 迷宫问题
- Google-glog 日志库使用手记
- RelativeLayout相对布局属性
- sql常识-LEFT JOIN
- Orleans-Hello World
- 用MVC+EF快速弄出一个CRUD
- LeetCode OJ 62. Unique Paths
- HTML5的优点与缺点?
- VsCode源码分析之布局
- Web服务端性能提升实践
- Sprint2的每日更新
- Ruby环境搭建
- 跟着百度学PHP[14]-PDO的错误处理模式&;PDO执行SQL
- TimeQuest学习总结
- RESTful API架构和oauth2.0认证机制(概念版)
- Python函数(十一)-生成器
- JSONModel 简单例子
- 查看python 3中的内置函数列表,以及函数功能描述
热门文章
- bzoj 3751: [NOIP2014]解方程【数学】
- hdu 1348【凸包模板】
- 小程序 获取地理位置-- wx.getLocation
- [App Store Connect帮助]七、在 App Store 上发行(2.4)设定价格与销售范围:安排价格调整
- spring进行事务管理
- hdu 2063 过山车 (最大匹配 匈牙利算法模板)
- poj 1511 Invitation Cards spfa 邻接矩阵
- [hdu1695] GCD【莫比乌斯反演】
- 使用dubbox开发REST应用
- Python的数据类型:list和tuple