/// <summary>
        /// Renders the requested identicon and returns it to the client.
        /// </summary>
        /// <param name="context"><see cref="HttpContext"/> with the current request and response.</param>
        public void ProcessRequest(HttpContext context)
        {
            if (IdenticonRequest.TryParse(context.Request.Url.Query, out var request))
            {
                // The urls are permanent so it is ok to cache icons for a long time
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Cache.SetMaxAge(TimeSpan.FromDays(30));

                var icon = Identicon.FromHash(request.Hash, request.Size);
                icon.Style = request.Style;

                switch (request.Format)
                {
                case ExportImageFormat.Png:
                    context.Response.ContentType = "image/png";
                    icon.SaveAsPng(context.Response.OutputStream);
                    break;

                case ExportImageFormat.Svg:
                    context.Response.ContentType = "image/svg+xml";
                    icon.SaveAsSvg(context.Response.OutputStream);
                    break;

                default:
                    throw new NotSupportedException($"The image format '{request.Format}' is not supported by {nameof(IdenticonHttpHandler)}.");
                }
            }
            else
            {
                throw new HttpException(404, "Icon not found");
            }
        }
Exemple #2
0
        public static void InitAreaCompleteInfoForEverest()
        {
            if (Everest.Flags.IsDisabled)
            {
                return;
            }

            if (Settings.Instance.SpeedrunClock > SpeedrunType.Off)
            {
                versionFull = $"{Celeste.Instance.Version}\n{Everest.Build}";

                using (Stream stream = Identicon.FromHash(Everest.InstallationHash, 100).SaveAsPng())
                    identicon = Texture2D.FromStream(Celeste.Instance.GraphicsDevice, stream);
            }
        }
Exemple #3
0
        private async Task HandleRequestAsync(HttpContext context, IdenticonRequest request)
        {
            var icon = Identicon.FromHash(request.Hash, request.Size);

            icon.Style = request.Style;

            var    headers = context.Response.GetTypedHeaders();
            Stream data;
            string contentType;

            switch (request.Format)
            {
            case ExportImageFormat.Svg:
                data        = icon.SaveAsSvg();
                contentType = "image/svg+xml";
                break;

            default:
                data        = icon.SaveAsPng();
                contentType = "image/png";
                break;
            }

            try
            {
                context.Response.ContentType   = contentType;
                context.Response.ContentLength = data.Length;

                // The urls are permanent so it is ok to cache icons for a long time
                headers.CacheControl =
                    new CacheControlHeaderValue
                {
                    Public = true,
                    MaxAge = TimeSpan.FromDays(30)
                };

                await data.CopyToAsync(context.Response.Body);
            }
            finally
            {
                data?.Dispose();
            }
        }
Exemple #4
0
        public static void InitAreaCompleteInfoForEverest2(bool pieScreen, Session session)
        {
            versionOffset = 0;

            if (Settings.Instance.SpeedrunClock > SpeedrunType.Off)
            {
                versionFull = $"{Celeste.Instance.Version}\n{Everest.Build}";

                if (session != null &&
                    Everest.Content.TryGet($"Maps/{AreaData.Get(session).Mode[(int) session.Area.Mode].Path}", out ModAsset asset) &&
                    asset.Source.Mod?.Multimeta?.Length >= 1)
                {
                    versionFull    = $"{versionFull}\n{asset.Source.Mod.Multimeta[0].Version}";
                    versionOffset -= 32;
                }

                identicon?.Dispose();
                using (Stream stream = Identicon.FromHash(Everest.InstallationHash, 100).SaveAsPng())
                    identicon = Texture2D.FromStream(Celeste.Instance.GraphicsDevice, stream);
            }

            isPieScreen = pieScreen;
        }
Exemple #5
0
 /// <summary>
 /// Creates an <see cref="IdenticonResult"/> instance with the specified hash.
 /// </summary>
 /// <param name="hash">The hex encoded hash that will be used as base for the icon. The hash string must contain at least 12 characters.</param>
 /// <param name="size">The size of the icon in pixels.</param>
 /// <param name="format">The format of the generated icon.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> was less than 1.</exception>
 /// <exception cref="ArgumentException"><paramref name="hash"/> was too short.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="hash"/> was <c>null</c>.</exception>
 public static IdenticonResult FromHash(string hash, int size, ExportImageFormat format = ExportImageFormat.Png)
 {
     return(new IdenticonResult(Identicon.FromHash(hash, size), format));
 }