Advertisement
Fastmapler

EE Bot Script

May 16th, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PlayerIOClient;
  11.  
  12. namespace DBot
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.  
  17.         public static Connection conn;
  18.         public static Client client;
  19.         public static List<string> names = new List<string>();
  20.         public static Random ran = new Random();
  21.         public static Dictionary<int, string> users = new Dictionary<int, string>();
  22.  
  23.         public bool isConnected;
  24.         public bool Conntry;
  25.         public static string username;
  26.         public static string worldKey;
  27.         public static string rotWorldKey;
  28.  
  29.         public Form1()
  30.         {
  31.             InitializeComponent();
  32.         }
  33.  
  34.  
  35.  
  36.         private void ConnToggle_Click(object sender, EventArgs e)
  37.         {
  38.             Conntry = false;
  39.             if ((isConnected) && (!Conntry))
  40.             {
  41.                 Conntry = true;
  42.                 conn.Send("say", "[DBot] Disconnecting!");
  43.                 isConnected = false;
  44.                 conn.Disconnect();
  45.                 ConnToggle.Text = "Join!";
  46.             }
  47.  
  48.             if ((!isConnected) && (!Conntry))
  49.             {
  50.                 try
  51.                 {
  52.                     client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", UserInput.Text, PassInput.Text, null);
  53.                     conn = client.Multiplayer.JoinRoom(WldInput.Text, null);
  54.                     worldKey = CodeInput.Text;
  55.                     rotWorldKey = CodeInput.Text;
  56.                     rotWorldKey = Rot13.Derot(worldKey);
  57.                     //CodeInput.Text = worldKey;
  58.                     conn.OnMessage += OnMessage;
  59.                     conn.Send("init");
  60.                     Console.Read();
  61.                     isConnected = true;
  62.                     Conntry = true;
  63.                     System.Threading.Thread.Sleep(750);
  64.                     conn.Send("access", worldKey);
  65.                     System.Threading.Thread.Sleep(750);
  66.                     conn.Send("say", "[DBot V0.1] Connected!");
  67.                     ConnToggle.Text = "Leave!";
  68.                 }
  69.                 catch (PlayerIOError oops)
  70.                 {
  71.                     Console.Write(oops.Message);
  72.                     Console.Beep(500, 250);
  73.                 }
  74.                 catch (Exception oops2)
  75.                 {
  76.                     Console.Write(oops2.Message);
  77.                     Console.Beep(1000, 500);
  78.                     Console.Beep(750, 500);
  79.                 }
  80.             }
  81.         }
  82.  
  83.  
  84.  
  85.         static void OnMessage(object sender, PlayerIOClient.Message m)
  86.         {
  87.             if (m.Type == "init") conn.Send("init2");
  88.  
  89.             if (m.Type == "add")
  90.             {
  91.                 names.Add(m.GetString(1));
  92.                 users.Add(m.GetInt(0), m.GetString(1));
  93.                 System.Threading.Thread.Sleep(750);
  94.                 conn.Send("say", "/pm " + m.GetString(1) + " Use !help for help.");
  95.             }
  96.  
  97.             if (m.Type == "access")
  98.             {
  99.                 System.Threading.Thread.Sleep(2000);
  100.                 conn.Send("say", "[DBot V0.1] Code achived!");
  101.             }
  102.  
  103.  
  104.             if (m.Type == "say")
  105.             {
  106.                 if (users.ContainsKey(m.GetInt(0)))
  107.                 {
  108.                     string username = users[m.GetInt(0)];
  109.  
  110.                     if (m.GetString(1) == "!help")
  111.                     {
  112.                             conn.Send("say", "[DBot] This is WIP. More will come soon.");
  113.                     }
  114.  
  115.                     if (m.GetString(1) == "!bug")
  116.                     {
  117.                         conn.Send("say", "Hello, " + username + " likes to eat bugs.");
  118.                         System.Threading.Thread.Sleep(750);
  119.                         conn.Send(rotWorldKey, 0, 0, 0, 15);
  120.                     }
  121.                 }
  122.             }
  123.         }
  124.  
  125.     }
  126.  
  127.     public class Rot13
  128.     {
  129.         public static string Derot(string worldKey)
  130.         {
  131.             char[] array = worldKey.ToCharArray();
  132.  
  133.             for (int i = 0; i < array.Length; i++)
  134.             {
  135.                 int number = (int)array[i];
  136.  
  137.                 if (number >= 'a' && number <= 'z')
  138.                 {
  139.                     if (number > 'm')
  140.                         number -= 13;
  141.                     else
  142.                         number += 13;
  143.                 }
  144.                 else if (number >= 'A' && number <= 'Z')
  145.                 {
  146.                     if (number > 'M')
  147.                         number -= 13;
  148.                     else
  149.                         number += 13;
  150.                 }
  151.  
  152.                 array[i] = (char)number;
  153.             }
  154.  
  155.             return new string(array);
  156.         }
  157.     }
  158.     public static class InitParse //Processor
  159.     {
  160.  
  161.         public static DataChunk[] Parse(PlayerIOClient.Message m)
  162.         {
  163.  
  164.             if (m == null) throw new ArgumentNullException("m");
  165.  
  166.             if (m.Type != "init" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m");
  167.  
  168.  
  169.  
  170.             // Get world data
  171.  
  172.             var p = 0u;
  173.  
  174.             var data = new Stack<object>();
  175.  
  176.             while (m[p] as string != "ws") { ++p; }
  177.  
  178.             while (m[p] as string != "we") { data.Push(m[++p]); }
  179.  
  180.  
  181.  
  182.             // Parse world data
  183.  
  184.             var chunks = new List<DataChunk>();
  185.  
  186.             while (data.Count > 0)
  187.             {
  188.  
  189.                 var args = new Stack<object>();
  190.  
  191.                 while (!(data.Peek() is byte[]))
  192.  
  193.                     args.Push(data.Pop());
  194.  
  195.  
  196.  
  197.                 var ys = (byte[])data.Pop();
  198.  
  199.                 var xs = (byte[])data.Pop();
  200.  
  201.                 var layer = (int)data.Pop();
  202.  
  203.                 var type = (uint)data.Pop();
  204.  
  205.  
  206.  
  207.                 chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray()));
  208.  
  209.             }
  210.  
  211.  
  212.  
  213.             return chunks.ToArray();
  214.  
  215.         }
  216.  
  217.     }
  218.  
  219.  
  220.  
  221.     public class DataChunk
  222.     {
  223.  
  224.         public int Layer { get; set; }
  225.  
  226.         public uint Type { get; set; }
  227.  
  228.         public Point[] Locations { get; set; }
  229.  
  230.         public object[] Args { get; set; }
  231.  
  232.  
  233.  
  234.         public DataChunk(int layer, uint type, byte[] xs, byte[] ys, object[] args)
  235.         {
  236.  
  237.             this.Layer = layer;
  238.  
  239.             this.Type = type;
  240.  
  241.             this.Args = args;
  242.  
  243.             this.Locations = GetLocations(xs, ys);
  244.  
  245.         }
  246.  
  247.  
  248.  
  249.         private static Point[] GetLocations(byte[] xs, byte[] ys)
  250.         {
  251.  
  252.             var points = new List<Point>();
  253.  
  254.             for (var i = 0; i < xs.Length; i += 2)
  255.  
  256.                 points.Add(new Point(
  257.  
  258.                     (xs[i] << 8) | xs[i + 1],
  259.  
  260.                     (ys[i] << 8) | ys[i + 1]));
  261.  
  262.             return points.ToArray();
  263.  
  264.         }
  265.  
  266.     }
  267.  
  268.  
  269.  
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement