Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading;
- using PlayerIOClient;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace SGB
- {
- class Program
- {
- public static string jbot = "jbot@gmail.com";
- public static string jbotp = "jbot123";
- public static string Email = jbot, Password = jbotp;
- public static string RoomId = "PWU3Eht6pYcUI";
- public static string GameId = "everybody-edits-su9rn58o40itdbnw69plyw";
- public static Random r = new Random();
- public static uint[,,] roomData = new uint[0, 3000, 3000];
- public static List<string> Admin = new List<string>();
- public static void Main(string[] args)
- {
- Connect(); // connects the bot
- Console.ReadKey();
- }
- #region Connect Information
- public static Connection con;
- public static Client client;
- public static void Connect()
- {
- client = PlayerIO.QuickConnect.SimpleConnect(GameId, Email, Password, null);
- con = client.Multiplayer.CreateJoinRoom(RoomId, "Everybodyedits" + client.BigDB.Load("config", "config")["version"], true, new Dictionary<string, string>(), new Dictionary<string, string>());
- con.Send("init");
- con.OnMessage += new MessageReceivedEventHandler(OnMessage);
- }
- #endregion
- public static void OnMessage(object sender, PlayerIOClient.Message m)
- {
- switch (m.Type)
- {
- #region Case initialize
- case "init":
- {
- #region Reads world data
- roomData = new uint[2, m.GetInt(18), m.GetInt(19)];
- var chunks = InitParse.Parse(m);
- foreach (var chunk in chunks)
- {
- foreach (var pos in chunk.Locations)
- {
- roomData[chunk.Layer, pos.X, pos.Y] = chunk.Type;
- }
- }
- #endregion
- con.Send("init2");
- Admin.Add(m.GetString(0)); // add the owner to the list obviously..
- Console.WriteLine("Bot connected.");
- con.Send("god", true);
- break;
- }
- #endregion
- #region Case build
- case "b":
- {
- int x = m.GetInt(1), y = m.GetInt(2), bid = m.GetInt(3);
- roomData[m.GetInt(0), m.GetInt(1), m.GetInt(2)] = (uint)m.GetInt(3);
- Random r = new Random();// integer name equals r.Next(minimum number, maximum number);
- if (bid == 1018)
- {
- int wormHeadX = x;
- int wormHeadY = y;
- int smr = r.Next(1, 4);
- if (smr == 1)//right
- {
- b(wormHeadX + 1, wormHeadY, 1018);
- Thread.Sleep(500);
- b(wormHeadX, wormHeadY, 0);
- }
- if (smr == 2)//left
- {
- b(x - 1, y, 1018);
- Thread.Sleep(500);
- b(wormHeadX, wormHeadY, 0);
- }
- if (smr == 3)//up
- {
- b(x, y + 1, 1018);
- Thread.Sleep(500);
- b(wormHeadX, wormHeadY, 0);
- }
- if (smr == 4)//down
- {
- b(x, y - 1, 1018);
- Thread.Sleep(500);
- b(wormHeadX, wormHeadY, 0);
- }
- }
- break;
- }
- #endregion
- #region Reset world
- case "reset": // if world is reset
- {
- var chunks1 = InitParse.Parse(m);
- foreach (var chunk in chunks1)
- {
- foreach (var pos in chunk.Locations)
- {
- roomData[chunk.Layer, pos.X, pos.Y] = chunk.Type;
- }
- }
- break;
- }
- #endregion
- #region case say
- case "say":
- {
- if (Regex.IsMatch(m.GetString(1), "^(!|$|@|#)"))
- {
- var msg = m.GetString(1).Substring(1, m.GetString(1).Length - 1).Split(' ');
- var user = users[m.GetInt(0)].name;
- if (msg[0] == "c" && Admin.Contains(user))
- {
- con.Disconnect();
- client.Logout();
- Console.WriteLine("Bot Disconnected");
- }
- }
- break;
- }
- #endregion
- #region Add players
- case "add":
- {
- #region Add users
- if (users.ContainsKey(m.GetInt(0)))
- {
- return; /*If player is already added returns their information to the list.*/
- }
- else
- {
- users.Add(m.GetInt(0), new Users()
- {
- name = m.GetString(1),
- });
- }
- #endregion
- break;
- }
- #endregion
- }
- }
- public static Dictionary<int, Users> users = new Dictionary<int, Users>();
- public class Users
- {
- public string name { get; set; }
- }
- public static void b(int x, int y, int bid) // quick build cuz im lazy.. xD
- {
- con.Send("b", 0, x, y, bid);
- }
- public void pm(string player, string message)
- {
- con.Send("say", string.Format("/pm {0} {1}", player, message));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement