public void SetOffLineByState(AsyncUserToken userToken) { if (userToken.userInfo.RoomID != -1) { SingleRoom room = allRoom.RoomList[userToken.userInfo.RoomID]; if (room.CurState != RoomActorState.NoReady) { Log4Debug("用户账号:" + userToken.userInfo.Register.userID + " 掉线前保存房间号:" + userToken.userInfo.RoomID); OffLineRooms.AddOrUpdate(userToken.userInfo.Register.userID, -1, (key, oldValue) => userToken.userInfo.RoomID); //更新掉线用户的状态 RoomActorUpdate roomActorUpdate = new RoomActorUpdate() { userIndex = userToken.userInfo.UniqueID, update = (int)RoomActorState.Offline + "" }; room.ClearUDP(userToken.userInfo.UniqueID); room.UpdateState(roomActorUpdate); } else { room.Quit(userToken.userInfo.UniqueID); Log4Debug("用户:" + userToken.userInfo.Register.userID + " 掉线,房间不保存。房间状态:" + room.CurState); } } }