I am making a chat application in which on the login page i have made textbox where user will enter communication channel no.. and that channel no i want to store in array ? Now when the user login to particular channel then it shuld show only users of that communication channel in chat pane.
Here i have used hash table for storing users and For this i have made a class chatengine.cs where i have a function to get list of users using javascript with AJAX
My problem is to select list of login users of particular channel
Plz provide me valuable suggestions with some code hint what should i do.. here is some code of getting chatengine class.
public class ChatEngine : IChatEngine
{
const string msg = "<li class=\"{0}\">{1}</li>\r\n";
const string userlistfmt = "<li>{0}</li>\r\n";
const string serverstyle = "servermsg";
const string userstyle = "usermsg";
const string actionstyle = "actionmsg";
const string timeoutfmt = "User {0} timed out";
const string textlimitfmt = "{0}, your message was {1} characters long. The limit is {2} characters.";
const string nickinusefmt = "{0} a user with this nick already exists";
const string joinedfmt = "User {0} has joined";
const string nickfmt = "{0} is now known as {1}";
const string killfmt = "<strong>User {0} has been terminated!</strong>";
const string clearfmt = "<strong>User {0} has cleared all chat log!</strong>";
const string unknowcmdfmt = "<strong>User {0} : Unknow command</strong>";
const string mefmt = "{0} {1}";
const string txtfmt = "{0}: {1}";
const long timerdelay = 30000000;
const int maxbuffer = 2000;
const int textlimit = 2000;
Timer timer;
Hashtable users;
StringCollection chat;
StringCollection pings;
object syncRoot = new object();
/// Default constructor
public ChatEngine()
{
users = new Hashtable();
chat = new StringCollection();
pings = new StringCollection();
TimerCallback OnTimerTick = new TimerCallback( TimerTick );
timer = new Timer( OnTimerTick, null, timerdelay, timerdelay );
}
// Check for pinged out users
private void TimerTick( object state )
{
lock( syncRoot )
{
string[] current = new string[ users.Keys.Count ];
users.Keys.CopyTo( current, 0 );
foreach( string guid in current )
{
if( !pings.Contains( guid ) )
{
chat.Add(
this.MakeServerMessage(
string.Format( timeoutfmt, users[ guid ].ToString() )
)
);
users.Remove( guid );
}
}
pings.Clear();
}
}
// Gets the current list of
// users
public string[] Users
{
get
{
string[] nicks = new string[ users.Count ];
users.Values.CopyTo( nicks, 0 );
return nicks;
}
}
/// HTML Formatted user list
public string UserList
{
get
{
StringBuilder sb = new StringBuilder();
string[] nicks = new string[ users.Count ];
users.Values.CopyTo( nicks, 0 );
foreach( string user in nicks )
{
sb.Append( string.Format( userlistfmt, user ) );
}
return sb.ToString();
}
}
// Gets the current buffer of chat text
public string BufferText
{
get
{
StringBuilder sb = new StringBuilder();
foreach( string line in chat )
{
sb.Append( line );
}
return sb.ToString();
}
}
// Does a user exist based on a guid
public bool GuidExists( string guid )
{
return users.ContainsKey( guid );
}
// Checks to see if the current user
// exists in the list
public bool UserExists(string user)
{
return users.ContainsValue( user );
}
// Adds a user to the list
public void AddUser(string id, string user)
{
lock( syncRoot )
if( !UserExists( user ) )
{
users.Add( id, user );
pings.Add( id );
chat.Add(
this.MakeServerMessage(
string.Format( joinedfmt, user )
)
);
}
}
}
}