public string mainLoop(int startTime) { Information information = new Information(); ChannelActions ChanActs = new ChannelActions(); ChanModes mode = new ChanModes(); Loader load = new Loader(); CTCP ctcp = new CTCP(); UserControl users = new UserControl(); httpRegex = new Regex(@"(?:http://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)?)|(?:ftp://(?:(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])*)(?::(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])*))?@)?(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?))(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[?:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[?:@&=])*))*)))"); try { ThreadStart userThreadStart = new ThreadStart(users.userControl); Thread userThread = new Thread(userThreadStart); userThread.Start(); } catch (Exception e) { Console.WriteLine(e.ToString()); } while (true) { while ((inputLine = reader.ReadLine()) != null) { Console.WriteLine(inputLine); if (inputLine.IndexOf("376") >= 0) //End of MOTD { writer.WriteLine("JOIN " + channel); writer.Flush(); } else break; while ((inputLine = reader.ReadLine()) != null) { Console.WriteLine(inputLine); if (ctcp.isCTCP()) ctcp.processCTCPType(); else if (inputLine == ("PING :" + server)) { writer.WriteLine("PONG " + server); writer.Flush(); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": op me") >= 0 && information.sender() == owner) { mode.setMode("+o", owner); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": op") >= 0) { string realSender = information.sender(); string realMsg = information.msg(); information.sendNamesToSrv(); inputLine = reader.ReadLine(); if (information.isOped(realSender) || information.sender() == owner && information.senderHost() == ownerhost) mode.setMode("+o", realMsg.Substring(nick.Length + 5)); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": voice me") >= 0 || inputLine.ToLower().IndexOf(nick.ToLower() + ": voice ") >= 0) { mode.setMode("+v", information.sender()); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": uptime") >= 0) { Uptime uptime = new Uptime(); uptime.uptime(startTime); } else if (inputLine.IndexOf("PART " + channel) >= 0) { users.userPart(); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": die") >= 0 && information.sender() == owner) { writer.WriteLine("QUIT :My master killed me"); writer.Flush(); cleanup(); return "ok"; } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": topic") >=0 && information.sender() == owner) { mode.setTopic(); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": !load") >= 0 && information.sender() == owner) { load.createAD("load"); } else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": !unload") >= 0 && information.sender() == owner) { load.createAD("unload"); } else if (Regex.IsMatch(inputLine, httpRegex.ToString()) && information.sender() != nick) { HttpHeader hh = new HttpHeader(); ThreadStart thStart = new ThreadStart(hh.processHeader); Thread th = new Thread(thStart); th.Start(); } if (inputLine.StartsWith("ERROR")) { Console.WriteLine(inputLine); return "error"; } } } } }
public void uptime(int startTime) { ChannelActions chanact = new ChannelActions(); DateTime now = DateTime.Now.ToUniversalTime(); System.TimeSpan span = new System.TimeSpan(System.DateTime.Parse("1/1/1970").Ticks); System.DateTime time = now.Subtract(span); long upTimesec = (int)(time.Ticks / 10000000) - startTime; TimeSpan ts = new TimeSpan(0, 0, (int) upTimesec); int days = (int) ts.TotalDays; int hours = (int) ts.TotalHours; int minutes = (int)ts.TotalMinutes; int seconds = (int)ts.TotalSeconds; chanact.sayn("I have been up for "); if (days >= 1) chanact.contSay(days + " days, "); if (hours >= 1 && hours <= 60) chanact.contSay(hours + " hours, "); else if(hours > 60) chanact.contSay(hours - days * 60 + " hour and "); if (minutes >= 1 && minutes <= 60) chanact.contSay(minutes + " minutes and "); else if(minutes > 60) chanact.contSay(minutes - hours*60 + " minutes and "); if(seconds <= 60) chanact.contSay(seconds + " seconds\n"); else if(seconds > 60) chanact.contSay(seconds - minutes*60 + " seconds\n"); }
public void processHeader() { IrcBot bot = new IrcBot(); Information info = new Information(); try { string[] httpInput = Regex.Split(inputLine, httpRegex.ToString(), RegexOptions.IgnoreCase); string[] input = info.msg().Split(' '); foreach (string text in input) if (Regex.IsMatch(text, httpRegex.ToString())) { WebClient web = new WebClient(); byte[] bInHttpStream = web.DownloadData(text); string inHttpString = Encoding.Default.GetString(bInHttpStream).Trim(); string[] data1 = Regex.Split(inHttpString.Trim(), "<title>|<TITLE>"); string[] titleContent = Regex.Split(data1[1].Trim(), "</title>|</TITLE>"); ChannelActions chanAct = new ChannelActions(); chanAct.say("[" + titleContent[0].Replace('\n',' ') + "]"); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }