OnConnectionLost Hook function called when a client disconnects 当客户端断开连接的时候的hook函数
(conn ziface.IConnection)
| 45 | // OnConnectionLost Hook function called when a client disconnects |
| 46 | // 当客户端断开连接的时候的hook函数 |
| 47 | func 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 | |
| 70 | func main() { |
| 71 | // Create a server instance |
nothing calls this directly
no test coverage detected