Documentation ¶
Overview ¶
Package session 管理当前Module所拥有的Session
Package session 客户端在连接到服务器网络后,除了Gate能取到客户端的实际连接Client外, 其他模块只能通过客户端的Session操作客户端。
Index ¶
- func GetBindFromMap(session map[string]string, moduleType string) string
- func GetConnectIDFromMap(session map[string]string) string
- func GetUUIDFromMap(session map[string]string) string
- type IModuleSessionOptions
- type Manager
- func (sessionManager *Manager) DeleteSession(uuid string)
- func (sessionManager *Manager) GetSession(uuid string) *Session
- func (sessionManager *Manager) LoadOrStore(uuid string, session *Session) (*Session, bool)
- func (sessionManager *Manager) MustUpdateFromMap(targetSession *Session, data map[string]string)
- func (sessionManager *Manager) Store(session *Session)
- func (sessionManager *Manager) UpdateSessionUUID(uuid string, session *Session)
- type Session
- func (s *Session) CloseSessionConnect(mod IModuleSessionOptions, gatemoduletype string)
- func (s *Session) FromMap(m map[string]string)
- func (s *Session) Get(key TKey) string
- func (s *Session) GetBind(moduleType string) string
- func (s *Session) GetBindedList() map[string]string
- func (s *Session) GetBool(key TKey) bool
- func (s *Session) GetConnectID() string
- func (s *Session) GetInt64(key TKey) int64
- func (s *Session) GetUUID() string
- func (s *Session) HasBind(moduleType string) bool
- func (s *Session) HasKey(key TKey) bool
- func (s *Session) IsVertify() bool
- func (s *Session) OnlyAddKeyFromSession(dir *Session)
- func (s *Session) SendMsg(mod IModuleSessionOptions, gatemoduletype string, msgid uint16, data []byte)
- func (s *Session) Set(key TKey, value string)
- func (s *Session) SetBind(moduleType string, value string)
- func (s *Session) SetBool(key TKey, value bool)
- func (s *Session) SetConnectID(value string)
- func (s *Session) SetInt64(key TKey, value int64)
- func (s *Session) SyncToBindedModule(mod IModuleSessionOptions)
- func (s *Session) ToMap() map[string]string
- type TKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBindFromMap ¶
GetBindFromMap 以session的格式从一个Map结构中获取绑定的服务器
func GetConnectIDFromMap ¶
GetConnectIDFromMap 以session的格式从一个Map结构中获取gate中链接的ID
func GetUUIDFromMap ¶
GetUUIDFromMap 以session的格式从一个Map结构中获取UUID
Types ¶
type IModuleSessionOptions ¶
type IModuleSessionOptions interface { GetModuleID() string SInnerSendModuleMsg(gate string, msg msg.IMsgStruct) SInnerSendClientMsg(gateid string, connectid string, msgid uint16, data []byte) SInnerCloseSessionConnect(gateid string, connectid string) }
IModuleSessionOptions 用于提供给 session 向客户端发送消息或者执行某些操作的接口 一般情况下,提供 base.Module 即可
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 当前Module的Session管理器
func (*Manager) DeleteSession ¶
DeleteSession 删除目标uuid的session
func (*Manager) GetSession ¶
GetSession 根据Session的UUID获取一个Session
func (*Manager) LoadOrStore ¶
LoadOrStore 加载或保存一个Session,返回操作成功的Session以及是否时加载行为
func (*Manager) MustUpdateFromMap ¶
MustUpdateFromMap 更新一个 session 到管理器中 targetSession 可以是不在当前管理器中的,但是其必须拥有UUID 如果当前管理器中已存在 targetSession.UUID 指定的session, 且两者不是同一个Session,会用 targetSession 完善当前管理器中已存在的Session
func (*Manager) UpdateSessionUUID ¶
UpdateSessionUUID 更新 session 绑定的UUID,由于 session manager 使用UUID作为索引 session 的主键,所以UUID的更改需要同时修改manager中的绑定的
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 客户端连接会话
func NewSessionFromMap ¶
NewSessionFromMap 从一个Map结构中实例化一个session
func (*Session) CloseSessionConnect ¶
func (s *Session) CloseSessionConnect(mod IModuleSessionOptions, gatemoduletype string)
CloseSessionConnect 请求管理该Session的网关关闭该Session的连接
func (*Session) GetBindedList ¶
GetBindedList 获取该 Session 绑定的所有模块 返回值 键为模块类型,值为模块ID
func (*Session) GetConnectID ¶
GetConnectID 获取Session的客户端连接ID
func (*Session) IsVertify ¶
IsVertify 判断当前Session是否已经经过验证,如果一个客户端连接经过了验证,则一定会存在一个 用户UUID绑定到此Session上。
func (*Session) OnlyAddKeyFromSession ¶
OnlyAddKeyFromSession 将dir中有且this中没有的键增加到this中,不会修改任何this中已有的键值, 只会增加this的键值。 这是一种简单的通过另一个Session完善当前Session的方法。
func (*Session) SendMsg ¶
func (s *Session) SendMsg(mod IModuleSessionOptions, gatemoduletype string, msgid uint16, data []byte)
SendMsg 向该Session指定的客户端发送一个消息
func (*Session) SetConnectID ¶
SetConnectID 设置Session的客户端连接ID
func (*Session) SyncToBindedModule ¶
func (s *Session) SyncToBindedModule(mod IModuleSessionOptions)
SyncToBindedModule 同步 Session 到 所有已绑定的模块