Guest User

IrcClient.cs

a guest
Jan 9th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 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("CAP REQ :twitch.tv/membership");
  39. outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  40. outputStream.Flush();
  41. }
  42.  
  43. public void joinRoom(string channel)
  44. {
  45. this.channel = channel;
  46. outputStream.WriteLine("JOIN #" + channel);
  47. outputStream.Flush();
  48. }
  49.  
  50. public void leaveRoom()
  51. {
  52. outputStream.Close();
  53. inputStream.Close();
  54.  
  55. }
  56.  
  57. public void sendIrcMessage(string message)
  58. {
  59. outputStream.WriteLine(message);
  60. outputStream.Flush();
  61. }
  62.  
  63. public void sendChatMessage(string message)
  64. {
  65. sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  66. }
  67.  
  68. public void PingResponse()
  69. {
  70. sendIrcMessage("PONG tmi.twitch.tv\r\n");
  71. }
  72.  
  73. public string readMessage()
  74. {
  75. string message = "";
  76. message = inputStream.ReadLine();
  77. return message;
  78. }
  79. }
  80. }
Add Comment
Please, Sign In to add comment