feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package user
|
||
|
||
import (
|
||
"blazing/cool"
|
||
"blazing/logic/service/common"
|
||
"fmt"
|
||
|
||
"blazing/modules/player/model"
|
||
"context"
|
||
"encoding/hex"
|
||
|
||
"github.com/gogf/gf/v2/os/glog"
|
||
)
|
||
|
||
// LoginSidInfo 登录携带的凭证结构体
|
||
type MAIN_LOGIN_IN struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
|
||
Head common.TomeeHeader `cmd:"1001" struc:"skip"` //玩家登录
|
||
|
||
Sid []byte `struc:"[16]byte"` // 登录会话ID,固定长度16字节
|
||
|
||
}
|
||
|
||
func (l *MAIN_LOGIN_IN) CheakSession() bool {
|
||
// tt, _ := cool.CacheManager.Keys(context.Background())
|
||
//g.Dump(tt)
|
||
t1 := hex.EncodeToString(l.Sid)
|
||
r, err := cool.CacheManager.Get(context.Background(), fmt.Sprintf("session: %d", l.Head.UserID))
|
||
if err != nil {
|
||
return false
|
||
}
|
||
if r.String() != t1 {
|
||
return false
|
||
}
|
||
|
||
cool.CacheManager.Remove(context.Background(), fmt.Sprintf("session: %d", l.Head.UserID))
|
||
glog.Debug(context.Background(), "后端获取", t1, err)
|
||
return true
|
||
}
|
||
|
||
type LoginMSInfo struct {
|
||
model.PlayerInfo
|
||
}
|
||
|
||
func NewOutInfo() *LoginMSInfo {
|
||
|
||
l := &LoginMSInfo{
|
||
PlayerInfo: model.NewPlayerInfo(),
|
||
}
|
||
|
||
return l
|
||
}
|