using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Holo.Managers;
using System.Data;
using Ion.Storage;
using Holo.Source.Virtual.Rooms;
using Holo.Source.Managers.RoomManager;
namespace Holo.Source.Virtual.Users
{
class ownRoomManager
{
#region declares
///
/// The username where the rooms belong to
///
internal string _Username;
///
/// Indicates if the the own rooms where generated
///
internal bool generatedOwnRooms = false;
///
/// Indicates i
///
internal bool ownRoomsUpdatedHelper = false;
///
/// Indicates if the own room packet needs an update
///
internal bool ownRoomsUpdated
{
get
{
if (ownRoomsUpdatedHelper)
return true;
foreach (KeyValuePair own in ownRooms)
{
if (own.Value.isActive())
return true;
}
return false;
}
set
{
ownRoomsUpdatedHelper = value;
}
}
///
/// Contains all room data
///
private Dictionary ownRooms;
///
/// The packet
///
internal string ownRoomPacket;
#endregion
#region private classes
///
/// Private structure for the rooms
///
#endregion
public ownRoomManager(string userName)
{
this.ownRooms = new Dictionary();
this._Username = userName;
generateOwnRooms();
}
///
/// Generates the users own rooms
///
internal void generateOwnRooms()
{
if (!this.generatedOwnRooms)
{
this.ownRooms = new Dictionary();
DataTable dTable;
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
dTable = dbClient.getTable("SELECT id,name,description,state,showname,visitors_now,visitors_max,category,model,showname, superusers, password FROM rooms WHERE owner = '" + _Username + "' ");
}
if (dTable.Rows.Count > 0)
{
foreach (DataRow dRow in dTable.Rows)
{
try
{
addOwnRoom(Convert.ToInt32(dRow["id"]), Convert.ToString(dRow["name"]),
Convert.ToInt32(dRow["state"]), Convert.ToInt32(dRow["visitors_max"]),
Convert.ToString(dRow["description"]), Convert.ToInt32(dRow["category"]), dRow["model"].ToString(),
Convert.ToInt32(dRow["showname"]), Convert.ToInt32(dRow["superusers"]), dRow["password"].ToString());
}
catch { }
}
}
ownRoomsUpdated = true;
}
}
///
/// Generates a own room string (the packet)
///
internal void generatedOwnRoomString()
{
if (this.ownRooms.Count > 0)
{
ownRoomPacket = "@P";
foreach (KeyValuePair kvPair in ownRooms)
{
ownRoomPacket += kvPair.Value.toOwnRoomString();
}
}
else
{
ownRoomPacket = "@y" + _Username;
}
}
///
/// returns a own room packet
///
/// your own rooms in packet format
internal string getOwnRoomPacket()
{
generatedOwnRoomString();
return ownRoomPacket;
}
///
/// Adds a room to your own room list
///
/// The id of the room
/// The name of the room
/// The state of the room
/// The maximum of visitors inside it
/// The description of the room
internal void addOwnRoom(int id, string name, int state, int visitorsMax, string description, int category, string model, int showname, int superusers, string password)
{
if (!ownRooms.ContainsKey(id))
{
if (NavigatorHelper.hasRoom(id))
{
ownRooms.Add(id, NavigatorHelper.getRoom(id, category));
}
else
{
ownRooms.Add(id, new RoomStructure(id, name, _Username, model, state, visitorsMax, description, category, "", showname, superusers, password));
}
}
}
///
/// Removes a room from your own room list
///
///
internal void removeOwnRoom(int id)
{
if (ownRooms.ContainsKey(id))
{
RoomStructure room = ownRooms[id];
ownRooms.Remove(id);
NavigatorHelper.removeRoom(id, room.getVisitorsNow());
ownRoomsUpdated = true;
}
}
internal int getCount()
{
return ownRooms.Count;
}
internal int getRoomCategory(int roomID)
{
return ownRooms[roomID].getCategory();
}
internal bool hasRoom(int roomID)
{
return ownRooms.ContainsKey(roomID);
}
///
/// Modifies a room in the collection
///
/// The id of the room
/// The new name of the room, if empty it's not modified
/// The new max visitors, -1 if not modified
/// The state of the room, -2 if it's not modified
/// The new description name
/// Indicates if the description should be modified or not
/// The category of the item, -1 if not different
internal void modifyRoom(int roomID, string name, int visitorsMax, int state, string description, bool updateDescription, int category, string password, string superUsers)
{
if (!ownRooms.ContainsKey(roomID))
return;
NavigatorHelper.modifyRoom(roomID, name, visitorsMax, state, description, updateDescription, category, password, superUsers);
ownRoomsUpdated = true;
}
internal void destroy()
{
this._Username = null;
this.ownRooms.Clear();
this.ownRooms = null;
}
}
}