Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PlayerIOClient;
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ZumzaUpload {
- class Program {
- static void Main(string[] args) {
- string email, password, worldId;
- Client client; Connection connection;
- Console.Write("Your email: "); email = Console.ReadLine();
- Console.Write("Your supercalifragilisticexpialidocious password: "); password = Console.ReadLine();
- Console.Write("Your world id: "); worldId = Console.ReadLine();
- client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", email, password, null);
- connection = client.Multiplayer.JoinRoom(worldId, null);
- var uploadTest = new UploadTest(connection);
- connection.Send("init");
- connection.OnMessage += delegate (Object s, Message m) {
- if(m.Type == "init") {
- connection.Send("init2");
- (new UploadTest(connection)).Test();
- }
- };
- Console.ReadKey();
- }
- }
- class UploadTest : UploadTestBase {
- private List<int>[,] world = new List<int>[60, 100];
- private volatile String key;
- private Connection connection;
- public UploadTest(Connection connection) : base(connection) {
- for (var i = 0; i < world.GetLength(0); i++)
- for (var j = 0; j < world.GetLength(1); j++)
- world[i, j] = new List<int>();
- this.connection = connection;
- connection.Send("init");
- connection.OnMessage += delegate (Object s, Message m) {
- if (m.Type == "init") {
- connection.Send("init2");
- key = derot(m.GetString(5));
- base.Test();
- } else if (m.Type == "b") {
- try {
- if (world[m.GetInt(1), m.GetInt(2)].Contains(m.GetInt(3))) { // Is this really the block which we are looking for?
- blocksToPlace--;
- calculateTime();
- world[m.GetInt(1), m.GetInt(2)].Remove(m.GetInt(3));
- }
- } catch (ArgumentOutOfRangeException) { }
- }
- };
- }
- private string derot(string EncryptedKey) {
- int c = 0;
- string key = "";
- for (int i = 0; i < EncryptedKey.Length; i++) {
- c = EncryptedKey[i];
- if (c >= 'a' && c <= 'z') {
- if (c > 'm')
- c -= 13;
- else
- c += 13;
- } else if (c >= 'A' && c <= 'Z') {
- if (c > 'M')
- c -= 13;
- else
- c += 13;
- }
- key = key + (char)c;
- }
- return key;
- }
- private DateTime lastTime;
- private volatile uint placingTime;
- private uint timeSum = 0;
- private void calculateTime() { //Top speed permited by police?
- timeSum += (uint) (DateTime.Now - lastTime).Milliseconds;
- placingTime = timeSum / (totalBlocks - blocksToPlace);
- lastTime = DateTime.Now;
- }
- private volatile bool placing = false;
- private volatile uint blocksToPlace = 0;
- private uint totalBlocks = 0;
- protected override void Upload(int layer, int x, int y, int block) {
- world[x, y].Add(block);
- blocksToPlace++; totalBlocks = blocksToPlace;
- if(!placing) {
- placing = true;
- Task.Factory.StartNew(() => {
- lastTime = DateTime.Now;
- placingTime = 8;
- do {
- for (var i = 0; i < world.GetLength(0); i++)
- for (var j = 0; j < world.GetLength(1); j++) {
- if (world[i, j].Count > 0) {
- while (key == null) ;
- connection.Send(key, 0, i, j, world[i, j][0]);
- Thread.Sleep((int)placingTime / 2); // its a street with 2 bands, right?
- }
- }
- } while (blocksToPlace > 0);
- placing = false;
- base.Check();
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement