Class SocketUserSession

java.lang.Object
com.iohao.net.external.core.netty.session.SocketUserSession
All Implemented Interfaces:
AttrOptionDynamic, UserSession

public final class SocketUserSession extends Object
Netty channel-backed implementation of an external user session.
Author:
渔民小镇
date:
2023-02-18
  • Field Details

    • options

      protected final AttrOptions options
    • channel

      protected io.netty.channel.Channel channel
    • userId

      protected long userId
    • userChannelId

      protected long userChannelId
    • externalServerId

      protected int externalServerId
    • state

      protected UserSessionState state
    • externalJoin

      protected ExternalJoinEnum externalJoin
    • bindingLogicServerIds

      protected int[] bindingLogicServerIds
    • attachment

      protected byte[] attachment
  • Method Details

    • isActive

      public boolean isActive()
      Description copied from interface: UserSession
      Check whether the session is active.
      Specified by:
      isActive in interface UserSession
      Returns:
      true if the session is active
    • writeAndFlush

      public io.netty.channel.ChannelFuture writeAndFlush(Object message)
      Description copied from interface: UserSession
      Write a message to the client and flush immediately.
      Parameters:
      message - message object
      Returns:
      transport-specific future or write result
    • getIp

      public String getIp()
      Description copied from interface: UserSession
      Get the client IP address.
      Returns:
      player IP
    • employ

      public void employ(CommunicationMessage message)
      Description copied from interface: UserSession
      Adds user info to request. Developers can extend data via HeadMetadata.setAttachmentData(byte[]), which will be forwarded to the logic server.
      Specified by:
      employ in interface UserSession
      Parameters:
      message - outbound message to enrich with session identity/attachment data
    • setUserId

      public void setUserId(long userId)
      Mark the session as identity-verified when the business user id is assigned.
      Specified by:
      setUserId in interface UserSession
      Parameters:
      userId - business user id
    • setBindingLogicServerIds

      public void setBindingLogicServerIds(int[] bindingLogicServerIds)
      Description copied from interface: UserSession
      Set logic server bindings associated with this session.
      Specified by:
      setBindingLogicServerIds in interface UserSession
      Parameters:
      bindingLogicServerIds - bound logic server ids
    • isVerifyIdentity

      public boolean isVerifyIdentity()
      Description copied from interface: UserSession
      Checks if the identity has been verified.
      Specified by:
      isVerifyIdentity in interface UserSession
      Returns:
      true if logged in
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getOptions

      public AttrOptions getOptions()
      Description copied from interface: AttrOptionDynamic
      Gets the dynamic member attributes (options)
      Specified by:
      getOptions in interface AttrOptionDynamic
      Returns:
      The dynamic member attributes
    • getChannel

      public io.netty.channel.Channel getChannel()
    • getUserId

      public long getUserId()
      Description copied from interface: UserSession
      Gets the ID of the current user (player).
      Specified by:
      getUserId in interface UserSession
      Returns:
      current business user id
    • getUserChannelId

      public long getUserChannelId()
      Description copied from interface: UserSession
      Gets the UserChannelId of the current user (player).
      Specified by:
      getUserChannelId in interface UserSession
      Returns:
      user channel id
    • getExternalServerId

      public int getExternalServerId()
    • getState

      public UserSessionState getState()
      Description copied from interface: UserSession
      Get the current session state.
      Specified by:
      getState in interface UserSession
      Returns:
      session state
    • getExternalJoin

      public ExternalJoinEnum getExternalJoin()
    • getBindingLogicServerIds

      public int[] getBindingLogicServerIds()
      Description copied from interface: UserSession
      Get logic server bindings associated with this session.
      Specified by:
      getBindingLogicServerIds in interface UserSession
      Returns:
      bound logic server ids
    • getAttachment

      public byte[] getAttachment()
    • setExternalServerId

      public void setExternalServerId(int externalServerId)
    • setState

      public void setState(UserSessionState state)
    • setExternalJoin

      public void setExternalJoin(ExternalJoinEnum externalJoin)
      Description copied from interface: UserSession
      Set the transport type used by this session.
      Specified by:
      setExternalJoin in interface UserSession
      Parameters:
      externalJoin - external transport type
    • setAttachment

      public void setAttachment(byte[] attachment)
      Description copied from interface: UserSession
      Set the attachment bytes stored on the session.
      Specified by:
      setAttachment in interface UserSession
      Parameters:
      attachment - attachment bytes