diff --git a/common/data/share/share.go b/common/data/share/share.go index 9b28e431..08784da1 100644 --- a/common/data/share/share.go +++ b/common/data/share/share.go @@ -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 } diff --git a/logic/controller/login_getserver.go b/logic/controller/login_getserver.go index 52aca8d4..bb60aeed 100644 --- a/logic/controller/login_getserver.go +++ b/logic/controller/login_getserver.go @@ -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) } diff --git a/logic/service/player/pack.go b/logic/service/player/pack.go index c52ed03b..96320d86 100644 --- a/logic/service/player/pack.go +++ b/logic/service/player/pack.go @@ -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 diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 015c308b..76cd083b 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -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 } diff --git a/logic/service/user/Login.go b/logic/service/user/Login.go index 0ae41daa..733e07d3 100644 --- a/logic/service/user/Login.go +++ b/logic/service/user/Login.go @@ -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 } diff --git a/modules/base/controller/admin/base_sys_user.go b/modules/base/controller/admin/base_sys_user.go index 10680c1f..d946d12d 100644 --- a/modules/base/controller/admin/base_sys_user.go +++ b/modules/base/controller/admin/base_sys_user.go @@ -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 diff --git a/modules/player/service/info.go b/modules/player/service/info.go index bae7b377..ce257324 100644 --- a/modules/player/service/info.go +++ b/modules/player/service/info.go @@ -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))