Beispiel #1
0
        private async Task <byte[]> GenerateBattlePreviewAsync()
        {
            int centerX           = 0;
            int centerY           = 0;
            int previewHalfHeight = 150;
            int previewHalfWidth  = 100;

            int chunkXFrom = (int)Math.Max(Math.Ceiling(((decimal)(centerX - previewHalfWidth)) / _battle.Settings.ChunkWidth), _battle.Settings.MinWidthIndex);
            int chunkYFrom = (int)Math.Max(Math.Ceiling(((decimal)(centerY - previewHalfHeight)) / _battle.Settings.ChunkHeight), _battle.Settings.MinHeightIndex);
            int chunkXTo   = (int)Math.Min(Math.Floor(((decimal)(centerX + previewHalfWidth)) / _battle.Settings.ChunkWidth), _battle.Settings.MaxWidthIndex);
            int chunkYTo   = (int)Math.Min(Math.Floor(((decimal)(centerY + previewHalfHeight)) / _battle.Settings.ChunkHeight), _battle.Settings.MaxHeightIndex);

            var chunks = new List <(int x, int y, byte[] image)>((chunkXTo - chunkXFrom) * (chunkYTo - chunkYFrom));

            for (int i = chunkXFrom; i <= chunkXTo; i++)
            {
                for (int j = chunkYFrom; j <= chunkYTo; j++)
                {
                    var chunkGrain = this.GrainFactory.GetGrain <IChunkGrain>(GuidExtensions.ToGuid(_battleId, i, j));
                    var chunkState = await chunkGrain.GetStateAsync();

                    chunks.Add((i, j, chunkState.Image));
                }
            }

            return(_imageProcessor.GenerateImageFromChunks(
                       chunks: chunks,
                       chunkHeight: _battle.Settings.ChunkHeight,
                       chunkWidth: _battle.Settings.ChunkWidth,
                       previewHeight: previewHalfHeight,
                       previewWidth: previewHalfWidth,
                       centerX: centerX,
                       centerY: centerY));
        }
Beispiel #2
0
        public LoginModule()
        {
            Get["/login"] = x => {
                dynamic model     = new ExpandoObject();
                var     returnUrl = (string)Request.Query.returnUrl;
                model.ReturnUrl = returnUrl;
                model.Copyright = @"© 2013 - " + DateTime.Now.ToString("yyyy") + " Anthilla S.r.l.";
                return(View["login", model]);
            };

            Post["/login"] = x => {
                var username = (string)Request.Form.Username;
                var password = (string)Request.Form.Password;
                if (string.IsNullOrEmpty(username + password))
                {
                    return(Context.GetRedirect("/login"));
                }
                ConsoleLogger.Log($"login attempt from {username}");
                var expiration = DateTime.Now.AddHours(4);
                var cookies    = Request.Cookies;
                while (cookies.Any())
                {
                    cookies.Clear();
                }
                var validationGuid = UserDatabase.ValidateUser(username, password);
                if (validationGuid == null)
                {
                    return(Context.GetRedirect("/login"));
                }
                var sessionCookie = new NancyCookie("antd-session", GuidExtensions.ToGuid(validationGuid).ToString(), expiration);
                ConsoleLogger.Log($"{username} logged in successfully");
                var returnUrl = (string)Request.Form.Return;
                return(this.LoginAndRedirect(GuidExtensions.ToGuid(validationGuid), expiration, returnUrl).WithCookie(sessionCookie));
            };

            Get["/logout"] = x => {
                var cookies = Request.Cookies;
                while (cookies.Any())
                {
                    cookies.Clear();
                }
                return(this.LogoutAndRedirect("/"));
            };

            Get["/login/auth/{username}/{password}"] = x => {
                dynamic model = new ExpandoObject();
                model.WantsEmail = true;
                model.HasToken   = false;
                model.Username   = x.username;
                model.Password   = x.password;
                model.Email      = "";
                return(View["login", model]);
            };

            Get["/login/token/{session}"] = x => {
                dynamic model = new ExpandoObject();
                model.Session = x.session;
                return(View["login-token", model]);
            };

            Post["/login/verify"] = x => {
                var username       = (string)Request.Form.Username;
                var password       = (string)Request.Form.Password;
                var validationGuid = UserDatabase.ValidateUser(username, password);
                var response       = validationGuid != null;
                return(Response.AsJson(response));
            };
        }
Beispiel #3
0
 private Guid FormatChunkKey(ChunkKey key)
 {
     return(GuidExtensions.ToGuid(key.BattleId, key.ChunkXIndex, key.ChunkYIndex));
 }