|
IRC Bot Help C#
IRC Bot Help C#
Currently viewing this thread: 1 (0 members and 1 guests)
 December 20th, 2004 03:35 PM
Neverside Newbie
Status: Offline!
IRC Bot Help C#
I just coded a small console IRC Bot. I just started learning C# a few days ago. I thought making something like this would be a good start. I'm just having trouble gaining a connection. The first time I ran the program it connected just fine. Now if I try and run it or build it it won't make a connection. Also how could I make it ask for a port number to connect to because when I was making it it gave me an error saying strings cannot be converted to int or something. So I just set it to the regular default for irc. I had my friends try this on their computers as well and they timed out during the connection as well. Please help if you can.
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
namespace Xirc_Bot
{
class Irc
{
public static int PORT = 6667;
public static string SERVER = "irc.gamesurge.net";
public static string USER = "Xirc-Bot v1.0b";
public static string NICK = "Xirc-Bot";
public static string CHANNEL = "#gibgames";
public static StreamWriter sw;
public static StreamReader sr;
public static void IrcBotTest()
{
Console.WriteLine("Test: " + USER);
}
public static void Main()
{
IrcBotTest();
Console.Write("Enter server name/address: ");
String strSERVER = Console.ReadLine();
Console.Write("Enter nickname: ");
String strNICK = Console.ReadLine();
Console.Write("Enter channel: ");
String strCHANNEL = Console.ReadLine();
string nick,input,pingmsg,data;
int chr,chr2;
try
{
IPHostEntry iphe = Dns.Resolve(strSERVER);
IPEndPoint ipep = new IPEndPoint(iphe.AddressList[0],PORT);
Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
server.Connect(ipep);
NetworkStream ns = new NetworkStream(server);
sw = new StreamWriter(ns);
sr = new StreamReader(ns);
sw.WriteLine("strNICK " + strNICK);
sw.Flush();
sw.WriteLine(USER);
sw.Flush();
while(true)
{
while((input = sr.ReadLine()) != null)
{
chr = input.IndexOf("PING :",0,input.Length);
if(chr != -1)
{
pingmsg =input.Replace("PING :","PONG ");
sw.WriteLine(pingmsg);
sw.Flush();
Thread.Sleep(10000);
sw.WriteLine("JOIN "+CHANNEL);
sw.Flush();
}
Console.WriteLine(input);
if(input.EndsWith("JOIN " + strCHANNEL))
{
nick = input.Substring(1,input.IndexOf("!")-1);
sw.WriteLine("NOTICE " + nick + " :Hey " + nick +
" get the **** out of my channel !!!!");
sw.Flush();
Thread.Sleep(2000);
}
chr = input.IndexOf("!join",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr).Replace("!join","JOIN ");
Console.WriteLine(pingmsg);
sw.WriteLine(pingmsg);
sw.Flush();
}
chr = input.IndexOf("!part",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr).Replace("!part","PART ");
Console.WriteLine(pingmsg);
sw.WriteLine(pingmsg);
sw.Flush();
}
chr = input.IndexOf("!say",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr+4);
chr = input.IndexOf("#",0);
chr2 = input.IndexOf(" ",chr);
data = input.Substring(chr,chr2-chr);
sw.WriteLine("PRIVMSG "+data+" : "+pingmsg);
sw.Flush();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Error:");
Console.WriteLine(e.Message);
}
finally
{
Main();
}
}
}
}
___________________
http://www.enviousgamers.tk/
 December 20th, 2004 03:39 PM
whoa, wtf?
Status: Offline!
Originally posted by XtC4242
I just coded a small console IRC Bot. I just started learning C# a few days ago. I thought making something like this would be a good start. I'm just having trouble gaining a connection. The first time I ran the program it connected just fine. Now if I try and run it or build it it won't make a connection. Also how could I make it ask for a port number to connect to because when I was making it it gave me an error saying strings cannot be converted to int or something. So I just set it to the regular default for irc. I had my friends try this on their computers as well and they timed out during the connection as well. Please help if you can.
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
namespace Xirc_Bot
{
class Irc
{
public static int PORT = 6667;
public static string SERVER = "irc.gamesurge.net";
public static string USER = "Xirc-Bot v1.0b";
public static string NICK = "Xirc-Bot";
public static string CHANNEL = "#gibgames";
public static StreamWriter sw;
public static StreamReader sr;
public static void IrcBotTest()
{
Console.WriteLine("Test: " + USER);
}
public static void Main()
{
IrcBotTest();
Console.Write("Enter server name/address: ");
String strSERVER = Console.ReadLine();
Console.Write("Enter nickname: ");
String strNICK = Console.ReadLine();
Console.Write("Enter channel: ");
String strCHANNEL = Console.ReadLine();
string nick,input,pingmsg,data;
int chr,chr2;
try
{
IPHostEntry iphe = Dns.Resolve(strSERVER);
IPEndPoint ipep = new IPEndPoint(iphe.AddressList[0],PORT);
Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
server.Connect(ipep);
NetworkStream ns = new NetworkStream(server);
sw = new StreamWriter(ns);
sr = new StreamReader(ns);
sw.WriteLine("strNICK " + strNICK);
sw.Flush();
sw.WriteLine(USER);
sw.Flush();
while(true)
{
while((input = sr.ReadLine()) != null)
{
chr = input.IndexOf("PING :",0,input.Length);
if(chr != -1)
{
pingmsg =input.Replace("PING :","PONG ");
sw.WriteLine(pingmsg);
sw.Flush();
Thread.Sleep(10000);
sw.WriteLine("JOIN "+CHANNEL);
sw.Flush();
}
Console.WriteLine(input);
if(input.EndsWith("JOIN " + strCHANNEL))
{
nick = input.Substring(1,input.IndexOf("!")-1);
sw.WriteLine("NOTICE " + nick + " :Hey " + nick +
" get the **** out of my channel !!!!");
sw.Flush();
Thread.Sleep(2000);
}
chr = input.IndexOf("!join",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr).Replace("!join","JOIN ");
Console.WriteLine(pingmsg);
sw.WriteLine(pingmsg);
sw.Flush();
}
chr = input.IndexOf("!part",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr).Replace("!part","PART ");
Console.WriteLine(pingmsg);
sw.WriteLine(pingmsg);
sw.Flush();
}
chr = input.IndexOf("!say",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr+4);
chr = input.IndexOf("#",0);
chr2 = input.IndexOf(" ",chr);
data = input.Substring(chr,chr2-chr);
sw.WriteLine("PRIVMSG "+data+" : "+pingmsg);
sw.Flush();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Error:");
Console.WriteLine(e.Message);
}
finally
{
Main();
}
}
}
}
Originally posted by XtC4242
I just coded a small console IRC Bot. I just started learning C# a few days ago. I thought making something like this would be a good start. I'm just having trouble gaining a connection. The first time I ran the program it connected just fine. Now if I try and run it or build it it won't make a connection. Also how could I make it ask for a port number to connect to because when I was making it it gave me an error saying strings cannot be converted to int or something. So I just set it to the regular default for irc. I had my friends try this on their computers as well and they timed out during the connection as well. Please help if you can.
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
namespace Xirc_Bot
{
class Irc
{
public static int PORT = 6667;
public static string SERVER = "irc.gamesurge.net";
public static string USER = "Xirc-Bot v1.0b";
public static string NICK = "Xirc-Bot";
public static string CHANNEL = "#gibgames";
public static StreamWriter sw;
public static StreamReader sr;
public static void IrcBotTest()
{
Console.WriteLine("Test: " + USER);
}
public static void Main()
{
IrcBotTest();
Console.Write("Enter server name/address: ");
String strSERVER = Console.ReadLine();
Console.Write("Enter nickname: ");
String strNICK = Console.ReadLine();
Console.Write("Enter channel: ");
String strCHANNEL = Console.ReadLine();
string nick,input,pingmsg,data;
int chr,chr2;
try
{
IPHostEntry iphe = Dns.Resolve(strSERVER);
IPEndPoint ipep = new IPEndPoint(iphe.AddressList[0],PORT);
Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
server.Connect(ipep);
NetworkStream ns = new NetworkStream(server);
sw = new StreamWriter(ns);
sr = new StreamReader(ns);
sw.WriteLine("strNICK " + strNICK);
sw.Flush();
sw.WriteLine(USER);
sw.Flush();
while(true)
{
while((input = sr.ReadLine()) != null)
{
chr = input.IndexOf("PING :",0,input.Length);
if(chr != -1)
{
pingmsg =input.Replace("PING :","PONG ");
sw.WriteLine(pingmsg);
sw.Flush();
Thread.Sleep(10000);
sw.WriteLine("JOIN "+CHANNEL);
sw.Flush();
}
Console.WriteLine(input);
if(input.EndsWith("JOIN " + strCHANNEL))
{
nick = input.Substring(1,input.IndexOf("!")-1);
sw.WriteLine("NOTICE " + nick + " :Hey " + nick +
" get the **** out of my channel !!!!");
sw.Flush();
Thread.Sleep(2000);
}
chr = input.IndexOf("!join",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr).Replace("!join","JOIN ");
Console.WriteLine(pingmsg);
sw.WriteLine(pingmsg);
sw.Flush();
}
chr = input.IndexOf("!part",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr).Replace("!part","PART ");
Console.WriteLine(pingmsg);
sw.WriteLine(pingmsg);
sw.Flush();
}
chr = input.IndexOf("!say",0,input.Length);
if(chr != -1)
{
pingmsg = input.Remove(0,chr+4);
chr = input.IndexOf("#",0);
chr2 = input.IndexOf(" ",chr);
data = input.Substring(chr,chr2-chr);
sw.WriteLine("PRIVMSG "+data+" : "+pingmsg);
sw.Flush();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Error:");
Console.WriteLine(e.Message);
}
finally
{
Main();
}
}
}
}
*sigh* You got a lot of work today. Come up with a single question and maybe I can help.
___________________
Fomerly known as lasnaranjas. Holler.

 December 20th, 2004 04:09 PM
whoa, wtf?
Status: Offline!
Here's the source of a client I did a while ago. I stated it, forgot about it, and left it where it was (I think it builds).
It sucks though, got some major bugs.
http://dev.jeromegagner.com/Irc%20Client.zip
-jerome
___________________
Fomerly known as lasnaranjas. Holler.

 March 30th, 2005 07:52 AM
Neverside Newbie
Status: Offline!
I do not know C# atoll but I know RFC1459 considerably well and I can understand some of your source. It looks as if you are not sending the unique PONG response correctly. p10 more specifically requires that the client send back PONG :UniqueNumericalStringHere. UniqueNumericalString being a ctime value that the server sends to you in the initial PING. That is the only reason I can think of that it would be timing out during connection. And again, please excuse my ignorance if I did not see the correct PONG response.
 April 30th, 2005 12:01 AM
whoa, wtf?
Status: Offline!
You're probably right. That code is at least a year old when I was still young. keke.
___________________
Fomerly known as lasnaranjas. Holler.

 May 1st, 2005 10:07 PM
Neverside Newbie
Status: Offline!
You need to do some tokening in order to get the connection to be succesful, in other words, you need to break up the message sent to you by the server, because at the end of Ping : there is a servername or jibberish and you need to add that to your PONG : message. I had the same issue a while ago, and by toking the string I was able to tryunf.
|