#region Arthea License
/***********************************************************************
* Arthea MUD by R. Jennings (2007) http://arthea.googlecode.com/ *
* By using this code you comply with the Artistic and GPLv2 Licenses. *
***********************************************************************/
#endregion
using System.Collections.Generic;
using Arthea.Connections.Enums;
using Arthea.Environment;
namespace Arthea.Connections
{
/// <summary>
/// Maintains a list of connections.
/// </summary>
public class ConnectionList : List<Connection>
{
#region [rgn] Methods (3)
// [rgn] Public Methods (3)
/// <summary>
/// Writes this instance.
/// </summary>
public void ProcessOutput()
{
if (Server.Instance.State != ServerState.Running)
return;
foreach (Connection conn in this)
{
if (conn.CanWrite())
{
conn.ProcessOutput();
}
}
}
/// <summary>
/// Reads input for all connections.
/// </summary>
public void ReadInput()
{
IEnumerator<Connection> c = GetEnumerator();
while (c.MoveNext())
{
if (c.Current.CanError())
{
Log.Info("Bad connection from {0} kicking them out.", c.Current);
c.Current.State = ConnectionState.Disconnected;
}
else if (c.Current.CanRead())
{
c.Current.Read();
}
}
}
/// <summary>
/// Processes this instance.
/// </summary>
public void Update()
{
for (int i = 0; i < Count;)
{
Connection conn = this[i];
if (conn.Wait > 0)
{
conn.Wait--;
i++;
continue;
}
if (conn.State == ConnectionState.Disconnected)
{
RemoveAt(i);
conn.Close();
continue;
}
if (conn.HasInput())
{
conn.ProcessInput();
}
i++;
}
}
#endregion [rgn]
}
}