This commit is contained in:
昔念
2026-02-07 18:21:52 +08:00
parent 6be35dc045
commit 460b92c044
7 changed files with 13 additions and 26 deletions

View File

@@ -121,7 +121,7 @@ func (s *cacheStore[T]) Del(ctx context.Context, key string) error {
if err != nil {
return gerror.Wrapf(err, "删除缓存失败,键: %s", key)
}
fmt.Printf("[INFO] 删除缓存 [%s] 键: %s 成功\n", s.prefix, key)
//fmt.Printf("[INFO] 删除缓存 [%s] 键: %s 成功\n", s.prefix, key)
return nil
}

View File

@@ -55,8 +55,8 @@ func (h Controller) GetServerOnline(data *user.SidInfo, c gnet.Conn) (result *rp
}
logininfo := ser.Info.SetLogin()
if logininfo != nil {
cool.CacheManager.Set(context.TODO(), fmt.Sprintf("player: %d", data.Head.UserID), logininfo, 0)
cool.CacheManager.Set(context.Background(), fmt.Sprintf("session: %d", data.Head.UserID), t1, 0)
cool.CacheManager.Set(context.TODO(), fmt.Sprintf("player:%d", data.Head.UserID), logininfo, 0)
cool.CacheManager.Set(context.Background(), fmt.Sprintf("session:%d", data.Head.UserID), t1, 0)
}

View File

@@ -243,19 +243,12 @@ func (p *ClientData) SendPack(b []byte) error {
if cli.Wsmsg.Upgraded {
// This is the echo server
err := wsutil.WriteServerMessage(p.Conn, ws.OpBinary, b)
if err != nil {
glog.Debug(context.Background(), err)
// logging.Infof("conn[%v] [err=%v]", p.Conn.RemoteAddr().String(), err.Error())
return err
}
wsutil.WriteServerMessage(p.Conn, ws.OpBinary, b)
} else {
err := p.Conn.AsyncWrite(b, nil)
if err != nil {
glog.Debug(context.Background(), err)
p.Conn.Write(b)
}
}
return nil

View File

@@ -175,6 +175,10 @@ func (p *Player) SendPack(b []byte) error {
psocket, ok := p.MainConn.Context().(*ClientData)
if ok {
return psocket.SendPack(b)
} else {
return fmt.Errorf("链接错误,取消发包")
}
return nil
}

View File

@@ -30,7 +30,7 @@ func (l *MAIN_LOGIN_IN) CheakSession() bool {
return false
}
cool.CacheManager.Remove(context.Background(), fmt.Sprintf("session: %d", l.Head.UserID))
cool.CacheManager.Remove(context.Background(), fmt.Sprintf("session:%d", l.Head.UserID))
//glog.Debug(context.Background(), "后端获取", t1, err)
return true
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"
"blazing/cool"
@@ -80,7 +81,7 @@ func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq)
if logininfo != nil {
res.Session = blazing.NewInfoService(uint32(t.UserId)).Gensession()
cool.CacheManager.Set(context.TODO(), fmt.Sprintf("player:%d", uint32(t1.ID)), logininfo, 0)
cool.CacheManager.Set(context.TODO(), fmt.Sprintf("player:%d", uint32(t1.ID)), logininfo, 10*time.Minute)
}
return

View File

@@ -160,17 +160,6 @@ func (s *InfoService) Gensession() string {
// // 解码UUID字符串为字节数组32位十六进制字符串对应16字节
uuidBytes, _ := hex.DecodeString(uuidStr)
// // 将accountID转换为4字节大端序字节数组
// accountBytes := make([]byte, 4)
// binary.BigEndian.PutUint32(accountBytes, uint32(s.userid))
// // 预分配缓冲区总长度4+16+4=24字节减少内存分配
// sessionBytes := make([]byte, 0, 24)
// sessionBytes = append(sessionBytes, accountBytes...)
// sessionBytes = append(sessionBytes, uuidBytes...)
// //sessionBytes = append(sessionBytes, grand.B(4)...)
// // 编码为十六进制字符串作为最终会话ID
sessionID := hex.EncodeToString(uuidBytes)
cool.CacheManager.Set(context.Background(), fmt.Sprintf("session:%d", uint32(s.userid)), sessionID, 0)
// ///User.Store(string(uuidStr), uint32(s.userid))