/// <summary> /// /// </summary> /// <param name="twitchUsername"></param> /// <param name="twitchOAuthToken"> /// A chat login token which can be generated here: http://www.twitchapps.com/tmi/ /// </param> public void Start(string twitchUsername, string twitchOAuthToken) { var client = new IrcClient(); client.Connected += client_Connected; client.RawMessageReceived += client_RawMessageReceived; client.Error += client_Error; client.ConnectFailed += client_ConnectFailed; client.PongReceived += client_PongReceived; client.ServerBounce += client_ServerBounce; client.ProtocolError += client_ProtocolError; client.ErrorMessageReceived += client_ErrorMessageReceived; _client = client; _registrationInformation = new IrcUserRegistrationInfo() { NickName = twitchUsername, Password = twitchOAuthToken, UserName = twitchUsername, RealName = twitchUsername }; Connect(); _lastPongTime = DateTime.UtcNow; StartPingLoop(); }
public void Connect() { this.client = new IrcClient(); this.client.ErrorMessageReceived += client_ErrorMessageReceived; this.client.Connected += client_Connected; this.client.RawMessageReceived += client_RawMessageReceived; this.client.ConnectFailed += client_ConnectFailed; this.client.MotdReceived += client_MotdReceived; this.client.Error += client_Error; this.client.ProtocolError += client_ProtocolError; this.client.Disconnected += client_Disconnected; this.client.NetworkInformationReceived += client_NetworkInformationReceived; this.client.ClientInfoReceived += client_ClientInfoReceived; this.client.ValidateSslCertificate += client_ValidateSslCertificate; IrcUserRegistrationInfo serviceReg = new IrcUserRegistrationInfo(); serviceReg.RealName = REALNAME; serviceReg.UserName = USERNAME; serviceReg.NickName = this.Nick; serviceReg.Password = ""; this.client.Connect(this.server, 6667, false, serviceReg); while (!isQuitting) { Thread.Sleep(10000); } }
public void Connect() { ircClient = new IrcClient { FloodPreventer = new IrcStandardFloodPreventer(10, 100) }; // register events ircClient.Connected += ircClient_Connected; ircClient.ConnectFailed += ircClient_ConnectFailed; ircClient.Disconnected += ircClient_Disconnected; ircClient.Registered += ircClient_Registered; ircClient.RawMessageReceived += ircClient_RawMessageReceived; ircClient.RawMessageSent += ircClient_RawMessageSent; IrcRegistrationInfo iri = new IrcUserRegistrationInfo() { UserName = "******", NickName = "yohelloyukinon", Password = "******" }; ircClient.Connect("irc.twitch.tv", 6667, false, iri); Thread.Sleep(1000); }
public void TestBasicConnectAndRegistration() { var client = new StandardIrcClient(); using (var connectedEvent = new ManualResetEventSlim(false)) { var registrationInfo = new IrcUserRegistrationInfo() { NickName = "cmpct_test", Password = "", UserName = "******", RealName = "cmpct_test" }; client.Connected += (sender, e) => connectedEvent.Set(); client.Connect("127.0.0.1", 6667, false, registrationInfo); if (!connectedEvent.Wait(100)) { client.Dispose(); Assert.Fail("ConnectedEvent not called: server not listening?"); } using (var registrationEvent = new ManualResetEventSlim(false)) { client.Registered += (sender, e) => registrationEvent.Set(); if (!registrationEvent.Wait(500)) { client.Dispose(); Assert.Fail("RegistrationEvent not called: not registered?"); } } } }
public MainWindow() { InitializeComponent(); this.messageField.KeyDown += textBoxEnter; //Instantiate an IRC client session irc = new StandardIrcClient(); IrcRegistrationInfo info = new IrcUserRegistrationInfo() { NickName = Environment.UserName, // "NerdChat", UserName = Environment.UserName + "NerdChat", RealName = "NerdChat" }; //Open IRC client connection irc.Connect("irc.freenode.net", false, info); irc.RawMessageReceived += IrcClient_Receive; // Add server to treeview TreeViewItem serverTreeItem = new TreeViewItem(); serverTreeItem.Header = "irc.freenode.net"; channelTree.Items.Add(serverTreeItem); // Add some dummy channels for testing for (int i = 0; i < 10; i++) { TreeViewItem dummyItem = new TreeViewItem(); dummyItem.Header = "#dummy" + i; serverTreeItem.Items.Add(dummyItem); } }
static void Main(string[] args) { IrcRegistrationInfo info = new IrcUserRegistrationInfo() { NickName = "myBot", UserName = "******", RealName = "myBot" }; //Open IRC client connection irc.Connected += Irc_Connected; irc.RawMessageReceived += IrcClient_Receive; irc.MotdReceived += Irc_MotdReceived; irc.Connect("irc.SUPERSERVER.org", 6667, false, info); String cmd = ""; while (cmd != "/exit") { cmd = Console.ReadLine(); irc.SendRawMessage(cmd); } }
public async Task Connect(string server, int port, bool useSsl, string nickName, string userName, string realname, List <string> channelsToJoin) { channels = channelsToJoin; irc = new StandardIrcClient { FloodPreventer = new IrcStandardFloodPreventer(3, 5000) }; irc.RawMessageSent += IrcOnRawMessageSent; irc.Error += OnIrcOnOnError; irc.Registered += IrcOnRegistered; irc.Disconnected += IrcOnDisconnected; try { var registrationInfo = new IrcUserRegistrationInfo { NickName = nickName, UserName = userName, RealName = realname }; var ipAddresses = await Dns.GetHostAddressesAsync(server); var ipAddress = ipAddresses.First(x => x.AddressFamily == AddressFamily.InterNetwork); Console.WriteLine($"Resolved IP: {ipAddress}"); var ipEndPoint = new IPEndPoint(ipAddress, port); irc.Connect(ipEndPoint, useSsl, registrationInfo); } catch (Exception e) { Console.WriteLine(e); } }
bool ConnectIRC(object[] Params) { if (!Session.Safe || (!Session.InSpace && !Session.InStation)) { return(false); } if (Config.UseIRC) { try { IrcUserRegistrationInfo reginfo = new IrcUserRegistrationInfo(); reginfo.NickName = Me.Name.Replace(" ", string.Empty).Replace("'", string.Empty); reginfo.RealName = Me.Name.Replace(" ", string.Empty).Replace("'", string.Empty); reginfo.UserName = Me.Name.Replace(" ", string.Empty).Replace("'", string.Empty); IRC.FloodPreventer = new IrcStandardFloodPreventer(4, 2000); IRC.Connect(new Uri("irc://" + Config.Server), reginfo); } catch { return(false); } } return(true); }
internal void Start(string parChannel, string parNickname) { if (Client != null) { return; } Channel = parChannel.ToLower(); Nickname = parNickname; var reg = new IrcUserRegistrationInfo { RealName = Nickname, NickName = Nickname, UserName = Nickname }; Client = new StandardIrcClient { FloodPreventer = new IrcStandardFloodPreventer(4, 2000) }; Client.ErrorMessageReceived += (sender, args) => { Console.WriteLine(args.Message); }; Client.Connected += (sender, args) => { }; Client.Disconnected += (sender, args) => { Client.Dispose(); Client = null; Thread.Sleep(120000); Start(Channel, Nickname); }; Client.Registered += (sender, args) => { var tmp = (StandardIrcClient)sender; tmp.LocalUser.JoinedChannel += (o, JoinedChannelArgs) => { if (JoinedChannelArgs.Channel.Name == Channel) { tmp.RawMessageReceived += (sender1, eventArgs) => { if (eventArgs.Message.Command != "PRIVMSG") { return; } var msgArgs = new MessageArgs(eventArgs.Message.Parameters[1], eventArgs.Message.Source.Name); MessageReceivedHandler(msgArgs); }; } }; tmp.Channels.Join(Channel); }; Client.Connect(Server, false, reg); }
public void Connect() { // Server var server = _configuration.GetValue <string>("client:server:address"); var port = _configuration.GetValue <int?>("client:server:port"); var secure = _configuration.GetValue <bool?>("client:server:secure"); // User var userName = _configuration.GetValue <string>("client:user:username"); var nickName = _configuration.GetValue <string>("client:user:nickname"); var realName = _configuration.GetValue <string>("client:user:realname"); // Misc var debug = _configuration.GetValue <bool>("client:debug"); // Validation of Configuration if ( !port.HasValue || !secure.HasValue || string.IsNullOrWhiteSpace(server) || string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(nickName) || string.IsNullOrWhiteSpace(realName) ) { throw new ConfigurationFormatException(); } // Create the userInfo Object var userInfo = new IrcUserRegistrationInfo { NickName = nickName, RealName = realName, UserName = userName }; // Append A password if we have one if (_configuration.GetValue <string>("client:user:password") != null) { userInfo.Password = _configuration.GetValue <string>("client:user:password"); } AssociateInitialEvents(server); // During debuging, echo results to screen if (debug) { IrcClient.RawMessageSent += (sender, ircArgs) => _logger.LogInformation(ircArgs.RawContent); IrcClient.RawMessageReceived += (sender, ircArgs) => _logger.LogInformation(ircArgs.RawContent); } IrcClient.Connect(server, port.Value, secure.Value, userInfo); }
private void findClientConfs() { regInfo = new IrcUserRegistrationInfo(); var conf = server.channels[0].config; regInfo.NickName = conf["nickname"]; regInfo.Password = conf["password"]; regInfo.RealName = conf["realname"]; regInfo.UserName = conf["username"]; regInfo.UserModes = new char[] { }; }
public Task ConnectAsync() { IrcUserRegistrationInfo registrationInfo = new IrcUserRegistrationInfo(); registrationInfo.RealName = this.ServerConfiguration.BotName; registrationInfo.UserName = ServerConfiguration.BotName; registrationInfo.NickName = ServerConfiguration.BotName; RawMessageReceived += OnRawMessageReceived; base.Connect(ServerConfiguration.GetServerEndpoint(), false, registrationInfo); return(Task.CompletedTask); }
/// <summary> /// Initializes a new instance of the IrcNetworkViewModel class /// </summary> public IrcNetworkViewModel(Network network, Settings settings) { this.Closable = true; this.DisplayName = network.Name; this.Settings = settings; IrcRegistrationInfo info; if (network.UseCustomIdentity) { info = new IrcUserRegistrationInfo() { NickName = network.Identity.Name ?? Environment.UserName, UserName = Environment.UserName, RealName = network.Identity.RealName ?? "Rumpelstilzchen", }; } else { Identity id = Identity.GlobalIdentity(); info = new IrcUserRegistrationInfo() { NickName = id.Name ?? Environment.UserName, UserName = Environment.UserName, RealName = id.RealName ?? "Rumpelstilzchen", }; } this.ProgressService = IoC.Get <IProgressService>(); this.Client = new IrcClient(); this.Client.Registered += this.clientRegistered; this.Client.ProtocolError += this.clientProtocolError; // TODO Display Popup this.Client.ConnectFailed += delegate(object sender, IrcErrorEventArgs e) { this.ProgressService.Hide(); Console.WriteLine("Couldn't connect to server"); }; using (var connectedEvent = new ManualResetEventSlim(false)) { this.Client.Connected += (sender, e) => connectedEvent.Set(); this.ProgressService.Show(); client.Connect(network.Address, false, info); if (!connectedEvent.Wait(1000)) { this.Client.Dispose(); return; } } }
/// <summary> /// Overwritten Init method. /// This method connects to the M59 server. /// So we connect to IRC here as well. /// </summary> public override void Init() { // base handler connecting to m59 server base.Init(); // create IRC command queues ChatCommandQueue = new LockingQueue <string>(); AdminCommandQueue = new LockingQueue <string>(); WhoXQueryQueue = new WhoXQueryQueue(); // Whether bot echoes to IRC or not. DisplayMessages = true; // Create list for keeping track of user registration. UserRegistration = new Dictionary <string, bool>(); // Init list of recent admins to send a command. RecentAdmins = new List <string>(); // create an IRC client instance IrcClient = new StandardIrcClient(); IrcClient.FloodPreventer = new FloodPreventer(Config.MaxBurst, Config.Refill); // hook up IRC client event handlers // beware! these are executed by the internal workthread // of the library. IrcClient.Connected += OnIrcClientConnected; IrcClient.ConnectFailed += OnIrcClientConnectFailed; IrcClient.Disconnected += OnIrcClientDisconnected; IrcClient.Registered += OnIrcClientRegistered; IrcClient.ProtocolError += OnIrcClientProtocolError; IrcClient.WhoXReplyReceived += OnWhoXReplyReceived; // build our IRC connection info IrcUserRegistrationInfo regInfo = new IrcUserRegistrationInfo(); regInfo.UserName = Config.NickName; regInfo.RealName = Config.NickName; regInfo.NickName = Config.NickName; // if password is set if (!String.Equals(Config.IRCPassword, String.Empty)) { regInfo.Password = Config.IRCPassword; } // log IRC connecting Log("SYS", "Connecting IRC to " + Config.IRCServer + ":" + Config.IRCPort); // connect the lib internally (this is async) IrcClient.Connect(Config.IRCServer, Config.IRCPort, false, regInfo); }
private void Reconnect() { if (IrcClient != null) { IrcClient.Disconnect(); IrcClient = null; } IrcClient = new IrcClient(); IrcClient.ClientId = "TWITCHCLIENT 2"; IrcClient.Connected += IrcClient_Connected; IrcClient.ProtocolError += IrcClient_ProtocolError; IrcClient.Error += IrcClient_Error; IrcClient.Disconnected += IrcClient_Disconnected; IrcClient.RawMessageReceived += IrcClient_RawMessageReceived; IrcClient.ConnectFailed += IrcClient_ConnectFailed; IrcClient.MotdReceived += IrcClient_MotdReceived; Random rnd = new Random(); string s = "justinfan" + rnd.Next(100000000); regInfo = new IrcUserRegistrationInfo() { NickName = s, UserName = s, Password = "******", RealName = s }; Header = "http://twitch.tv, Подключаемся к " + StreamerNick; if (!string.IsNullOrEmpty(_directAdress)) { string[] dat = _directAdress.Split(':'); try { int port = int.Parse(dat[1]); IrcClient.Connect(dat[0], port, false, regInfo); } catch { Header = "http://twitch.tv, Ошибка " + StreamerNick; } } else { IrcClient.Connect(StreamerNick + ".jtvirc.com", 6667, false, regInfo); } }
protected override Task DoStartAsync(CancellationToken cancellationToken) { var username = this.GetUserName(); var registration = new IrcUserRegistrationInfo { NickName = username, RealName = username, UserName = username, }; this.Client.Connect(this.Options.Host, this.Options.UseSsl, registration); this.Logger.LogInformation($"Connected to {this.Options.Host} as {username}"); return(Task.CompletedTask); }
public Task Connect() { connectingTaskCompletionSource = new TaskCompletionSource <object>(); client.Connected += OnConnectedCallback; client.ConnectFailed += OnConnectFailedCallback; var registrationInfo = new IrcUserRegistrationInfo { NickName = serverConfig.UserName, Password = serverConfig.Password, RealName = "Relays messages between chat rooms on different services.", UserName = serverConfig.UserName }; client.Connect(serverConfig.ServerAddress, false, registrationInfo); return(connectingTaskCompletionSource.Task); }
public void Connect(IPEndPoint ipEndPoint, IrcUserRegistrationInfo registrationInfo) { Connect(registrationInfo); if (Client == null) { Client = new Tcp(Loop); } Client.Connect(ipEndPoint, (ex) => { isConnected = true; HandleClientConnected(registrationInfo); Client.Data += OnRead; Client.Resume(); }); HandleClientConnecting(); }
private void Reconnect() { this.Status = false; if (IrcClient != null) { IrcClient.Disconnect(); IrcClient = null; } IrcClient = new IrcClient(); IrcClient.Connected += IrcClient_Connected; IrcClient.ProtocolError += IrcClient_ProtocolError; IrcClient.Error += IrcClient_Error; IrcClient.Disconnected += IrcClient_Disconnected; IrcClient.RawMessageReceived += IrcClient_RawMessageReceived; IrcClient.ConnectFailed += IrcClient_ConnectFailed; IrcClient.MotdReceived += IrcClient_MotdReceived; IrcClient.RawMessageSent += IrcClient_RawMessageSent; // IrcClient. //IrcClient. Random rnd = new Random(); string s = "Guest" + rnd.Next(1000, 99999); regInfo = new IrcUserRegistrationInfo() { NickName = s, UserName = s, Password = null, RealName = s }; string[] dat = Properties.Settings.Default.url_GohaTV.Split(':'); try { int port = int.Parse(dat[1]); IrcClient.Connect(dat[0], port, false, regInfo); } catch (Exception e) { StartReconnect(); MessageError("Connection error: " + e.Message); } }
/// <summary> /// Overwritten Init method. /// This method connects to the M59 server. /// So we connect to IRC here as well. /// </summary> public override void Init() { // base handler connecting to m59 server base.Init(); // create IRC command queues ChatCommandQueue = new LockingQueue <string>(); AdminCommandQueue = new LockingQueue <string>(); // create an IRC client instance IrcClient = new IrcClient(); IrcClient.FloodPreventer = new FloodPreventer(Config.MaxBurst, Config.Refill); // hook up IRC client event handlers // beware! these are executed by the internal workthread // of the library. IrcClient.Connected += OnIrcClientConnected; IrcClient.ConnectFailed += OnIrcClientConnectFailed; IrcClient.Disconnected += OnIrcClientDisconnected; IrcClient.Registered += OnIrcClientRegistered; IrcClient.ProtocolError += OnIrcClientProtocolError; // build our IRC connection info IrcUserRegistrationInfo regInfo = new IrcUserRegistrationInfo(); regInfo.UserName = Config.NickName; regInfo.RealName = Config.NickName; regInfo.NickName = Config.NickName; // if password is set if (!String.Equals(Config.IRCPassword, String.Empty)) { regInfo.Password = Config.IRCPassword; } // log IRC connecting Log("SYS", "Connecting IRC to " + Config.IRCServer + ":" + Config.IRCPort); // connect the lib internally (this is async) IrcClient.Connect(Config.IRCServer, Config.IRCPort, false, regInfo); }
static void Main(string[] args) { client = new IrcClient(); var reg = new IrcUserRegistrationInfo(); reg.NickName = "botctgn"; reg.UserName = "******"; reg.RealName = "botctgn"; client.Connect("irc.freenode.net", 6667, false, reg); client.Disconnected += ClientOnDisconnected; client.Connected += ClientOnConnected; client.ErrorMessageReceived += ClientOnErrorMessageReceived; client.MotdReceived += ClientOnMotdReceived; client.RawMessageReceived += ClientOnRawMessageReceived; client.ChannelListReceived += ClientOnChannelListReceived; client.ProtocolError += ClientOnProtocolError; while (!closingTime) { Thread.Sleep(10); } }
public void Connect(Server server) { IsConnecting = true; var userInfo = new IrcUserRegistrationInfo { NickName = server.UserProfile.Nickname, RealName = server.UserProfile.Nickname, UserName = server.UserProfile.Nickname }; if (server.Port <= 0) { base.Connect(server.Address, server.SslEnabled, userInfo); } else { base.Connect(server.Address, server.Port, server.SslEnabled, userInfo); } CurrentServer = server; }
private void ConnectMethod(string commandstring) { var userdata = Class1.GetModData(); IrcUserRegistrationInfo myreg; if (commandstring == "#/connect default") { myclient = new StandardIrcClient(); setup_events(); setup_settings(); var server = userdata[3].Split(':'); myreg = new IrcUserRegistrationInfo() { NickName = userdata[2], UserName = userdata[0], RealName = userdata[1] }; myclient.Connect(server[0], int.Parse((Il2CppSystem.String)server[1]), bool.Parse(server[2]), myreg); return; } if (!commandstring.StartsWith("#/connect")) { return; } var hostargs = commandstring.Replace("#/connect", "").Trim().Split(' '); myclient = new StandardIrcClient(); setup_events(); setup_settings(); myreg = new IrcUserRegistrationInfo() { NickName = userdata[2], UserName = userdata[0], RealName = userdata[1] }; myclient.Connect(hostargs[0], int.Parse((Il2CppSystem.String)hostargs[1]), false, myreg); }
private void ircClientConnect(string adress, int port, string nickname, string password) { IrcUserRegistrationInfo regInf = new IrcUserRegistrationInfo() { NickName = nickname, UserName = nickname, Password = password, RealName = nickname }; try { ircClient.Connect(adress, port, false, regInf); do { Thread.Sleep(1000); } while (!ircClient.IsConnected); } catch (Exception e) { Debug.Print("IrcClient Connection Exception: " + e.Message); } }
public void TestJoinChannel() { var client = new StandardIrcClient(); var registrationInfo = new IrcUserRegistrationInfo() { NickName = "cmpct_test", Password = "", UserName = "******", RealName = "cmpct_test" }; client.Connect("127.0.0.1", 6667, false, registrationInfo); using (var registrationEvent = new ManualResetEventSlim(false)) { // Need to include the registration check for the delay client.Registered += (sender, e) => registrationEvent.Set(); if (!registrationEvent.Wait(500)) { client.Dispose(); Assert.Fail("RegistrationEvent not called: not registered?"); } } using (var joinedChannelEvent = new ManualResetEventSlim(false)) { client.LocalUser.JoinedChannel += (sender, e) => joinedChannelEvent.Set(); client.Channels.Join("#test"); if (!joinedChannelEvent.Wait(500)) { client.Dispose(); Assert.Fail("JoinedChannelEvent not called: channel not joined?"); } } }
private void ConnectBtn_Click(object sender, EventArgs e) { if (client.IsConnected) { client.Disconnect(); ConnectBtn.Text = "Connect"; } else { Uri uri = new Uri(AddressTxb.Text); ConnectBtn.Text = "Connecting..."; IrcUserRegistrationInfo info = new IrcUserRegistrationInfo(); string username = UsernameTxb.Text; if (username.Length < 1) { username = "******" + RandomNumberGenerator.Create().ToString(); } info.NickName = username; info.RealName = username; info.UserName = username; info.Password = PasswordTxb.Text; client.Connect(uri, info); } }
public bool Connect(BotType target) { switch (target) { case BotType.Osu: { IrcUserRegistrationInfo reg = new IrcUserRegistrationInfo() { NickName = m_credentials.OsuCredentials.Username, UserName = m_credentials.OsuCredentials.Username, RealName = m_credentials.OsuCredentials.Username, Password = m_credentials.OsuCredentials.Password, }; try { m_osuClient = new StandardIrcClient(); m_osuClient.Connected += (o, e) => { Console.WriteLine("Connected to irc.ppy.sh"); }; m_osuClient.ConnectFailed += (o, e) => { Console.WriteLine("Failed connecting to irc.ppy.sh"); }; Console.WriteLine("Connecting to irc.ppy.sh..."); m_osuClient.RawMessageReceived += m_osuClient_RawMessageReceived; m_osuClient.Disconnected += (o, e) => { m_osuClient.Disconnect(); Console.WriteLine("Got disconnected from irc.ppy.sh, reconnecting..."); m_osuClient.Connect("irc.ppy.sh", 6667, false, reg); }; m_osuClient.Connect("irc.ppy.sh", 6667, false, reg); m_osuClient.SendRawMessage($"PASS {m_credentials.OsuCredentials.Password}\r\n"); m_osuClient.SendRawMessage($"NICK {m_credentials.OsuCredentials.Username}\r\n"); return(true); } catch (Exception e) { Console.WriteLine($"Something happened while trying to connect to irc.ppy.sh, {e.Message}"); return(false); } } case BotType.Twitch: { { IrcUserRegistrationInfo reg = new IrcUserRegistrationInfo() { NickName = m_credentials.TwitchCredentials.Username, UserName = m_credentials.TwitchCredentials.Username, RealName = m_credentials.TwitchCredentials.Username, Password = m_credentials.TwitchCredentials.Password }; try { m_twitchClient = new TwitchIrcClient(); m_twitchClient.Connected += (o, e) => { Console.WriteLine("Connected to irc.twitch.tv"); }; m_twitchClient.ConnectFailed += (o, e) => { Console.WriteLine("Failed connecting to irc.twitch.tv"); }; Console.WriteLine("Connecting to irc.twitch.tv..."); m_twitchClient.RawMessageReceived += m_twitchClient_RawMessageReceived; m_twitchClient.Disconnected += (o, e) => { Console.WriteLine("Got disconnected from irc.twitch.tv, reconnecting..."); m_twitchClient.Connect("irc.twitch.tv", 6667, false, reg); }; m_twitchClient.Connect("irc.twitch.tv", 6667, false, reg); return(true); } catch (Exception e) { Console.WriteLine($"Something happened while trying to connect to irc.twitch.tv, {e.Message}"); return(false); } } } default: return(false); // wat } }
public override void Join(Action <IChatChannel> callback, string channel) { ircClient = new IrcClient(); var safeConnectDelay = Chat.ChatChannels.Count * 100; Thread.Sleep(safeConnectDelay); ChannelName = "#" + channel.Replace("#", ""); pingTimer = new Timer((sender) => { TryIrc(() => ircClient.Ping()); (sender as TwitchChannel).disconnectTimer.Change(10000, Timeout.Infinite); }, this, Timeout.Infinite, Timeout.Infinite); disconnectTimer = new Timer((sender) => { Log.WriteError("{0} ping timeout", Chat.ChatName); TryIrc(() => Leave()); }, this, Timeout.Infinite, Timeout.Infinite); SetupStatsWatcher(); using (WebClientBase webClient = new WebClientBase()) { var badgesJson = this.With(x => webClient.Download(String.Format(@"https://api.twitch.tv/kraken/chat/{0}/badges", ChannelName.Replace("#", "")))) .With(x => JsonConvert.DeserializeObject <TwitchBadges>(x)); if (badgesJson != null) { channelBadges["admin"] = this.With(x => badgesJson.admin).With(x => x.image); channelBadges["broadcaster"] = this.With(x => badgesJson.broadcaster).With(x => x.image); channelBadges["mod"] = this.With(x => badgesJson.mod).With(x => x.image); channelBadges["staff"] = this.With(x => badgesJson.staff).With(x => x.image); channelBadges["turbo"] = this.With(x => badgesJson.turbo).With(x => x.image); channelBadges["subscriber"] = this.With(x => badgesJson.subscriber).With(x => x.image); } } SetUserBadge(ChannelName.ToLower().Replace("#", ""), "broadcaster"); JoinCallback = callback; var nickname = Chat.IsAnonymous ? (Chat as ChatBase).AnonymousNickName : Chat.NickName; var registrationInfo = new IrcUserRegistrationInfo() { UserName = nickname, NickName = nickname, RealName = nickname, Password = Chat.IsAnonymous ? "blah" : "oauth:" + Chat.Config.GetParameterValue("OAuthToken") as string, }; var host = Chat.Config.GetParameterValue("Host") as string; var portText = Chat.Config.GetParameterValue("Port") as string; int port = 6667; int.TryParse(portText, out port); if (TryIrc(() => { ircClient.Initialize(); ircClient.Disconnected += ircClient_Disconnected; ircClient.RawMessageReceived += ircClient_RawMessageReceived; ircClient.PongReceived += ircClient_PongReceived; if (Regex.IsMatch(host, @"\d+\.\d+\.\d+\.\d+")) { ircClient.Connect(host, port, false, registrationInfo); } else { Utils.Net.TestTCPPort(host, port, (hostList, error) => { if (hostList == null || hostList.AddressList.Count() <= 0) { Log.WriteError("All servers are down. Domain:" + host); Leave(); } else { ircClient.Connect(hostList.AddressList[random.Next(0, hostList.AddressList.Count())], port, false, registrationInfo); } }); } }) != null) { Leave(); } }
private void CreateRegistrationInfo() { this.RegistrationInfo = new IrcUserRegistrationInfo { NickName = this.network.Identity.NickName, Password = this.network.Identity.Password, RealName = this.network.Identity.RealName, UserName = this.network.Identity.UserName }; }
void Run() { Client = new StandardIrcClient(); DrawCommandLine(); var Info = new IrcUserRegistrationInfo(); Info.NickName = Settings.Default.Name; Info.RealName = Settings.Default.Realname; Info.UserName = Settings.Default.Realname + "Bot"; using (var connectedEvent = new ManualResetEventSlim(false)) { Client.Connected += (sender2, e2) => connectedEvent.Set(); Client.Connect(new Uri(Settings.Default.Server), Info); if (!connectedEvent.Wait(10000)) { Client.Dispose(); PrintLine(string.Format("Connection to {0} timed out.", Settings.Default.Server), ConsoleColor.Red); return; } PrintLine(string.Format("Connected to {0}", Settings.Default.Server)); // *** POST-INIT Client.MotdReceived += delegate(Object Sender, EventArgs E) { PrintLine("Joining Channels..."); Client.Channels.Join(Settings.Default.Channel); }; // *** DEBUG OUTPUT Client.RawMessageReceived += delegate(Object Sender, IrcRawMessageEventArgs Event) { PrintLine(Event.RawContent); }; // *** PING Client.PingReceived += delegate(Object Sender, IrcPingOrPongReceivedEventArgs Event) { Client.Ping(Event.Server); }; // *** CHANNEL JOINING Client.LocalUser.JoinedChannel += delegate(Object Sender, IrcChannelEventArgs Event) { Event.Channel.MessageReceived += Channel_MessageReceived; SayInChannel(OnJoinActions); }; // *** REJOIN AFTER KICK Client.LocalUser.LeftChannel += delegate(Object Sender, IrcChannelEventArgs Event) { Client.Channels.Join(Event.Channel.Name); }; Int32 Counter = 0; while (Client.IsConnected) { Thread.Sleep(5); if (DCTimer > 0) { DCTimer--; if (DCTimer == 0) { Client.Disconnect(); } } if (++Counter == 12000) { PrintLine("Manual Ping"); Client.Ping(); Counter = 0; } while (Console.KeyAvailable) { Console.SetCursorPosition(0, 0); ConsoleKeyInfo Key = Console.ReadKey(true); switch (Key.Key) { case ConsoleKey.Enter: ConsoleCommand(); CommandLine = ""; break; case ConsoleKey.Backspace: if (CommandLine.Length > 0) { CommandLine = CommandLine.Substring(0, CommandLine.Length - 1); } break; default: CommandLine = CommandLine + Key.KeyChar; break; } DrawCommandLine(); } } } DrawCommandLine(); }
static void Main(string[] args) { SetConsoleCtrlHandler(cancelHandler, true); pConfigManager Config = new pConfigManager(@"IRC.cfg", true) { WriteOnChange = true }; Config.LoadConfig(@"IRC.cfg", true); string IRCAddress = Config.GetValue("IRCAddress", "irc.ppy.sh"); string IRCUsername = Config.GetValue("IRCUsername", "lslqtz"); string IRCPassword = Config.GetValue("IRCPassword", ""); int IRCConnectTimeout = Config.GetValue("IRCConnectTimeout", 10000); IRCChannels = Config.GetValue("Channels", "#osu").Split(','); Init(); //Database.ConnectionString = Config.GetValue("ConnectionString", Database.ConnectionString); IrcUserRegistrationInfo IRCUserRegistrationInfo = new IrcUserRegistrationInfo() { NickName = IRCUsername, UserName = IRCUsername, Password = IRCPassword }; IRCClient = new StandardIrcClient(); IRCClient.Registered += OnRegistered; IRCClient.Connected += OnConnected; IRCClient.ProtocolError += OnProtocolError; IRCClient.RawMessageSent += OnSentRawMessage; IRCClient.RawMessageReceived += OnReceivedRawMessage; using (var connectedEvent = new ManualResetEventSlim(false)) { IRCClient.Connected += (s, e) => connectedEvent.Set(); IRCClient.Connect(IRCAddress, false, IRCUserRegistrationInfo); if (!connectedEvent.Wait(IRCConnectTimeout)) { Console.WriteLine("Connection timed out."); Console.ReadKey(true); } while (true) { string str = ""; ConsoleKeyInfo NewKey = Console.ReadKey(true); while (NewKey.Key != ConsoleKey.Enter) { if (NewKey.Key == ConsoleKey.Backspace) { if (str.Length > 0) { str = str.Remove(str.Length - 1); } } else { str += NewKey.KeyChar; } InitTitle(((!string.IsNullOrEmpty(str)) ? string.Format("Current Content: {0}", str) : null)); NewKey = Console.ReadKey(true); } InitTitle(); string[] NewLine = str.Split(':'); if (NewLine.Length > 1) { string target = NewLine[0]; string text = string.Join(" ", NewLine, 1, NewLine.Length - 1); SendMessage(target, text); } str = ""; } } }