``feat(socket): 完善踢人流程日志记录,添加CloseChan确保数据保存完成``

This commit is contained in:
1
2025-10-16 18:59:38 +00:00
parent 52ea55ac39
commit 08fcc72b6d
6 changed files with 22 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package controller
import (
"blazing/common/data/share"
"blazing/cool"
"fmt"
"blazing/common/socket/errorcode"
@@ -35,11 +36,15 @@ func IsToday(t time.Time) bool {
func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.LoginMSInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
if tt := data.CheakSession(); tt { //说明sid正确
cool.Loger.Info(context.TODO(), "准备踢人")
err := h.RPCClient.Kick(data.Head.UserID) //先踢人
if err != nil {
fmt.Println("踢人失败", err)
}
<-time.After(time.Millisecond * 3000)
//player.KickPlayer(data.Head.UserID)
cool.Loger.Info(context.TODO(), "踢人请求完成,继续登录流程")
// <-time.After(time.Millisecond * 3000)
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
t := player.GetPlayer(c, data.Head.UserID)
t.Service = blservice.NewUserService(data.Head.UserID)

View File

@@ -44,6 +44,7 @@ type ClientData struct {
Mu sync.Mutex
ERROR_CONNUT int
Wsmsg *WsCodec
CloseChan chan struct{}
}
func NewClientData() *ClientData {

View File

@@ -41,11 +41,13 @@ func KickPlayer(userid uint32) error { //踢出玩家
//实际上这里有个问题,会造成重复保存问题
player1.SendPack(head.Pack(nil))
player1.MainConn.Context().(*ClientData).CloseChan = make(chan struct{})
player1.MainConn.Context().(*ClientData).Mu.Lock()
player1.MainConn.Close()
player1.MainConn.Context().(*ClientData).Mu.Unlock()
// clientdata.Player = player
<-player1.MainConn.Context().(*ClientData).CloseChan
}
}