using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DuckEmulator.HabboHotel.Inside.Storage.MySql.Database.Interfaces;
using DuckEmulator.Security;
namespace DuckEmulator.HabboHotel.Outside.Clients
{
class ClientManager
{
///
/// Uint for HabboId, client client
///
internal SecurityDictionary Clients;
internal ClientManager()
{
Clients = new SecurityDictionary();
}
internal uint GetIdByUsername(string Username)
{
foreach (Client Client in Clients.Values.ToList())
{
if (Client.GetHabbo() == null)
{
continue;
}
if (Client.GetHabbo().Username.ToLower() == Username.ToLower())
{
return Client.GetHabbo().Id;
}
}
using (IQueryAdapter Adapter = DuckEnvironment.GetAdapter())
{
Adapter.setQuery("SELECT id FROM users WHERE username = '" + Username + "' LIMIT 1");
try
{
return (uint)Adapter.getRow()["id"];
}
catch
{
return new uint();
}
}
}
internal string GetUsernameById(uint Id)
{
foreach (Client Client in Clients.Values.ToList())
{
if (Client.GetHabbo() == null)
{
continue;
}
if (Client.GetHabbo().Id == Id)
{
return Client.GetHabbo().Username;
}
}
using (IQueryAdapter Adapter = DuckEnvironment.GetAdapter())
{
Adapter.setQuery("SELECT username FROM users WHERE id = '" + Id + "' LIMIT 1");
try
{
return (string)Adapter.getRow()["username"];
}
catch
{
return "Unknown";
}
}
}
internal void AddClient(Client Client)
{
Clients.Add(Client.GetId(), Client);
}
internal void RemoveClient(uint Id)
{
Clients.Remove(Id);
}
internal Client GetClient(uint Id)
{
try { return Clients[Id]; }
catch { return null; }
}
internal Client GetClientByHabboId(uint Id)
{
foreach (Client Client in Clients.Values.ToList())
{
if (Client != null)
{
if (Client.GetHabbo() != null)
{
if (Client.GetHabbo().Id == Id)
{
return Client;
}
}
}
}
return null;
}
internal void Dispose()
{
foreach (Client Client in Clients.Values.ToList())
{
Client.Dispose(false);
}
Clients = null;
}
}
}