public DenoisePlacementBehaviour(UsefulDataRepresentation guiData, Bitmap canvas, LockBitmap borders, Dictionary <System.Drawing.Color, int> curCanvasInvPalette)
 {
     this.guiData             = guiData;
     this.canvas              = canvas;
     this.borders             = borders;
     this.curCanvasInvPalette = curCanvasInvPalette;
 }
 public TopDownPlacementBehaviour(UsefulDataRepresentation guiData, Bitmap canvas, LockBitmap borders, Dictionary <System.Drawing.Color, int> curCanvasInvPalette)
 {
     this.guiData             = guiData;
     this.canvas              = canvas;
     this.borders             = borders;
     this.curCanvasInvPalette = curCanvasInvPalette;
     lastUpdateIterCount      = new int[canvas.Width, canvas.Height];
 }
Ejemplo n.º 3
0
        private void ChangeCanvas()
        {
            curCanvas = guiData.CanvasId;
            Logger.Info("Loading canvas {0} in UserManager", curCanvas);

            //Disconnect everyone
            for (int i = users.Count - 1; i >= 0; i--)
            {
                Logger.Info("{0} disconnected", users[i].Client.Username);
                if (users[i].Session != null)
                {
                    users[i].Session.ClearQueue();
                    users[i].Session.Close();
                }
                if (users[i].Client.Status != Status.CLOSEDERROR && users[i].Client.Status != Status.CLOSEDDISCONNECT)
                {
                    users[i].Client.Disconnect();
                    if (users[i].Id != Guid.Empty)
                    {
                        guiUpdater.PushEvent("manager.status", new UserStatusData(users[i].Id, Status.NOTOPEN));
                    }
                }
                users.RemoveAt(i);
            }

            try
            {
                //Load canvas
                canvas?.Dispose();
                System.Net.WebRequest  request        = System.Net.WebRequest.Create("https://pixelplace.io/canvas/" + guiData.CanvasId.ToString() + ".png");
                System.Net.WebResponse response       = request.GetResponse();
                System.IO.Stream       responseStream = response.GetResponseStream();
                canvas = new Bitmap(responseStream);
                responseStream.Dispose();
            }
            catch (System.Net.WebException)
            {
                Logger.Error("Invalid canvas in usermanager");
                canvas = new Bitmap(1, 1);
                return;
            }

            try
            {
                //Load locked pixels
                System.Net.WebRequest  request2        = System.Net.WebRequest.Create("https://pixelplace.io/canvas/" + guiData.CanvasId.ToString() + "p.png");
                System.Net.WebResponse response2       = request2.GetResponse();
                System.IO.Stream       responseStream2 = response2.GetResponseStream();

                borders?.Dispose();
                borders = new LockBitmap(responseStream2);

                responseStream2.Dispose();
            }
            catch (System.Net.WebException)
            {
                borders = new LockBitmap(canvas.Width, canvas.Height);
            }
            lock (eventsToProcess)
            {
                eventsToProcess.Clear();
            }
            ChangePlacementBehaviour();

            Logger.Info("UserManager canvas loading finished");
        }