using System;
using System.Collections;
using Holo.Virtual.Rooms;
using Ion.Storage;
namespace Holo.Managers
{
///
/// Provides management for virtual rooms, aswell as some misc tasks for rooms.
///
public static class roomManager
{
#region Declares
///
/// Contains the hooked virtual room objects.
///
private static Hashtable _Rooms = new Hashtable();
///
/// The peak amount of rooms that has been in the room manager since start of the emulator.
///
private static int _peakRoomCount;
#endregion
#region Virtual room management
///
/// Adds a virtualRoom class together with the roomID to the roomManager.
///
/// The ID of the room to add..
/// The virtualRoom class of this room.
public static void addRoom(int roomID, virtualRoom Room)
{
if (_Rooms.ContainsKey(roomID) == false)
{
_Rooms.Add(roomID, Room);
Out.WriteLine("Room [" + roomID + ", publicroom: " + Room.isPublicroom.ToString().ToLower() + "] loaded.", Out.logFlags.StandardAction);
if (_Rooms.Count > _peakRoomCount)
_peakRoomCount = _Rooms.Count;
}
}
///
/// Removes a room from the roomManager. [if it exists]
///
/// The ID of the room to remove.
public static void removeRoom(int roomID)
{
if(_Rooms.ContainsKey(roomID))
{
bool boolPublicroom = ((virtualRoom)_Rooms[roomID]).isPublicroom;
_Rooms.Remove(roomID);
updateRoomVisitorCount(roomID, 0);
Out.WriteLine("Room [" + roomID + ", publicroom: " + boolPublicroom.ToString().ToLower() + "] destroyed.", Out.logFlags.StandardAction);
GC.Collect();
}
}
///
/// Returns a bool that indicates if the roomManager contains a certain room.
///
/// The ID of the room.
public static bool containsRoom(int roomID)
{
return _Rooms.ContainsKey(roomID);
}
///
/// Returns the current amount of rooms in the roomManager.
///
public static int roomCount
{
get
{
return _Rooms.Count;
}
}
///
/// Returns the peak amount of rooms in the roomManager since boot.
///
public static int peakRoomCount
{
get
{
return _peakRoomCount;
}
}
///
/// Returns a virtualRoom class for a certain room.
///
/// The ID of the room.
public static virtualRoom getRoom(int roomID)
{
return (virtualRoom)_Rooms[roomID];
}
#endregion
#region Misc room related functions
///
/// Updates the inside visitors count in the database for a certain room.
///
/// The ID of the room to update.
/// The new visitors count.
public static void updateRoomVisitorCount(int roomID, int visitorCount)
{
using (DatabaseClient dbClient = (Eucalypt.dbManager.GetClient()))
dbClient.ExecuteQuery("UPDATE rooms SET visitors_now = '" + visitorCount + "' WHERE id = '" + roomID + "' LIMIT 1");
}
public static int getUserCount(int categoryID)
{
int count = 0;
foreach (virtualRoom room in _Rooms.Values)
{
if (room.category == categoryID)
count += room.Users.Count;
}
return count;
}
///
/// Returns the int ID for a certain room state.
///
/// The room state ID.
public static int getRoomState(string State)
{
if (State == "closed")
return 1;
else if (State == "password")
return 2;
else
return 0;
}
///
/// Returns the string state for a certain room state byte.
///
/// The room state ID.
public static string getRoomState(int State)
{
if (State == 1)
return "closed";
else if (State == 2)
return "password";
else
return "open";
}
#endregion
}
}