Advertisement
Guest User

ZUpload - The new version

a guest
Aug 31st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.62 KB | None | 0 0
  1. using PlayerIOClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ZumzaUpload {
  8.     class Program {
  9.         static void Main(string[] args) {
  10.             string email, password, worldId;
  11.             Client client; Connection connection;
  12.             Console.Write("Your email: "); email = Console.ReadLine();
  13.             Console.Write("Your supercalifragilisticexpialidocious password: "); password = Console.ReadLine();
  14.             Console.Write("Your world id: "); worldId = Console.ReadLine();
  15.             client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", email, password, null);
  16.             connection = client.Multiplayer.JoinRoom(worldId, null);
  17.             var uploadTest = new UploadTest(connection);
  18.             connection.Send("init");
  19.             connection.OnMessage += delegate (Object s, Message m) {
  20.                 if(m.Type == "init") {
  21.                     connection.Send("init2");
  22.                     (new UploadTest(connection)).Test();
  23.                 }
  24.             };
  25.             Console.ReadKey();
  26.         }
  27.     }
  28.  
  29.     class UploadTest : UploadTestBase {
  30.         private List<int>[,] world = new List<int>[60, 100];
  31.         private volatile String key;
  32.         private Connection connection;
  33.  
  34.         public UploadTest(Connection connection) : base(connection) {
  35.             for (var i = 0; i < world.GetLength(0); i++)
  36.                 for (var j = 0; j < world.GetLength(1); j++)
  37.                     world[i, j] = new List<int>();
  38.             this.connection = connection;
  39.             connection.Send("init");
  40.             connection.OnMessage += delegate (Object s, Message m) {
  41.                 if (m.Type == "init") {
  42.                     connection.Send("init2");
  43.                     key = derot(m.GetString(5));
  44.                     base.Test();
  45.                 } else if (m.Type == "b") {
  46.                     try {
  47.                         if (world[m.GetInt(1), m.GetInt(2)].Contains(m.GetInt(3))) { // Is this really the block which we are looking for?
  48.                             blocksToPlace--;
  49.                             calculateTime();
  50.                             world[m.GetInt(1), m.GetInt(2)].Remove(m.GetInt(3));
  51.                         }
  52.                     } catch (ArgumentOutOfRangeException) { }
  53.                 }
  54.             };
  55.         }
  56.  
  57.         private string derot(string EncryptedKey) {
  58.             int c = 0;
  59.             string key = "";
  60.             for (int i = 0; i < EncryptedKey.Length; i++) {
  61.                 c = EncryptedKey[i];
  62.                 if (c >= 'a' && c <= 'z') {
  63.                     if (c > 'm')
  64.                         c -= 13;
  65.                     else
  66.                         c += 13;
  67.                 } else if (c >= 'A' && c <= 'Z') {
  68.                     if (c > 'M')
  69.                         c -= 13;
  70.                     else
  71.                         c += 13;
  72.                 }
  73.                 key = key + (char)c;
  74.             }
  75.             return key;
  76.         }
  77.  
  78.         private DateTime lastTime;
  79.         private volatile uint placingTime;
  80.         private uint timeSum = 0;
  81.  
  82.         private void calculateTime() { //Top speed permited by police?
  83.             timeSum += (uint) (DateTime.Now - lastTime).Milliseconds;
  84.             placingTime = timeSum / (totalBlocks - blocksToPlace);
  85.             lastTime = DateTime.Now;
  86.         }
  87.  
  88.         private volatile bool placing = false;
  89.         private volatile uint blocksToPlace = 0;
  90.         private uint totalBlocks = 0;
  91.  
  92.         protected override void Upload(int layer, int x, int y, int block) {  
  93.             world[x, y].Add(block);
  94.             blocksToPlace++; totalBlocks = blocksToPlace;
  95.             if(!placing) {
  96.                 placing = true;
  97.                 Task.Factory.StartNew(() => {
  98.                     lastTime = DateTime.Now;
  99.                     placingTime = 8;
  100.                     do {
  101.                         for (var i = 0; i < world.GetLength(0); i++)
  102.                             for (var j = 0; j < world.GetLength(1); j++) {
  103.                                 if (world[i, j].Count > 0) {
  104.                                     while (key == null) ;
  105.                                     connection.Send(key, 0, i, j, world[i, j][0]);
  106.                                     Thread.Sleep((int)placingTime / 2); // its a street with 2 bands, right?
  107.                                 }
  108.                             }
  109.                     } while (blocksToPlace > 0);
  110.                     placing = false;
  111.                     base.Check();
  112.                 });
  113.             }
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement