Files
bl/modules/blazing/service/login.go
昔念 3e55b0f481 ```
feat(vscode): 添加调试参数配置

为launch.json添加-debug=1参数,便于调试模式启动

docs(README): 补充zellij终端复用工具使用说明

添加x-cmd安装和zellij会话管理相关命令示例

refactor(config): 注释掉GamePort配置项

暂时注释GamePort配置项以解决配置冲突问题

refactor(xmlres): 移除未使用的gf框架依赖
2026-01-01 22:19:00 +08:00

87 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/common/data/share"
"blazing/cool"
"blazing/modules/config/model"
"encoding/binary"
"encoding/hex"
"github.com/gogf/gf/v2/util/guid"
)
type LoginService struct {
*cool.Service
}
func NewLoginServiceService() *LoginService {
return &LoginService{
&cool.Service{
Model: model.NewServerList(),
},
}
}
// 生成session
// GetSessionId 生成并返回会话ID、UUID字符串及可能的错误
// 会话ID由accountID(4字节) + UUID(16字节) + 随机数(4字节)组成,最终编码为十六进制字符串
func (s *LoginService) GetSessionId(accountID uint) string {
// // 生成UUID v7带错误处理UUID生成失败时返回错误
// uuidV7, err := uuid.NewV7()
// if err != nil {
// return "", "", err
// }
uuidStr := guid.S()
// 将accountID转换为4字节大端序字节数组
accountBytes := make([]byte, 4)
binary.BigEndian.PutUint32(accountBytes, uint32(accountID))
// 预分配缓冲区总长度4+16+4=24字节减少内存分配
sessionBytes := make([]byte, 0, 24)
sessionBytes = append(sessionBytes, accountBytes...)
sessionBytes = append(sessionBytes, uuidStr...)
//sessionBytes = append(sessionBytes, grand.B(4)...)
// 编码为十六进制字符串作为最终会话ID
sessionID := hex.EncodeToString(sessionBytes)
share.ShareManager.SaveSession(uuidStr, uint32(accountID))
return sessionID
}
func (s *LoginService) SetServerID(OnlineID uint16, Port uint16) error {
m := cool.DBM(s.Model).Where("online_id", OnlineID)
// record, err := m.One()
// if err != nil {
// return err
// }
// if record == nil {
// //说明是新的服务器
// _, err := m.InsertAndGetId(&model.ServerList{OnlineID: OnlineID, Port: Port})
// return err
// }
var tttt model.ServerList
m.Scan(&tttt)
tttt.Port = Port
tttt.OnlineID = OnlineID
m.Save(tttt)
return nil
}
func (s *LoginService) GetServerID(OnlineID uint16) *model.ServerList {
var tttt *model.ServerList
err := cool.DBM(s.Model).Where("online_id", OnlineID).Scan(&tttt)
if err != nil {
return nil
}
return tttt
}