session

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package session 管理当前Module所拥有的Session

Package session 客户端在连接到服务器网络后,除了Gate能取到客户端的实际连接Client外, 其他模块只能通过客户端的Session操作客户端。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBindFromMap

func GetBindFromMap(session map[string]string, moduleType string) string

GetBindFromMap 以session的格式从一个Map结构中获取绑定的服务器

func GetConnectIDFromMap

func GetConnectIDFromMap(session map[string]string) string

GetConnectIDFromMap 以session的格式从一个Map结构中获取gate中链接的ID

func GetUUIDFromMap

func GetUUIDFromMap(session map[string]string) string

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

func (sessionManager *Manager) DeleteSession(uuid string)

DeleteSession 删除目标uuid的session

func (*Manager) GetSession

func (sessionManager *Manager) GetSession(uuid string) *Session

GetSession 根据Session的UUID获取一个Session

func (*Manager) LoadOrStore

func (sessionManager *Manager) LoadOrStore(uuid string, session *Session) (*Session, bool)

LoadOrStore 加载或保存一个Session,返回操作成功的Session以及是否时加载行为

func (*Manager) MustUpdateFromMap

func (sessionManager *Manager) MustUpdateFromMap(targetSession *Session, data map[string]string)

MustUpdateFromMap 更新一个 session 到管理器中 targetSession 可以是不在当前管理器中的,但是其必须拥有UUID 如果当前管理器中已存在 targetSession.UUID 指定的session, 且两者不是同一个Session,会用 targetSession 完善当前管理器中已存在的Session

func (*Manager) Store

func (sessionManager *Manager) Store(session *Session)

Store 保存一个Session

func (*Manager) UpdateSessionUUID

func (sessionManager *Manager) UpdateSessionUUID(uuid string, session *Session)

UpdateSessionUUID 更新 session 绑定的UUID,由于 session manager 使用UUID作为索引 session 的主键,所以UUID的更改需要同时修改manager中的绑定的

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session 客户端连接会话

func NewSessionFromMap

func NewSessionFromMap(session map[string]string) *Session

NewSessionFromMap 从一个Map结构中实例化一个session

func (*Session) CloseSessionConnect

func (s *Session) CloseSessionConnect(mod IModuleSessionOptions, gatemoduletype string)

CloseSessionConnect 请求管理该Session的网关关闭该Session的连接

func (*Session) FromMap

func (s *Session) FromMap(m map[string]string)

FromMap 用Map中有的键的值替换当前session中的值

func (*Session) Get

func (s *Session) Get(key TKey) string

Get 获取指定键的值

func (*Session) GetBind

func (s *Session) GetBind(moduleType string) string

GetBind 获取当前绑定的指定类型模块的ID

func (*Session) GetBindedList

func (s *Session) GetBindedList() map[string]string

GetBindedList 获取该 Session 绑定的所有模块 返回值 键为模块类型,值为模块ID

func (*Session) GetBool

func (s *Session) GetBool(key TKey) bool

GetBool 获取指定键的 bool 值

func (*Session) GetConnectID

func (s *Session) GetConnectID() string

GetConnectID 获取Session的客户端连接ID

func (*Session) GetInt64

func (s *Session) GetInt64(key TKey) int64

GetInt64 获取指定键的 int64 值

func (*Session) GetUUID

func (s *Session) GetUUID() string

GetUUID get this session uuid

func (*Session) HasBind

func (s *Session) HasBind(moduleType string) bool

HasBind 判断当前是否已经绑定指定类型的模块

func (*Session) HasKey

func (s *Session) HasKey(key TKey) bool

HasKey 判断当前是否存在指定键的值

func (*Session) IsVertify

func (s *Session) IsVertify() bool

IsVertify 判断当前Session是否已经经过验证,如果一个客户端连接经过了验证,则一定会存在一个 用户UUID绑定到此Session上。

func (*Session) OnlyAddKeyFromSession

func (s *Session) OnlyAddKeyFromSession(dir *Session)

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) Set

func (s *Session) Set(key TKey, value string)

Set 设置指定键的值

func (*Session) SetBind

func (s *Session) SetBind(moduleType string, value string)

SetBind 设置当前绑定的指定类型模块的ID

func (*Session) SetBool

func (s *Session) SetBool(key TKey, value bool)

SetBool 设置指定键的 bool 值

func (*Session) SetConnectID

func (s *Session) SetConnectID(value string)

SetConnectID 设置Session的客户端连接ID

func (*Session) SetInt64

func (s *Session) SetInt64(key TKey, value int64)

SetInt64 设置指定键的 int64 值

func (*Session) SyncToBindedModule

func (s *Session) SyncToBindedModule(mod IModuleSessionOptions)

SyncToBindedModule 同步 Session 到 所有已绑定的模块

func (*Session) ToMap

func (s *Session) ToMap() map[string]string

ToMap 将当前Session的键值到处成为 map[string]string 的类型

type TKey

type TKey string

TKey Session中字段的键的类型

const (
	// 索引绑定的服务器,仅是头部,该Key需要在后面拼接目标索引的Module类型
	SessionKeyBindHead TKey = "_s0_bind_"
	// gate 中用于描述链接的唯一ID
	SessionKeyConnectID TKey = "_s0_connectid"
	// session 的 UUID 是 session管理器 中的主键
	SessionKeyUUID TKey = "_s0_uuid"
)

系统中默认的一些 Session 的键

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL