/// <summary> /// Create method to hide implementation of ITwitchClient. /// This method should connect to the server once sending the required connecting strings required. /// Therefore the ITwitchClient returned will have been connected to the server on return, however /// it does not access whether the additional server settings have been successful. This for example could /// mean that an attempt has been made to connect to a channel which has failed, the client would still /// be returned connected to the server but not connected to the channel. /// The DefaultMessageHandler should be used to review if a GlobalUserState message is sent by the /// server. /// </summary> /// <param name="url"></param> /// <param name="port"></param> /// <param name="user"></param> /// <param name="password"></param> /// <param name="channel"></param> /// <param name="recievers"></param> /// <returns></returns> public ITwitchClient create(string url, int port, string user, string password, string channel, int cooldown, OperationRequestEventRaiser opEventRaiser, PrivMessageEventRaiser privEventRaiser, WhisperMessageEventRaiser whisperEventRaiser) { try { TcpClient tcp = new TcpClient(url, port); StreamReader sr = new StreamReader(tcp.GetStream()); StreamWriter sw = new StreamWriter(tcp.GetStream()); sw.WriteLine("CAP REQ :twitch.tv/membership\r\n"); sw.Flush(); sw.WriteLine("CAP REQ :twitch.tv/tags\r\n"); sw.Flush(); sw.WriteLine("CAP REQ :twitch.tv/commands\r\n"); sw.Flush(); sw.WriteLine("PASS " + password); sw.WriteLine("NICK " + user); sw.WriteLine("USER " + user + " 8 * :" + user); sw.Flush(); sw.WriteLine(":" + user + "!" + user + "@" + user + ".tmi.twitch.tv JOIN #" + channel); sw.Flush(); return(new TwitchIrcClient(sr, sw, user, channel, cooldown, opEventRaiser, privEventRaiser, whisperEventRaiser)); } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
public TwitchIrcClient(StreamReader sr, StreamWriter sw, string user, string channel, int cooldown, OperationRequestEventRaiser opRequestEventRaiser, MessageEventRaiser privMessageEventRaiser, MessageEventRaiser whisperMessageEventRaiser) { this.reader = sr; this.writer = sw; this.queue = new BlockingCollection <string>();//new Queue<string>(); this.User = user; this.channel = channel; this.cooldown = cooldown; this.opRequestEventRaiser = opRequestEventRaiser; this.privEventRaiser = privMessageEventRaiser; this.whisperEventRaiser = whisperMessageEventRaiser; AsyncRead(); }