Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Threading;
- using System.Net.Sockets;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- class MySocket
- {
- public static ArrayList SERVER_1 = new ArrayList();
- public static int totalBytesReceived;
- public static string SERV;
- public static int PORT = 6667;
- public static string NICK;
- public static string PASS;
- public static string USER;
- public static string REAL;
- public static byte[] receivedBytes = new byte[10240];
- public static IPHostEntry ipHost;
- public static IPAddress ipAddress;
- public static IPEndPoint ipEndPoint;
- public static Socket sender = new Socket(AddressFamily.InterNetwork,
- SocketType.Stream,
- ProtocolType.Tcp);
- }
- private static void Write_Line(String text)
- {
- Form1 Form1 = new Form1();
- Form1.textBox1.AppendText(text + "\r\n");
- }
- class CTCP
- {
- public static void VER(string text)
- {
- string SENDER = text.Substring(text.IndexOf(":") + 1, text.IndexOf("!") - 1);
- MySocket.sender.Send(Encoding.ASCII.GetBytes("NOTICE " + SENDER + " :VERSION R-IRCv0.0 " + System.Environment.OSVersion.ToString() + "\x0D\x0A"));
- }
- public static void TIME(string text)
- {
- string SENDER = text.Substring(text.IndexOf(":") + 1, text.IndexOf("!") - 1);
- MySocket.sender.Send(Encoding.ASCII.GetBytes("NOTICE " + SENDER + " : " + System.DateTime.Now.ToString() + "\x0D\x0A"));
- }
- public static void PING(string text)
- {
- Write_Line("Obtained ping request!\r\n" + "Replying...");
- int len = text.Length;
- string POC = text.Substring(Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).IndexOf(":") + 1);
- Write_Line("PONG: " + POC + "\x0D\x0A");
- MySocket.sender.Send(Encoding.ASCII.GetBytes("PONG :" + POC + "\x0D\x0A"));
- }
- }
- private void display_AppData()
- {
- Write_Line(
- "MMMMMMMMMMMMO MMMM MMMMMMMMMMMM? MMMMMMMM \r\n" +
- "MMMMMMMMMMMMMMM MMMM MMMMMMMMMMMMMMM ~MMMMMMMMMMMM \r\n" +
- "MMMM MMMMM MMMM MMMM MMMM+ NMMMM MMMMM \r\n" +
- "MMMM MMMM MMMM MMMM MMMM ~MMMM MMMM \r\n" +
- "MMMM MMMM MMMM MMMM ,MMMM MMMM \r\n" +
- "MMMMMMMMMMMMMMM, MMMM MMMMMMMMMMMMMMM MMMM \r\n" +
- "MMMMMMMMMMMMMM MMMM MMMMMMMMMMMMM? MMMM \r\n" +
- "MMMM MMMMM MMMMMMMM MMMM MMMM :MMMMM MMMM \r\n" +
- "MMMM MMMMM MMMMMMMM MMMM MMMM =MMMM MMMM MMM \r\n" +
- "MMMM MMMMM MMMM MMMM MMMM MMMM MMMMM \r\n" +
- "MMMM MMMMM MMMM MMMM MMMM ,MMMMM7 :MMMMMM \r\n" +
- "MMMM MMMMN MMMM MMMM MMMM, MMMMMMMMMMMO \r\n" +
- "++++ ++++= ++++ ++++ ++++ 7MMMM? \r\n\r\n"+
- "######### ######## #### ### \r\n" +
- "## ### ##### ## ## ## ##### ## ## ## # #### \r\n" +
- "######### ## ## ## ## ##### ## ## ## ## #### ## ## \r\n" +
- "## ### ## ## ### ## ## ## ### ## ## #######\r\n" +
- "## ### ## ## ## ## ## ## ## ## ## ## ## ## \r\n" +
- "## ### ##### ## ## ## ##### ## ## #### ## \r\n"
- );
- }
- private int connect()
- {
- MySocket.SERV = textBox3.Text;
- MySocket.PORT = Convert.ToInt32(numericUpDown1.Value);
- MySocket.NICK = textBox5.Text;
- MySocket.USER = textBox7.Text;
- MySocket.PASS = textBox4.Text;
- Write_Line("Resolving Host...");
- try
- {
- MySocket.ipHost = Dns.Resolve(MySocket.SERV);
- }
- catch (Exception ex)
- {
- Write_Line("Error: " + ex.Message);
- return 0;
- }
- Write_Line("Looking up Network");
- MySocket.ipAddress = MySocket.ipHost.AddressList[0];
- MySocket.ipEndPoint = new IPEndPoint(MySocket.ipAddress, MySocket.PORT);
- Write_Line("Connecting...");
- try
- {
- MySocket.sender.Connect(MySocket.ipEndPoint);
- }
- catch (Exception ex)
- {
- Write_Line(ex.Message);
- return 0;
- }
- Write_Line("Connected!\r\n");
- return 1;
- }
- private void Register()
- {
- if (MySocket.sender.Connected)
- {
- if (MySocket.PASS.Length > 0)
- {
- byte[] PASS = Encoding.ASCII.GetBytes("PASS " + MySocket.PASS + "\x0D\x0A");
- MySocket.sender.Send(PASS);
- }
- byte[] NICK = Encoding.ASCII.GetBytes("NICK " + MySocket.NICK + "\x0D\x0A");
- MySocket.sender.Send(NICK);
- byte[] USER = Encoding.ASCII.GetBytes("USER " + MySocket.USER + " 3 * :R-IRC User" + "\x0D\x0A");
- MySocket.sender.Send(USER);
- }
- }
- private void Update()
- {
- if (MySocket.sender.Connected)
- {
- if (MySocket.sender.Available > 0)
- {
- string LINE;
- string SENDER;
- string MSG;
- MySocket.totalBytesReceived = MySocket.sender.Receive(MySocket.receivedBytes);
- LINE = Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived);
- if (Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Contains("PING :"))
- {
- Write_Line("Obtained ping request!\r\n" + "Replying...");
- int len = Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Length;
- string POC = Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Substring(Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).IndexOf(":") + 1);
- Write_Line("PONG: " + POC + "\x0D\x0A");
- MySocket.sender.Send(Encoding.ASCII.GetBytes("PONG :" + POC + "\x0D\x0A"));
- }
- if (Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived).Contains("PRIVMSG"))
- {
- SENDER = LINE.Substring(LINE.IndexOf(":") + 1, LINE.IndexOf("!") - 1);
- MSG = LINE.Substring(LINE.IndexOf(":",LINE.IndexOf(":")+1) + 1);
- if (LINE.Contains("VERSION"))
- {
- CTCP.VER(LINE);
- }
- if (LINE.Contains("PING"))
- {
- CTCP.PING(LINE);
- }
- else
- {
- Write_Line(SENDER + ": " + MSG);
- }
- }
- else
- {
- Write_Line(Encoding.ASCII.GetString(MySocket.receivedBytes, 0, MySocket.totalBytesReceived));
- }
- }
- }
- }
- private void Scan()
- {
- while (MySocket.sender.Connected)
- {
- Update();
- Thread.Sleep(3000);
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (textBox2.Text != "")
- {
- send_msg(textBox2.Text);
- textBox2.Clear();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- connect();
- Register();
- timer1.Start();
- button1.Enabled = false;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- display_AppData();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- timer1.Stop();
- if (MySocket.sender.Connected)
- {
- MySocket.sender.Send(Encoding.ASCII.GetBytes("QUIT PROJECT R-IRC IS GO!!! \x0D\x0A"));
- MySocket.sender.Disconnect(true);
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Update();
- }
- private void send_msg(string text)
- {
- if (text.Substring(1, text.IndexOf(" ")-1).ToUpper() == "JOIN")
- {
- MySocket.sender.Send(
- Encoding.ASCII.GetBytes(
- text.Substring(1, text.IndexOf(" ")) +
- text.Substring(text.IndexOf(" "))
- + "\x0D\x0A"
- ));
- Write_Line(
- text.Substring(1, text.IndexOf(" ")) +
- text.Substring(text.IndexOf(" "))
- + "\x0D\x0A");
- }
- else if (text.Substring(1, text.IndexOf(" ")-1).ToUpper() == "MSG")
- {
- string TARGET = text.Substring(text.IndexOf(" ")+1, text.IndexOf(" ", text.IndexOf(" ") + 1) - text.IndexOf(" "));
- string MSG = text.Substring(text.IndexOf(" ", text.IndexOf(" ") + 1) + 1);
- MySocket.sender.Send(
- Encoding.ASCII.GetBytes(
- "PRIVMSG " +
- TARGET + " :" +
- MSG + "\x0D\x0A"
- ));
- Write_Line(
- "PRIVMSG " +
- TARGET + " :" +
- MSG + "\r\n");
- }
- else
- {
- MySocket.sender.Send(
- Encoding.ASCII.GetBytes(
- text.Substring(1, text.IndexOf(" ")) +
- text.Substring(text.IndexOf(" "))
- + "\x0D\x0A"
- ));
- Write_Line(
- text.Substring(1, text.IndexOf(" ")) +
- text.Substring(text.IndexOf(" "))
- + "\x0D\x0A");
- }
- }
- private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 13)
- {
- if (textBox2.Text != "")
- {
- send_msg(textBox2.Text);
- textBox2.Clear();
- }
- }
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- timer1.Stop();
- if (MySocket.sender.Connected)
- {
- MySocket.sender.Send(Encoding.ASCII.GetBytes("QUIT PROJECT R-IRC IS GO!!! \x0D\x0A"));
- MySocket.sender.Disconnect(true);
- }
- }
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- }
- private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
- {
- System.Diagnostics.Process.Start(e.LinkText);
- }
- private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
- {
- }
- private void tableLayoutPanel3_Paint(object sender, PaintEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement