Files
bl/logic/service/player/server.go
昔念 5e01837f78 refactor(logic): 重构逻辑层代码
- 移除未使用的 SocketHandler_Tomee.go、ai.go、effect_1.go 文件
- 更新 player 包名引用,替换原 service 包
- 调整 TomeeHeader 和相关处理逻辑至 player 包
- 更新各控制器中的 Player 引用为 player 包中的类型
- 移除冗余的 GetPlayer 方法,使用新逻辑
2025-09-14 01:35:16 +08:00

45 lines
1.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 player
import "blazing/common/socket/errorcode"
func GetPlayer(c *Conn, userid uint32) *Player { //TODO 这里待优化,可能存在内存泄漏问题
c.Mu.Lock()
defer c.Mu.Unlock()
//检查player初始化是否为conn初始后取map防止二次连接后存在两个player
clientdata := c.MainConn.Context().(*ClientData)
if clientdata.Player != nil {
return clientdata.Player
}
clientdata.Player = NewPlayer(
WithConn(c), //注入conn
)
// gff := socket.NewClientData()
// gff.Player = clientdata.Player
// c.MainConn.SetContext(gff)
Mainplayer.Store(userid, clientdata.Player)
return clientdata.Player
// return nil
}
func KickPlayer(userid uint32) { //踢出玩家
//TODO 返回错误码
//var player *entity.Player
if player1, ok := Mainplayer.Load((userid)); ok {
//取成功,否则创建
head := NewTomeeHeader(1001, userid)
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
player1.SendPack(head.Pack(nil))
player1.MainConn.MainConn.Close()
// clientdata.Player = player
}
//return player
// return nil
}