void OnDestroy() { Completed -= OnComplete; Received -= OnReceiveMsg; // 退出的时候, 最后尝试一下看消息能否发出 LeaveRoom output = new LeaveRoom() { RoomId = RoomId, ReleaseIfNoUser = true, }; SendMsg(ROOM.LeaveRoom, output.ToByteArray()); RoomLogic.Fini(); }
public void RemovePlayer(SocketAsyncEventArgs args, bool bCloseRoomIfNoUser) { bool ret = false; PlayerInfo pi = GetPlayer(args); if (pi == null) { Log($"RoomManager RemovePlayer Error - Player not found!"); return; } // 如果该玩家还没有离开房间, 则要离开这个房间 RoomLogic roomLogic = Rooms[pi.RoomId]; if (roomLogic.IsOnline(pi.Enter.TokenId)) { roomLogic.Offline(pi.Enter.TokenId); // 通知大厅 UpdateRoomInfoToLobby(roomLogic); } // 最后看是否需要关闭房间 if (roomLogic.CurPlayerCount == 0 && bCloseRoomIfNoUser) { // 关闭房间 roomLogic.Fini(); // 结束化 Rooms.Remove(pi.RoomId); // 通知大厅:删除房间 Protobuf.Lobby.UpdateRoomInfo output2 = new Protobuf.Lobby.UpdateRoomInfo() { RoomId = roomLogic.RoomId, IsRemove = true, }; MixedManager.Instance.LobbyManager.SendMsg(Protobuf.Lobby.LOBBY.UpdateRoomInfo, output2.ToByteArray()); } Players.Remove(args); }