Ejemplo n.º 1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     spamcount = 0;
     loadIRCInfo();
     Thread configGreet = new Thread(GreetConfig);
     configGreet.Start();
     Thread configFarewell = new Thread(FarewellConfig);
     configFarewell.Start();
     if (System.IO.File.Exists("users.bin") == false | System.IO.File.Exists("passwords.bin") == false | System.IO.File.Exists("registers.bin") == false | System.IO.File.Exists(".activeusers") == false)
     {
         Thread configUser = new Thread(startUserList);
         configUser.Start();
     }
     if (System.IO.File.Exists("log.bin") == false)
     {
         StreamWriter swlog = new StreamWriter("log.bin");
         swlog.Close();
     }
     StreamWriter sw = new StreamWriter(".activeusers");
     sw.Close();
     if (System.IO.File.Exists("owner.bin") == false)
     {
         ownerConfiguration();
     }
     if (System.IO.File.Exists("blacklist.bin") == false)
     {
         StreamWriter swbl = new StreamWriter("blacklist.bin");
         swbl.Close();
     }
     isLogging = false;
     ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
     ObsidFunc.settalkingTo("nobody");
     updatetmr = new System.Timers.Timer(300);
     updatetmr.Elapsed += new System.Timers.ElapsedEventHandler(updateTmrWork);
     updatetmr.Interval = 300;
     canGreet = false;
     if (System.IO.File.Exists("messages.bin") == false)
     {
         StreamWriter swmg = new StreamWriter("messages.bin");
         swmg.Write("|");
         swmg.Close();
     }
     configHashSet();
 }
Ejemplo n.º 2
0
        public string recv()
        {
            byte[] data = new byte[2048];
            sock.Receive(data, 2048, System.Net.Sockets.SocketFlags.None);
            mail = System.Text.ASCIIEncoding.UTF8.GetString(data).Replace("\0", "");
            if (mail.Contains(" "))
            {
                if (mail.Substring(0, 4) == "PING")
                {
                    string pserv = mail.Substring(mail.IndexOf(":"), mail.Length - mail.IndexOf(":"));
                    pserv = pserv.TrimEnd((char)0);
                    mail = "PING from " + pserv + "\r" + "PONG to " + pserv;
                    send("PONG " + pserv);
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 7) == "PRIVMSG")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    rnick = tmparr[0];
                    tmparr = mail.Split(':');
                    rmsg = tmparr[1].Trim() ;
                    string sayingto = Regex.Split(mail, "PRIVMSG ")[1].Split(':')[0].Substring(0, Regex.Split(mail, "PRIVMSG ")[1].Split(':')[0].Length - 1);
                    string commandName;
                    if (rmsg.Contains(" "))
                    {
                        commandName = rmsg.Substring(0, rmsg.IndexOf(' '));
                    }
                    else
                    {
                        commandName = rmsg;
                    }
                    bool nickblacklisted = isBlacklisted(rnick);
                    ObsidianFunctions.Functions ObsidBot = new ObsidianFunctions.Functions();
                    //MessageBox.Show("privmsg");
                    if (nickblacklisted == false)
                    {
                        foreach (string command in executableCommands)
                        {
                            if (commandName == "!" + command)
                            {
                                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                                send(ObsidFunc.exeExec(command + ".exe", channel, rnick, rmsg));
                            }
                        }
                        foreach (string command in jarCommands)
                        {
                            if (commandName == "!" + command.Replace(".jar", ""))
                            {
                                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                                send(ObsidFunc.jarExec(command, channel, rnick, rmsg));
                            }
                        }
                        foreach (string command in classCommands)
                        {
                            if (rmsg.StartsWith("!" + command))
                            {
                                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                                send(ObsidFunc.classExec(command, channel, rnick, rmsg));
                            }
                        }
                        foreach (string command in compileCommands)
                        {
                            if (commandName == "!" + command.Replace(".cs", ""))
                            {
                                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                                send(ObsidFunc.CSCompileRun(command, channel, rnick, rmsg));
                                configHashSet();
                            }
                        }
                        foreach (string command in javaCommands)
                        {
                            if (commandName == "!" + command.Replace(".java", ""))
                            {
                                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                                send(ObsidFunc.JavaCompileRun(command, channel, rnick, rmsg));
                                configHashSet();
                            }
                        }
                        //add AIML
                        if (sayingto == nick && rnick != nick && rmsg.StartsWith("!") == false)
                        {
                            ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                            send(ObsidFunc.exeExec("botchat.exe", channel, rnick, rmsg));
                        }
                    }

                    if (ObsidBot.controlSpam() == true)
                    {
                        if (rmsg == oldmsg)
                        {
                            increaseSpamCount();
                            if (spamcount >= 4)
                            {
                                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                                if (ObsidFunc.isOperator() == true)
                                {
                                    send("KICK " + channel + " " + rnick + " No Spamming or Repeating one's self");
                                    spamcount = 0;
                                }
                                else
                                {
                                    send("PRIVMSG " + channel + " :Try not to spam or excessively repeat yourself");
                                    spamcount = 0;
                                }
                            }

                        }
                    }

                    ObsidianFunctions.Functions Obsid = new ObsidianFunctions.Functions();
                    if (Obsid.isLogging() == true)
                    {
                        logMsg();
                    }
                    detectLang();
                    bool newMessages = Obsid.hasMessages(rnick);
                    if (newMessages == true)
                    {
                        Obsid.sayMessages(rnick);
                    }
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "JOIN")
                {

                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    rnick = tmparr[0];
                    FervorLibrary.Library Greetings = new FervorLibrary.Library();
                    if (Greetings.canGreet() == true)
                    {

                        Random rand = new Random();
                        int indexgreet = rand.Next(0, Greetings.greetnumber());
                        say(nick, "!greet " + indexgreet.ToString());
                    }
                    ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                    bool newMessages = ObsidFunc.hasMessages(rnick);
                    if (newMessages == true)
                    {
                        say(rnick, "!You have messages");
                        string[] usermessages = ObsidFunc.sayMessages(rnick);
                        foreach (string x in usermessages)
                        {
                            send(x);
                        }
                    }
                    say(nick, "!names");
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "PART" || mail.Substring(mail.IndexOf(" ") + 1, 4) == "QUIT")
                {
                    ObsidianFunctions.Functions ObsidBot = new ObsidianFunctions.Functions();
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    rnick = tmparr[0];
                    FervorLibrary.Library FervLib = new FervorLibrary.Library();
                    if (FervLib.canGreet() == true)
                    {

                        Random rand = new Random();

                        int indexfarewell = rand.Next(0, FervLib.farewellnumber());
                        say(nick, "!farewell " + indexfarewell.ToString());
                    }
                    ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                    say(rnick, ObsidFunc.deactivate(rnick, rmsg));
                    if (rnick == ObsidBot.talkingTo())
                    {
                        ObsidBot.settalkingTo("nobody");
                    }
                    say(nick, "!names");
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "MODE")
                {
                    mail = mail.Replace("\0", "").Trim();
                    int nameopslength = nick.Length + 3;
                    string action = mail.Substring(mail.Length - nameopslength);
                    if (action.StartsWith("+o") | action.StartsWith("+r") | action.StartsWith("+h"))
                    {
                        ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                        ObsidFunc.opTrue();
                        send("PRIVMSG " + channel + " :isOperator = true");

                    }
                    else if (action.StartsWith("-o") | action.StartsWith("-r") | action.StartsWith("-h"))
                    {
                        ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                        ObsidFunc.opFalse();
                        send("PRIVMSG " + channel + " :isOperator = false");
                    }

                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "KICK")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    rnick = tmparr[0];
                    tmparr = mail.Split(':');
                    rmsg = tmparr[1];
                    ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                    say(rnick, ObsidFunc.deactivate(rnick, rmsg)) ;
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 3) == "353")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split(':');
                    rmsg = tmparr[1];
                    ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                    say(nick, ObsidFunc.setNames(rmsg));
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "NICK")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    rnick = tmparr[0];
                    tmparr = mail.Split(':');
                    string newnick = tmparr[1];
                    ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                    say(rnick, ObsidFunc.deactivate(rnick, rmsg));
                    bool newMessages = ObsidFunc.hasMessages(newnick);
                    if (newMessages == true)
                    {
                        ObsidFunc.sayMessages(newnick);
                    }
                }
            }
            oldMsg();
            return mail;
        }