Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PlayerIOClient;
- namespace DBot
- {
- public partial class Form1 : Form
- {
- public static Connection conn;
- public static Client client;
- public static List<string> names = new List<string>();
- public static Random ran = new Random();
- public static Dictionary<int, string> users = new Dictionary<int, string>();
- public bool isConnected;
- public bool Conntry;
- public static string username;
- public static string worldKey;
- public static string rotWorldKey;
- public Form1()
- {
- InitializeComponent();
- }
- private void ConnToggle_Click(object sender, EventArgs e)
- {
- Conntry = false;
- if ((isConnected) && (!Conntry))
- {
- Conntry = true;
- conn.Send("say", "[DBot] Disconnecting!");
- isConnected = false;
- conn.Disconnect();
- ConnToggle.Text = "Join!";
- }
- if ((!isConnected) && (!Conntry))
- {
- try
- {
- client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", UserInput.Text, PassInput.Text, null);
- conn = client.Multiplayer.JoinRoom(WldInput.Text, null);
- worldKey = CodeInput.Text;
- rotWorldKey = CodeInput.Text;
- rotWorldKey = Rot13.Derot(worldKey);
- //CodeInput.Text = worldKey;
- conn.OnMessage += OnMessage;
- conn.Send("init");
- Console.Read();
- isConnected = true;
- Conntry = true;
- System.Threading.Thread.Sleep(750);
- conn.Send("access", worldKey);
- System.Threading.Thread.Sleep(750);
- conn.Send("say", "[DBot V0.1] Connected!");
- ConnToggle.Text = "Leave!";
- }
- catch (PlayerIOError oops)
- {
- Console.Write(oops.Message);
- Console.Beep(500, 250);
- }
- catch (Exception oops2)
- {
- Console.Write(oops2.Message);
- Console.Beep(1000, 500);
- Console.Beep(750, 500);
- }
- }
- }
- static void OnMessage(object sender, PlayerIOClient.Message m)
- {
- if (m.Type == "init") conn.Send("init2");
- if (m.Type == "add")
- {
- names.Add(m.GetString(1));
- users.Add(m.GetInt(0), m.GetString(1));
- System.Threading.Thread.Sleep(750);
- conn.Send("say", "/pm " + m.GetString(1) + " Use !help for help.");
- }
- if (m.Type == "access")
- {
- System.Threading.Thread.Sleep(2000);
- conn.Send("say", "[DBot V0.1] Code achived!");
- }
- if (m.Type == "say")
- {
- if (users.ContainsKey(m.GetInt(0)))
- {
- string username = users[m.GetInt(0)];
- if (m.GetString(1) == "!help")
- {
- conn.Send("say", "[DBot] This is WIP. More will come soon.");
- }
- if (m.GetString(1) == "!bug")
- {
- conn.Send("say", "Hello, " + username + " likes to eat bugs.");
- System.Threading.Thread.Sleep(750);
- conn.Send(rotWorldKey, 0, 0, 0, 15);
- }
- }
- }
- }
- }
- public class Rot13
- {
- public static string Derot(string worldKey)
- {
- char[] array = worldKey.ToCharArray();
- for (int i = 0; i < array.Length; i++)
- {
- int number = (int)array[i];
- if (number >= 'a' && number <= 'z')
- {
- if (number > 'm')
- number -= 13;
- else
- number += 13;
- }
- else if (number >= 'A' && number <= 'Z')
- {
- if (number > 'M')
- number -= 13;
- else
- number += 13;
- }
- array[i] = (char)number;
- }
- return new string(array);
- }
- }
- public static class InitParse //Processor
- {
- public static DataChunk[] Parse(PlayerIOClient.Message m)
- {
- if (m == null) throw new ArgumentNullException("m");
- if (m.Type != "init" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m");
- // Get world data
- var p = 0u;
- var data = new Stack<object>();
- while (m[p] as string != "ws") { ++p; }
- while (m[p] as string != "we") { data.Push(m[++p]); }
- // Parse world data
- var chunks = new List<DataChunk>();
- while (data.Count > 0)
- {
- var args = new Stack<object>();
- while (!(data.Peek() is byte[]))
- args.Push(data.Pop());
- var ys = (byte[])data.Pop();
- var xs = (byte[])data.Pop();
- var layer = (int)data.Pop();
- var type = (uint)data.Pop();
- chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray()));
- }
- return chunks.ToArray();
- }
- }
- public class DataChunk
- {
- public int Layer { get; set; }
- public uint Type { get; set; }
- public Point[] Locations { get; set; }
- public object[] Args { get; set; }
- public DataChunk(int layer, uint type, byte[] xs, byte[] ys, object[] args)
- {
- this.Layer = layer;
- this.Type = type;
- this.Args = args;
- this.Locations = GetLocations(xs, ys);
- }
- private static Point[] GetLocations(byte[] xs, byte[] ys)
- {
- var points = new List<Point>();
- for (var i = 0; i < xs.Length; i += 2)
- points.Add(new Point(
- (xs[i] << 8) | xs[i + 1],
- (ys[i] << 8) | ys[i + 1]));
- return points.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement