Advertisement
atillabyte

HoneyBot.5

Apr 28th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using PlayerIOClient;
  6. using System.Timers;
  7. using System.Net;
  8. using System.Text.RegularExpressions;
  9. using System.IO;
  10. using System.Collections;
  11. using System.Diagnostics;
  12.  
  13. namespace HoneyBot
  14. {
  15.     class Program
  16.     {
  17.         public static IniFile ini = new IniFile();
  18.         public static Connection con;
  19.  
  20.         public static Boolean detect_kick = false;
  21.         public static string owner;
  22.  
  23.         static Dictionary<int, string> ID2Username = new Dictionary<int, string>();
  24.         static Dictionary<string, int> Username2ID = new Dictionary<string, int>();
  25.  
  26.         static Dictionary<int, Analysis> ID2Analysis = new Dictionary<int, Analysis>();
  27.  
  28.         public class Analysis { public uint FaceChanges = 0; public uint CrownChanges = 0; }
  29.  
  30.         public static void Tick(object a, object b)
  31.         {
  32.             foreach (KeyValuePair<int, Analysis> x in ID2Analysis)
  33.             {
  34.                 try
  35.                 {
  36.                     if (x.Value.FaceChanges >= 10 || x.Value.CrownChanges >= 10)
  37.                     {
  38.                         Console.WriteLine("Detected: " + ID2Username[x.Key]);
  39.  
  40.                         if (ID2Username[x.Key].ToLower() != owner)
  41.                         {
  42.                             if (detect_kick) con.Send("say", "/kick " + ID2Username[x.Key]);
  43.  
  44.                             con.Send("say", "[HoneyBot] Detected: " + ID2Username[x.Key]);
  45.                         }
  46.                     }
  47.                     x.Value.FaceChanges = 0;
  48.                 }
  49.                 catch { }
  50.             }
  51.         }
  52.  
  53.         public static void Tick2(object a, object b)
  54.         {
  55.             try
  56.             {
  57.                 using (WebClient wb = new WebClient())
  58.                 {
  59.                     wb.Proxy = null;
  60.                     foreach (string user in wb.DownloadString("http://atil.la/public_projects/HoneyBot/bad.lst?v=5").Split(','))
  61.                     {
  62.                         if (!BadPeople.Contains(user))
  63.                             BadPeople.Add(user);
  64.                     }
  65.                 }
  66.             }
  67.             catch { }
  68.         }
  69.  
  70.  
  71.         public static List<string> BadPeople = new List<string>();
  72.  
  73.         static void Main(string[] args)
  74.         {
  75.             Console.Title = "HoneyBot - Anti-Crash";
  76.  
  77.             Console.Write("Retrieving Blacklist...");
  78.             using (WebClient wb = new WebClient())
  79.             {
  80.                 wb.Proxy = null;
  81.                 foreach (string user in wb.DownloadString("http://atil.la/public_projects/HoneyBot/bad.lst").Split(','))
  82.                 {
  83.                     BadPeople.Add(user);
  84.                 }
  85.             }
  86.             Console.WriteLine("Done.");
  87.  
  88.             ini.Load("settings.ini");
  89.  
  90.             string username = ini.GetKeyValue("Login", "Email");
  91.             string password = ini.GetKeyValue("Login", "Password");
  92.             string room = ini.GetKeyValue("Login", "RoomID");
  93.  
  94.             string AuthType = ini.GetKeyValue("Advanced", "AUTH");
  95.  
  96.             try
  97.             { detect_kick = bool.Parse(ini.GetKeyValue("Advanced", "DetectKick")); }
  98.             catch { }
  99.  
  100.             Client c = null;
  101.  
  102.  
  103.             if (AuthType.ToUpper() == "NORMAL")
  104.                 c = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", username, password);
  105.             else if (AuthType.ToUpper() == "KONG")
  106.                 c = PlayerIO.QuickConnect.KongregateConnect("everybody-edits-su9rn58o40itdbnw69plyw", username, password);
  107.             else if (AuthType.ToUpper() == "FB")
  108.                 c = PlayerIO.QuickConnect.FacebookOAuthConnect("everybody-edits-su9rn58o40itdbnw69plyw", password, "");
  109.  
  110.             con = c.Multiplayer.CreateJoinRoom(room, "Everybodyedits176", true, null, null);
  111.  
  112.             Timer timer = new Timer(2500);
  113.             timer.AutoReset = true;
  114.             timer.Enabled = true;
  115.             timer.Elapsed += Tick;
  116.  
  117.             Timer timer2 = new Timer(120000);
  118.             timer2.AutoReset = true;
  119.             timer2.Enabled = true;
  120.             timer2.Elapsed += Tick2;
  121.  
  122.             con.OnMessage += delegate(object s, Message e)
  123.             {
  124.                 switch (e.Type)
  125.                 {
  126.                     case "face":
  127.                         if (ID2Analysis.ContainsKey((int)e[0]))
  128.                             ID2Analysis[(int)e[0]].FaceChanges++;
  129.                         break;
  130.  
  131.                     case "k":
  132.                         if (ID2Analysis.ContainsKey((int)e[0]))
  133.                             ID2Analysis[(int)e[0]].CrownChanges++;
  134.                         break;
  135.                     case "add":
  136.  
  137.                         if (e.Count >= 11)
  138.                             if ((int)e[11] <= 2) con.Send("say", "/kick " + (string)e[1] + " " + "[HoneyBot] You are below level 3.");
  139.  
  140.                         if (BadPeople.Contains((string)e[1])) con.Send("say", "/kick " + (string)e[1] + " " + "[HoneyBot] You are banned.");
  141.  
  142.                         if (ID2Username.ContainsKey((int)e[0])) ID2Username[(int)e[0]] = (string)e[1];
  143.                         else
  144.                             ID2Username.Add((int)e[0], (string)e[1]);
  145.  
  146.                         if (Username2ID.ContainsKey((string)e[1])) Username2ID[(string)e[1]] = (int)e[0];
  147.                         else
  148.                             Username2ID.Add((string)e[1], (int)e[0]);
  149.  
  150.                         if (!ID2Analysis.ContainsKey((int)e[0]))
  151.                             ID2Analysis.Add((int)e[0], new Analysis());
  152.  
  153.                         break;
  154.  
  155.                     case "init":
  156.                         System.Threading.Thread.Sleep(1000);
  157.                         Console.WriteLine("Connected to: {0}", room);
  158.                         owner = (string)e[0];
  159.                         con.Send("say", "[HoneyBot] Initalized.");
  160.                         break;
  161.                 }
  162.             };
  163.             con.OnDisconnect += delegate(object a, string b)
  164.             {
  165.                 Console.WriteLine("[HoneyBot] Disconnected. [TIME: " + DateTime.Now + "]");
  166.                 Main(new string[] { });
  167.             };
  168.             con.Send("init"); con.Send("init2");
  169.             Console.ReadLine();
  170.         }
  171.     }
  172.     public class IniFile
  173.     {
  174.         private Hashtable m_sections;
  175.  
  176.         public IniFile()
  177.         {
  178.             m_sections = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
  179.         }
  180.  
  181.         public void Load(string sFileName)
  182.         {
  183.             Load(sFileName, false);
  184.         }
  185.  
  186.         public void Load(string sFileName, bool bMerge)
  187.         {
  188.             if (!bMerge)
  189.             {
  190.                 RemoveAllSections();
  191.             }
  192.             IniSection tempsection = null;
  193.             StreamReader oReader = new StreamReader(sFileName);
  194.             Regex regexcomment = new Regex("^([\\s]*#.*)", (RegexOptions.Singleline | RegexOptions.IgnoreCase));
  195.             Regex regexsection = new Regex("^[\\s]*\\[[\\s]*([^\\[\\s].*[^\\s\\]])[\\s]*\\][\\s]*$", (RegexOptions.Singleline | RegexOptions.IgnoreCase));
  196.             Regex regexkey = new Regex("^\\s*([^=\\s]*)[^=]*=(.*)", (RegexOptions.Singleline | RegexOptions.IgnoreCase));
  197.             while (!oReader.EndOfStream)
  198.             {
  199.                 string line = oReader.ReadLine();
  200.                 if (line != string.Empty)
  201.                 {
  202.                     Match m = null;
  203.                     if (regexcomment.Match(line).Success)
  204.                     {
  205.                         m = regexcomment.Match(line);
  206.                         Trace.WriteLine(string.Format("Skipping Comment: {0}", m.Groups[0].Value));
  207.                     }
  208.                     else if (regexsection.Match(line).Success)
  209.                     {
  210.                         m = regexsection.Match(line);
  211.                         Trace.WriteLine(string.Format("Adding section [{0}]", m.Groups[1].Value));
  212.                         tempsection = AddSection(m.Groups[1].Value);
  213.                     }
  214.                     else if (regexkey.Match(line).Success && tempsection != null)
  215.                     {
  216.                         m = regexkey.Match(line);
  217.                         Trace.WriteLine(string.Format("Adding Key [{0}]=[{1}]", m.Groups[1].Value, m.Groups[2].Value));
  218.                         tempsection.AddKey(m.Groups[1].Value).Value = m.Groups[2].Value;
  219.                     }
  220.                     else if (tempsection != null)
  221.                     {
  222.                         Trace.WriteLine(string.Format("Adding Key [{0}]", line));
  223.                         tempsection.AddKey(line);
  224.                     }
  225.                     else
  226.                     {
  227.                         Trace.WriteLine(string.Format("Skipping unknown type of data: {0}", line));
  228.                     }
  229.                 }
  230.             }
  231.             oReader.Close();
  232.         }
  233.  
  234.         public void Save(string sFileName)
  235.         {
  236.             StreamWriter oWriter = new StreamWriter(sFileName, false);
  237.             foreach (IniSection s in Sections)
  238.             {
  239.                 Trace.WriteLine(string.Format("Writing Section: [{0}]", s.Name));
  240.                 oWriter.WriteLine(string.Format("[{0}]", s.Name));
  241.                 foreach (IniSection.IniKey k in s.Keys)
  242.                 {
  243.                     if (k.Value != string.Empty)
  244.                     {
  245.                         Trace.WriteLine(string.Format("Writing Key: {0}={1}", k.Name, k.Value));
  246.                         oWriter.WriteLine(string.Format("{0}={1}", k.Name, k.Value));
  247.                     }
  248.                     else
  249.                     {
  250.                         Trace.WriteLine(string.Format("Writing Key: {0}", k.Name));
  251.                         oWriter.WriteLine(string.Format("{0}", k.Name));
  252.                     }
  253.                 }
  254.             }
  255.             oWriter.Close();
  256.         }
  257.  
  258.         public System.Collections.ICollection Sections
  259.         {
  260.             get
  261.             {
  262.                 return m_sections.Values;
  263.             }
  264.         }
  265.  
  266.         public IniSection AddSection(string sSection)
  267.         {
  268.             IniSection s = null;
  269.             sSection = sSection.Trim();
  270.  
  271.             if (m_sections.ContainsKey(sSection))
  272.             {
  273.                 s = (IniSection)m_sections[sSection];
  274.             }
  275.             else
  276.             {
  277.                 s = new IniSection(this, sSection);
  278.                 m_sections[sSection] = s;
  279.             }
  280.             return s;
  281.         }
  282.  
  283.         public bool RemoveSection(string sSection)
  284.         {
  285.             sSection = sSection.Trim();
  286.             return RemoveSection(GetSection(sSection));
  287.         }
  288.  
  289.         public bool RemoveSection(IniSection Section)
  290.         {
  291.             if (Section != null)
  292.             {
  293.                 try
  294.                 {
  295.                     m_sections.Remove(Section.Name);
  296.                     return true;
  297.                 }
  298.                 catch (Exception ex)
  299.                 {
  300.                     Trace.WriteLine(ex.Message);
  301.                 }
  302.             }
  303.             return false;
  304.         }
  305.  
  306.         public bool RemoveAllSections()
  307.         {
  308.             m_sections.Clear();
  309.             return (m_sections.Count == 0);
  310.         }
  311.  
  312.         public IniSection GetSection(string sSection)
  313.         {
  314.             sSection = sSection.Trim();
  315.  
  316.             if (m_sections.ContainsKey(sSection))
  317.             {
  318.                 return (IniSection)m_sections[sSection];
  319.             }
  320.             return null;
  321.         }
  322.  
  323.         public string GetKeyValue(string sSection, string sKey)
  324.         {
  325.             IniSection s = GetSection(sSection);
  326.             if (s != null)
  327.             {
  328.                 IniSection.IniKey k = s.GetKey(sKey);
  329.                 if (k != null)
  330.                 {
  331.                     return k.Value;
  332.                 }
  333.             }
  334.             return string.Empty;
  335.         }
  336.  
  337.         public bool SetKeyValue(string sSection, string sKey, string sValue)
  338.         {
  339.             IniSection s = AddSection(sSection);
  340.             if (s != null)
  341.             {
  342.                 IniSection.IniKey k = s.AddKey(sKey);
  343.                 if (k != null)
  344.                 {
  345.                     k.Value = sValue;
  346.                     return true;
  347.                 }
  348.             }
  349.             return false;
  350.         }
  351.  
  352.         public bool RenameSection(string sSection, string sNewSection)
  353.         {
  354.             bool bRval = false;
  355.             IniSection s = GetSection(sSection);
  356.             if (s != null)
  357.             {
  358.                 bRval = s.SetName(sNewSection);
  359.             }
  360.             return bRval;
  361.         }
  362.  
  363.         public bool RenameKey(string sSection, string sKey, string sNewKey)
  364.         {
  365.             IniSection s = GetSection(sSection);
  366.             if (s != null)
  367.             {
  368.                 IniSection.IniKey k = s.GetKey(sKey);
  369.                 if (k != null)
  370.                 {
  371.                     return k.SetName(sNewKey);
  372.                 }
  373.             }
  374.             return false;
  375.         }
  376.  
  377.         public class IniSection
  378.         {
  379.             private IniFile m_pIniFile;
  380.             private string m_sSection;
  381.             private Hashtable m_keys;
  382.  
  383.             protected internal IniSection(IniFile parent, string sSection)
  384.             {
  385.                 m_pIniFile = parent;
  386.                 m_sSection = sSection;
  387.                 m_keys = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
  388.             }
  389.  
  390.             public System.Collections.ICollection Keys
  391.             {
  392.                 get
  393.                 {
  394.                     return m_keys.Values;
  395.                 }
  396.             }
  397.  
  398.             public string Name
  399.             {
  400.                 get
  401.                 {
  402.                     return m_sSection;
  403.                 }
  404.             }
  405.  
  406.             public IniKey AddKey(string sKey)
  407.             {
  408.                 sKey = sKey.Trim();
  409.                 IniSection.IniKey k = null;
  410.                 if (sKey.Length != 0)
  411.                 {
  412.                     if (m_keys.ContainsKey(sKey))
  413.                     {
  414.                         k = (IniKey)m_keys[sKey];
  415.                     }
  416.                     else
  417.                     {
  418.                         k = new IniSection.IniKey(this, sKey);
  419.                         m_keys[sKey] = k;
  420.                     }
  421.                 }
  422.                 return k;
  423.             }
  424.  
  425.             public bool RemoveKey(string sKey)
  426.             {
  427.                 return RemoveKey(GetKey(sKey));
  428.             }
  429.  
  430.             public bool RemoveKey(IniKey Key)
  431.             {
  432.                 if (Key != null)
  433.                 {
  434.                     try
  435.                     {
  436.                         m_keys.Remove(Key.Name);
  437.                         return true;
  438.                     }
  439.                     catch (Exception ex)
  440.                     {
  441.                         Trace.WriteLine(ex.Message);
  442.                     }
  443.                 }
  444.                 return false;
  445.             }
  446.  
  447.             public bool RemoveAllKeys()
  448.             {
  449.                 m_keys.Clear();
  450.                 return (m_keys.Count == 0);
  451.             }
  452.  
  453.             public IniKey GetKey(string sKey)
  454.             {
  455.                 sKey = sKey.Trim();
  456.                 if (m_keys.ContainsKey(sKey))
  457.                 {
  458.                     return (IniKey)m_keys[sKey];
  459.                 }
  460.                 return null;
  461.             }
  462.  
  463.             public bool SetName(string sSection)
  464.             {
  465.                 sSection = sSection.Trim();
  466.                 if (sSection.Length != 0)
  467.                 {
  468.                     IniSection s = m_pIniFile.GetSection(sSection);
  469.                     if (s != this && s != null) return false;
  470.                     try
  471.                     {
  472.                         m_pIniFile.m_sections.Remove(m_sSection);
  473.                         m_pIniFile.m_sections[sSection] = this;
  474.                         m_sSection = sSection;
  475.                         return true;
  476.                     }
  477.                     catch (Exception ex)
  478.                     {
  479.                         Trace.WriteLine(ex.Message);
  480.                     }
  481.                 }
  482.                 return false;
  483.             }
  484.  
  485.             public string GetName()
  486.             {
  487.                 return m_sSection;
  488.             }
  489.  
  490.             public class IniKey
  491.             {
  492.                 private string m_sKey;
  493.                 private string m_sValue;
  494.                 private IniSection m_section;
  495.  
  496.                 protected internal IniKey(IniSection parent, string sKey)
  497.                 {
  498.                     m_section = parent;
  499.                     m_sKey = sKey;
  500.                 }
  501.  
  502.                 public string Name
  503.                 {
  504.                     get
  505.                     {
  506.                         return m_sKey;
  507.                     }
  508.                 }
  509.  
  510.                 public string Value
  511.                 {
  512.                     get
  513.                     {
  514.                         return m_sValue;
  515.                     }
  516.                     set
  517.                     {
  518.                         m_sValue = value;
  519.                     }
  520.                 }
  521.  
  522.                 public void SetValue(string sValue)
  523.                 {
  524.                     m_sValue = sValue;
  525.                 }
  526.                 public string GetValue()
  527.                 {
  528.                     return m_sValue;
  529.                 }
  530.  
  531.                 public bool SetName(string sKey)
  532.                 {
  533.                     sKey = sKey.Trim();
  534.                     if (sKey.Length != 0)
  535.                     {
  536.                         IniKey k = m_section.GetKey(sKey);
  537.                         if (k != this && k != null) return false;
  538.                         try
  539.                         {
  540.                             m_section.m_keys.Remove(m_sKey);
  541.                             m_section.m_keys[sKey] = this;
  542.                             m_sKey = sKey;
  543.                             return true;
  544.                         }
  545.                         catch (Exception ex)
  546.                         {
  547.                             Trace.WriteLine(ex.Message);
  548.                         }
  549.                     }
  550.                     return false;
  551.                 }
  552.  
  553.                 public string GetName()
  554.                 {
  555.                     return m_sKey;
  556.                 }
  557.             }
  558.         }
  559.     }
  560. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement