MCPcopy
hub / github.com/aceld/zinx / OnConnectionLost

Function OnConnectionLost

zinx_app_demo/mmo_game/server.go:47–68  ·  view source on GitHub ↗

OnConnectionLost Hook function called when a client disconnects 当客户端断开连接的时候的hook函数

(conn ziface.IConnection)

Source from the content-addressed store, hash-verified

45// OnConnectionLost Hook function called when a client disconnects
46// 当客户端断开连接的时候的hook函数
47func OnConnectionLost(conn ziface.IConnection) {
48 // Get the "pID" property of the current connection
49 // 获取当前连接的PID属性
50 pID, _ := conn.GetProperty("pID")
51 var playerID int32
52 if pID != nil {
53 playerID = pID.(int32)
54 }
55
56 // Get the corresponding player object based on the player ID
57 // 根据pID获取对应的玩家对象
58 player := core.WorldMgrObj.GetPlayerByPID(playerID)
59
60 // Trigger the player's disconnection business logic
61 // 触发玩家下线业务
62 if player != nil {
63 player.LostConnection()
64 }
65
66 fmt.Println("====> Player ", playerID, " left =====")
67
68}
69
70func main() {
71 // Create a server instance

Callers

nothing calls this directly

Calls 3

GetPlayerByPIDMethod · 0.80
LostConnectionMethod · 0.80
GetPropertyMethod · 0.65

Tested by

no test coverage detected