1
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user