Guest User

Untitled

a guest
Apr 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Net;
  7. using System.Net.Sockets;
  8.  
  9. namespace ZeroBot
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             bool Quit = false;
  16.             string BotName;
  17.             string Server;
  18.             int Port;
  19.             string Channel;
  20.             string User;
  21.             if (!File.Exists("BotConfig.txt"))
  22.             {
  23.                 Console.Write("Bot Nickname: ");
  24.                 BotName = Console.ReadLine();
  25.                 Console.Write("Server: ");
  26.                 Server = Console.ReadLine();
  27.                 Console.Write("Port (Usually 6667): ");
  28.                 Port = Int32.Parse(Console.ReadLine());
  29.                 Console.Write("Channel: ");
  30.                 Channel = Console.ReadLine();
  31.                 Console.Write("Bot User: ");
  32.                 User = Console.ReadLine();
  33.                 string[] lines = { BotName, Server, Port.ToString(), Channel, User };
  34.                 File.WriteAllLines("BotConfig.txt", lines);
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine("BotConfig.txt exists.");
  39.             }
  40.  
  41.             string[] BotInfo = File.ReadAllLines("BotConfig.txt");
  42.             BotName = BotInfo[0];
  43.             Server = BotInfo[1];
  44.             Port = Int32.Parse(BotInfo[2]);
  45.             Channel = BotInfo[3];
  46.             User = BotInfo[4];
  47.  
  48.             Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  49.             Console.WriteLine("Socket created");
  50.             IPHostEntry host = Dns.GetHostEntry(Server);
  51.             Console.WriteLine("Host found");
  52.             IPEndPoint endPoint = new IPEndPoint(host.AddressList.First(), Port);
  53.             Console.WriteLine("Endpoint created");
  54.             socket.Connect(endPoint);
  55.             Console.WriteLine("Connected");
  56.             NetworkStream networkstream = new NetworkStream(socket);
  57.             StreamWriter sWriter = new StreamWriter(networkstream, Encoding.UTF8);
  58.             StreamReader sReader = new StreamReader(networkstream, Encoding.UTF8);
  59.             sWriter.WriteLine("USER " + User + " * * :ZeroOne\r\n");
  60.             Console.WriteLine("Sent USER");
  61.             sWriter.WriteLine("NICK " + BotName + "\r\n");
  62.             Console.WriteLine("Sent NICK");
  63.             sWriter.WriteLine("JOIN " + Channel + "\r\n");
  64.             Console.WriteLine("Sent JOIN");
  65.  
  66.             while (!Quit)
  67.             {
  68.                 string input = sReader.ReadLine();
  69.                 if (input != null)
  70.                 {
  71.                     string[] words = input.Split(' ');
  72.                     if (words[0] == "PING")
  73.                     {
  74.                         sWriter.WriteLine("PONG " + words[1] + "\r\n");
  75.                     }
  76.                     Console.WriteLine(input);
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }
Add Comment
Please, Sign In to add comment