using System;
//using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
namespace iSM
{
class Program
{
struct EventUser
{
internal string Nickname;
internal string Username;
internal string Hostname;
}
static void Main(string[] args)
{
TcpClient tcpClient = new TcpClient();
string sMainBuf = "";
tcpClient.Connect("
irc.ham.de.euirc.net", 6667);
SendText(ref tcpClient, "USER 1 2 3 :4");
SendText(ref tcpClient, "NICK asdffdsa");
while(tcpClient.Connected)
{
byte[] baBuffer = new byte[512];
string sRawCmd, sPrefix, sCmd, sParams;
EventUser User;
tcpClient.Client.Receive(baBuffer);
sMainBuf = sMainBuf + System.Text.ASCIIEncoding.Default.GetString(baBuffer);
sMainBuf.Replace("\r", "\n");
sMainBuf.Replace("\n\n", "\n");
while(sMainBuf.IndexOf('\n') > -1)
{
sRawCmd = sMainBuf.Substring(0, sMainBuf.IndexOf('\n')-1);
sMainBuf.Remove(0, sMainBuf.IndexOf('\n'));
Console.WriteLine(sRawCmd);
if(sRawCmd.Length > 0)
{
if(sRawCmd[0] == ':')
{
sPrefix = sRawCmd.Substring(0, sRawCmd.IndexOf(' ')-1);
sRawCmd.Remove(0, sRawCmd.IndexOf(' '));
int iHostPrePos = sPrefix.IndexOf('@');
if(iHostPrePos > -1)
{
User.Hostname = sPrefix.Substring(iHostPrePos, sPrefix.Length - iHostPrePos);
sPrefix.Remove(iHostPrePos, sPrefix.Length - iHostPrePos);
}
int iUserPrePos = sPrefix.IndexOf('!');
if(iUserPrePos > -1)
{
User.Username = sPrefix.Substring(iUserPrePos, sPrefix.Length - iUserPrePos);
sPrefix.Remove(iUserPrePos, sPrefix.Length - iUserPrePos);
}
User.Nickname = sPrefix;
}
}
}
}
}
static void SendText(ref TcpClient tcpClient, string Text)
{
if (tcpClient != null)
tcpClient.Client.Send(System.Text.ASCIIEncoding.Default.GetBytes(Text+"\r\n"));
}
}
}