/* Thor Server 2.0 Project - Codenamed "Stockholm" Copyright 2008 - 2009 Joe Hegarty This file is part of The Thor Server 2.0 Project - Codenamed "Stockholm". The Thor Server 2.0 Project - Codenamed "Stockholm" is free software: you can redistribute it and/or modify it under the terms of the Microsoft Public License The Thor Server Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Microsoft Public License for more details. You should have received a copy of the Microsoft Public License along with The Thor Server Project. If not, see http://www.opensource.org/licenses/ms-pl.html */ using System; using System.Collections.Generic; using System.Linq; using StockholmLibrary.Data; using StockholmLibrary.Util; namespace StockholmLibrary.Game.Flats { //------------------------------------ public enum EFlatAvailability { Open = 0, Closed = 1, Passworded = 2 } //------------------------------------ public class FlatManager { private object _flatManagerLock = new object(); private Dictionary _flatList; //********************************************** public FlatManager() { _flatList = new Dictionary(); } //********************************************** public void InitialiseFlat(int roomId) { lock (_flatManagerLock) { if (!_flatList.ContainsKey(roomId)) { _flatList.Add(roomId, new Flat(roomId)); } } } //********************************************** public Flat GetFlat(int roomId) { lock (_flatManagerLock) { if (_flatList.ContainsKey(roomId)) { return _flatList[roomId]; } } return null; } //********************************************** public bool FlatInitialised(int roomId) { lock (_flatManagerLock) { return _flatList.ContainsKey(roomId); } } //********************************************** public bool FlatExists(int roomId) { var db = Stockholm.Get().Database; var roomQuery = from p in db.Rooms where p.RoomID == roomId select p.RoomID; return roomQuery.Count() > 0; } } }