Comments (2)
https://www.yuque.com/iohao/game/sw1y8u
在处理 action 时,我们可以通过 FlowContext.userId 可以很方便得到当前用户(玩家)id,userId 实际的保存地方是游戏对外服的 UserSession 中。每次请求时会在游戏对外服中,将当前 userId 设置到 RequestMessage 的元信息对象中;如果开发者想在处理 action 时,携带上一些自定义的信息时,可以通过 HeadMetadata.attachmentData 属性来完成。
假如我们想要把 channel 的 ip(由于这些数据只在游戏对外服中),携带上到 action 业务处理中得到,我们就可以把这些数据设置到 HeadMetadata.attachmentData 属性中,在游戏对外服转发请求到网关之前设置就好的。
当设置好需要携带到游戏逻辑服的数据时,我们可以通过
FlowContext.getAttachment() 方法来获取我们在游戏对外服设置的数据
from iogame.
参考
public void employ(RequestMessage requestMessage) {
... ... 省略部分代码
HeadMetadata headMetadata = requestMessage.getHeadMetadata();
if (!this.isVerifyIdentity()) {
// 只有没进行验证的,才给 userChannelId
String channelId = this.getChannelId();
// 一般指用户的 channelId (来源于对外服的 channel 长连接)
byte[] channelIdBytes = channelId.getBytes();
// 元信息扩展
headMetadata.setAttachmentData(channelIdBytes);
}
... ... 省略部分代码
}
元信息扩展关键代码
headMetadata.setAttachmentData
from iogame.
Related Issues (20)
- 逻辑服监听机制
- 新增 - 全链路调用日志跟踪 traceId HOT 3
- 使用websocket协议通信有没办法客户端一次请求,而服务端返回多次响应 HOT 3
- ioGame21 发布前的公告通知 HOT 1
- ioGame21 首发功能的计划 HOT 3
- 心跳响应前的回调 HOT 1
- FlowContext 增加通信能力,提供同步、异步、异步回调的便捷使用 HOT 9
- FlowContext 增加更新、获取元信息的便捷使用 HOT 3
- 移除 ioGame17 中,已标记废弃的代码
- 请问下我在使用过程中在dto中string的属性无法pb序列化,还需要特殊处理吗?我看文中没有提到issue也没有 HOT 1
- 模拟客户端 能否添加 自动重连机制 HOT 1
- 继承的java类,生成的proto 为空 HOT 2
- 可以提供跟gm后台这种外部系统可以通过feign等通讯工具直接调用action接口 HOT 3
- 多服多进程的Docker部署 HOT 2
- 对外服组播能力支持 HOT 6
- 对接口数据 加密加压缩 HOT 4
- 前端页面通过websocket.js发送信息后自动关闭 HOT 1
- 广播后怎么获取广播的的数据Message,没有有回调函数啊 HOT 2
- 逻辑服A1如何调用指定的逻辑服B2的方法 HOT 4
- 网关集群部署出现问题 -- 请教: HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iogame.