Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ircclient
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int port;
- string buf, nick, owner, server, chan;
- System.Net.Sockets.TcpClient sock = new System.Net.Sockets.TcpClient();
- System.IO.TextReader input;
- System.IO.TextWriter output;
- //Get pass, nick, owner, server, port, and channel from user
- Console.Write("Enter bot nick: ");
- nick = Console.ReadLine();
- Console.Write("Enter bot owner name: ");
- owner = Console.ReadLine();
- Console.Write("Enter server IP: ");
- server = Console.ReadLine();
- Console.Write("Enter port number: ");
- port = Convert.ToInt32(Console.ReadLine());
- Console.Write("Channel: ");
- chan = Console.ReadLine();
- //Connect to irc server and get input and output text streams from TcpClient.
- sock.Connect(server, port);
- if (!sock.Connected)
- {
- Console.WriteLine("Failed to connect!");
- return;
- }
- input = new System.IO.StreamReader(sock.GetStream());
- output = new System.IO.StreamWriter(sock.GetStream());
- //Starting USER and NICK login commands
- output.Write(
- "USER " + nick + " 0 * :" + owner + "\r\n" +
- "NICK " + nick + "\r\n" +
- "PASS " + "oauth:drg908drg03kdgr09drgi0drg90se" + "\r\n"
- );
- output.Flush();
- //Process each line received from irc server
- for (buf = input.ReadLine(); ; buf = input.ReadLine())
- {
- //Display received irc message
- Console.WriteLine(buf);
- //Send pong reply to any ping messages
- if (buf.StartsWith("PING ")) { output.Write(buf.Replace("PING", "PONG") + "\r\n"); output.Flush(); }
- if (buf[0] != ':') continue;
- /* IRC commands come in one of these formats:
- * :NICK!USER@HOST COMMAND ARGS ... :DATA\r\n
- * :SERVER COMAND ARGS ... :DATA\r\n
- */
- //After server sends 001 command, we can set mode to bot and join a channel
- if (buf.Split(' ')[1] == "001")
- {
- output.Write(
- "MODE " + nick + " +B\r\n" +
- "JOIN " + chan + "\r\n"
- );
- output.Flush();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement