Files
bl/logic/controller/login_main.go
昔念 026689f3ed ```
feat(cache): 添加复合键缓存操作支持

添加了基于 uint32+string 组合键的缓存操作方法,包括
GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和
ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景

fix(vscode): 添加 cSpell 配置支持 struc 词汇

refactor(session): 移除过时的会话管理方法

移除了基于单一字符串键的会话管理方法,因为已迁移到使用
复合键的缓存操作方式
```
2026-01-19 18:51:56 +08:00

58 lines
1.4 KiB
Go

package controller
import (
"blazing/common/data/share"
"blazing/cool"
"blazing/common/socket/errorcode"
"blazing/logic/service/user"
"blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/player/service"
"context"
"time"
"github.com/panjf2000/gnet/v2"
)
// Login 处理命令: 1001
func (h Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.LoginMSInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
isSessionValid := data.CheakSession()
if !isSessionValid {
defer c.Close()
return
}
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
currentPlayer := player.GetPlayer(c, data.Head.UserID)
if currentPlayer == nil {
cool.Logger.Error(context.Background(), "获取玩家失败", data.Head.UserID)
defer c.Close()
return
}
currentPlayer.Service = service.NewUserService(data.Head.UserID)
currentPlayer.Info = currentPlayer.Service.Info.GetCache()
if currentPlayer.Info == nil {
defer c.Close()
return
}
currentPlayer.Info.UserID = data.Head.UserID
currentPlayer.Logintime = uint32(time.Now().Unix()) //保存时间戳
currentPlayer.CompleteLogin() //通知客户端登录成功
result = user.NewOutInfo() //设置登录消息
result.PlayerInfo = *currentPlayer.Info
defer space.GetSpace(currentPlayer.Info.MapID).EnterMap(currentPlayer)
return result, 0
}