Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Connection conn;
- public static Client client;
- public static List<string> names = new List<string>();
- public static Dictionary<int, string> users = new Dictionary<int, string>();
- public static Random ran = new Random();
- public static string rotCode;
- public static bool hascode;
- public static bool connected;
- public static string username;
- public static int health;
- public static int playerX;
- public static int playerY;
- public class block
- {
- public int layer { get; set; }
- public int x { get; set; }
- public int y { get; set; }
- public int bid { get; set; }
- }
- public static List<block> blockL = new List<block>();
- public static int[, ,] blocks = new int[2, 400, 650];
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void JoinWorld_Click(object sender, EventArgs e)
- {
- if (!connected)
- {
- try
- {
- client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", emailInput.Text, passInput.Text, null);
- conn = client.Multiplayer.JoinRoom(wldInput.Text, null);
- conn.OnMessage += OnMessage;
- conn.Send("init");
- Console.Read();
- System.Threading.Thread.Sleep(2000);
- conn.Send("say", "[???] Connected!");
- System.Threading.Thread.Sleep(750);
- conn.Send("access", codeInput.Text);
- }
- catch (PlayerIOError oops)
- {
- Console.WriteLine("Error! " + oops);
- Console.Beep(1000 , 1000);
- }
- }
- else
- {
- conn.Send("say", "[???] Disconnecting!");
- connected = false;
- conn.Disconnect();
- }
- }
- static void OnMessage(object sender, PlayerIOClient.Message m)
- {
- if (m.Type == "init")
- {
- connected = true;
- conn.Send("init2");
- rotCode = Rot13.Derot(m.GetString(5));
- }
- if (m.Type == "access")
- {
- hascode = true;
- conn.Send("say", "[???] Code achived!");
- }
- if (m.Type == "add")
- {
- names.Add(m.GetString(1));
- users.Add(m.GetInt(0), m.GetString(1));
- }
- if (m.Type == "left")
- {
- users.Remove(m.GetInt(0));
- }
- if (m.Type == "m")
- {
- int userid = m.GetInt(0);
- int playerX = m.GetInt(1) / 16;
- int playerY = m.GetInt(2) / 16;
- int hor = m.GetInt(7);
- int ver = m.GetInt(8);
- // conn.Send("say", userid + ", " + playerX + ", " + playerY + ", " + hor + ", " + ver + ", " + (playerX + hor) + ", " +(playerY + ver)); //Decommentfy if you want to see stats in game.
- if (blocks[0, playerX + hor, playerY + ver] == 16) //This does not work, regardless of the specified block being near you.
- {
- /* System.Threading.Thread.Sleep(750);
- conn.Send("say", "Found the block." + blocks[0, playerX + hor, playerY + ver]);
- System.Threading.Thread.Sleep(750); */
- conn.Send(rotCode, 0, playerX + hor, playerY + ver, 4);
- }
- }
- if (m.Type == "say")
- {
- if (users.ContainsKey(m.GetInt(0)))
- {
- string username = users[m.GetInt(0)];
- if (m.GetString(1) == "!help")
- {
- conn.Send("say", "/pm " + username + "[???] This is WIP. More will come soon.");
- }
- }
- }
- }
- public void getMapData(PlayerIOClient.Message m)
- {
- int w = m.GetInt(12);
- int h = m.GetInt(13);
- uint c = m.Count;
- uint kc = 17;
- while (kc < m.Count)
- {
- try
- {
- if (m.GetString(kc) == "ws")
- break;
- }
- catch { }
- kc++;
- }
- kc++;
- while (kc < c)
- {
- try
- {
- if (m.GetString(kc) == "we")
- break;
- }
- catch { }
- int blockid = m.GetInt(kc);
- int layer = m.GetInt(kc + 1);
- byte[] bytearray1 = m.GetByteArray(kc + 2);
- byte[] bytearray2 = m.GetByteArray(kc + 3);
- int bytelen = bytearray1.Length;
- for (int n = 0; n < bytelen; n += 2)
- {
- int x = Convert.ToInt32(bytearray1[n] << 8 | bytearray1[n + 1]);
- int y = Convert.ToInt32(bytearray2[n] << 8 | bytearray2[n + 1]);
- blocks[layer, x, y] = blockid;
- blockL.Add(new block { layer = layer, x = x, y = y, bid = blockid/*, health = health ~What does this do?~*/ });
- }
- switch (blockid)
- {
- case 242:
- case 381:
- kc += 7;
- break;
- case 43:
- case 165:
- case 77:
- case 83:
- case 361:
- case 374:
- case 375:
- case 376:
- case 377:
- case 378:
- case 379:
- case 380:
- case 385:
- case 1000:
- kc += 5;
- break;
- default:
- kc += 4;
- break;
- }
- }
- }
- public class Rot13
- {
- public static string Derot(string code)
- {
- char[] array = code.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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement