Guest User

IrcClient.cs

a guest
Jan 9th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. using System.IO;
  13. using System.Threading;
  14. using System.Text.RegularExpressions;
  15. using System.Runtime.InteropServices;
  16. using System.Media;
  17. using System.Diagnostics;
  18.  
  19. namespace WindowsFormsApplication1
  20. {
  21.     class IrcClient
  22.     {
  23.         private string userName;
  24.         private string channel;
  25.  
  26.         public TcpClient tcpClient;
  27.         private StreamReader inputStream;
  28.         private StreamWriter outputStream;
  29.  
  30.         public IrcClient(string ip, int port, string username, string password)
  31.         {
  32.             tcpClient = new TcpClient(ip, port);
  33.             inputStream = new StreamReader(tcpClient.GetStream());
  34.             outputStream = new StreamWriter(tcpClient.GetStream());
  35.  
  36.             outputStream.WriteLine("PASS " + password);
  37.             outputStream.WriteLine("NICK " + userName);
  38.             outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  39.             outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  40.             outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  41.             outputStream.Flush();
  42.         }
  43.  
  44.         public void joinRoom(string channel)
  45.         {
  46.             this.channel = channel;
  47.             outputStream.WriteLine("JOIN #" + channel);
  48.             outputStream.Flush();
  49.         }
  50.  
  51.         public void leaveRoom()
  52.         {
  53.             outputStream.Close();
  54.             inputStream.Close();
  55.  
  56.         }
  57.  
  58.         public void sendIrcMessage(string message)
  59.         {
  60.             outputStream.WriteLine(message);
  61.             outputStream.Flush();
  62.         }
  63.  
  64.         public void sendChatMessage(string message)
  65.         {
  66.             sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  67.         }
  68.  
  69.         public void PingResponse()
  70.         {
  71.             sendIrcMessage("PONG tmi.twitch.tv\r\n");
  72.         }
  73.  
  74.         public string readMessage()
  75.         {
  76.             string message = "";
  77.             message = inputStream.ReadLine();
  78.             return message;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment