Giter Club home page Giter Club logo

Comments (2)

iohao avatar iohao commented on August 16, 2024

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.

iohao avatar iohao commented on August 16, 2024

参考

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.