Beispiel #1
0
        public ActionResult Edit(long?block_id, string block_name, string block_friendly_name, long?[] block_templates, long?block_content_root, string block_area, string block_controller, string block_action, bool block_allow_sort, string block_order_fields)
        {
            using (BlockRepository block_repository = new BlockRepository())
            {
                if (block_id.HasValue)
                {
                    block_repository.Update(block_id.Value, block_name, block_friendly_name, (block_templates == null ? string.Empty : string.Join(",", block_templates)), block_content_root, block_area, block_controller, block_action, block_allow_sort, block_order_fields, CurrentUser.user_domain);
                }
                else
                {
                    block_id = block_repository.CreateGlobalID();

                    string new_block_name = Transliterator.Translite(block_friendly_name);

                    if (block_repository.Exists(new_block_name, CurrentUser.user_domain))
                    {
                        new_block_name = new_block_name + "-" + block_id.ToString();
                    }

                    block_repository.Create(block_id.Value, new_block_name, block_friendly_name, (block_templates == null ? string.Empty : string.Join(",", block_templates)), block_content_root, block_area, block_controller, block_action, block_allow_sort, block_order_fields, false, CurrentUser.user_domain);
                }
            }

            return(RedirectToAction("Index"));
        }
        public async Task PutBlock([FromBody] BuddyLookup lookupData)
        {
            var   from_profile = (await profileRepository.Lookup(lookupData.SourceProfile)).First();
            var   to_profile   = (await profileRepository.Lookup(lookupData.TargetProfile)).First();
            Block block        = new Block();

            block.FromProfileid = from_profile.Id;
            block.ToProfileid   = to_profile.Id;
            await blockRepository.Create(block);

            blockRepository.SendAddEvent(from_profile, to_profile);
        }
Beispiel #3
0
        public ActionResult AddSeparate()
        {
            string block_friendly_name = "Разделитель";

            using (BlockRepository block_repository = new BlockRepository())
            {
                long block_id = block_repository.CreateGlobalID();

                string new_block_name = Transliterator.Translite(block_friendly_name);

                if (block_repository.Exists(new_block_name, CurrentUser.user_domain))
                {
                    new_block_name = new_block_name + "-" + block_id.ToString();
                }

                block_repository.Create(block_id, new_block_name, block_friendly_name, string.Empty, null, null, null, null, false, string.Empty, true, CurrentUser.user_domain);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Clone(long?domain_id)
        {
            Dictionary <long, long> views = new Dictionary <long, long>();

            Dictionary <long, long> templates = new Dictionary <long, long>();

            Dictionary <long, long> blocks = new Dictionary <long, long>();

            Dictionary <long, long> contents = new Dictionary <long, long>();

            if (domain_id.HasValue)
            {
                using (DomainRepository domain_repository = new DomainRepository())
                {
                    var source_domain = domain_repository.GetByID(domain_id.Value);

                    // create domain

                    long new_domain_id = domain_repository.CreateGlobalID();

                    domain_repository.Create(new_domain_id, string.Format("new-{0}", new_domain_id), string.Empty);

                    // end create domain

                    // create views

                    using (ViewRepository view_repository = new ViewRepository())
                    {
                        foreach (var view in view_repository.All(source_domain.domain_id))
                        {
                            long new_view_id = view_repository.CreateGlobalID();

                            view_repository.Create(new_view_id, view.view_friendly_name, view.view_name, view.view_path, new_domain_id, view.view_order);

                            views.Add(view.view_id, new_view_id);
                        }
                    }

                    // end create views

                    // create templates

                    using (TemplateRepository template_repository = new TemplateRepository())
                    {
                        foreach (var template in template_repository.All(source_domain.domain_id))
                        {
                            long new_template_id = template_repository.CreateGlobalID();

                            string template_views = string.Empty;

                            foreach (var template_view_id in ((string)template.template_views ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                template_views += string.Format("{0},", views[Int64.Parse(template_view_id)]);
                            }

                            template_repository.Create(new_template_id, template.template_friendly_name, template.template_name, template.template_allow_subpartitions, template.template_fields, template_views.Trim(','), template.template_templates, template.template_allow_sort, template.template_order_fields, template.template_create_child, new_domain_id, template.template_order);

                            templates.Add(template.template_id, new_template_id);
                        }

                        foreach (var template in template_repository.All(new_domain_id))
                        {
                            string template_templates = string.Empty;

                            foreach (var template_template_id in ((string)template.template_templates ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                template_templates += string.Format("{0},", templates[Int64.Parse(template_template_id)]);
                            }

                            template_repository.UpdateRefsTemplates(template.template_id, template_templates.Trim(','));
                        }
                    }

                    // end create templates

                    // create variables

                    using (VariableRepository variable_repository = new VariableRepository())
                    {
                        foreach (var variable in variable_repository.All(source_domain.domain_id))
                        {
                            long new_variable_id = variable_repository.CreateGlobalID();

                            variable_repository.Create(new_variable_id, variable.var_name, variable.var_friendly_name, variable.var_value, variable.var_type, variable.var_comment, variable.var_group, new_domain_id);
                        }
                    }

                    // end create variables

                    // create blocks

                    using (BlockRepository block_repository = new BlockRepository())
                    {
                        foreach (var block in block_repository.All(source_domain.domain_id))
                        {
                            long new_block_id = block_repository.CreateGlobalID();

                            string block_templates = string.Empty;

                            foreach (var block_template_id in ((string)block.block_templates ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                block_templates += string.Format("{0},", templates[Int64.Parse(block_template_id)]);
                            }

                            block_repository.Create(new_block_id, block.block_name, block.block_friendly_name, block_templates.Trim(','), block.block_content_root, block.block_area, block.block_controller, block.block_action, block.block_allow_sort, block.block_order_fields, block.block_separated, new_domain_id, block.block_order);

                            blocks.Add(block.block_id, new_block_id);
                        }
                    }

                    // end create blocks

                    // create contents

                    using (ContentRepository content_repository = new ContentRepository())
                    {
                        foreach (var content in content_repository.GetByDomain(source_domain.domain_id))
                        {
                            // build user data

                            string user_data = string.Empty;

                            using (FieldRepository field_repository = new FieldRepository())
                            {
                                List <dynamic> fields = field_repository.GetByIDs(content.template_fields);

                                foreach (var item in fields)
                                {
                                    if (item.field_group != "Пользовательские")
                                    {
                                        continue;
                                    }

                                    var value = ((IDictionary <string, object>)content)[item.field_name];

                                    if (value != null)
                                    {
                                        switch ((string)item.field_type)
                                        {
                                        case "string":
                                        case "html":
                                            value = string.Format("'{0}'", MySql.Data.MySqlClient.MySqlHelper.EscapeString(value));
                                            break;

                                        case "boolean":

                                            break;

                                        case "list":
                                            break;

                                        case "date":
                                            value = string.Format("'{0}'", value.ToString("yyyy-MM-dd"));
                                            break;

                                        case "decimal":
                                            value = value.ToString().Replace(",", ".");
                                            break;

                                        default:
                                            value = value == null ? null : string.Format("'{0}'", value);
                                            break;
                                        }
                                    }

                                    user_data += string.Format(",{0} = {1}", item.field_name, (value == null ? "NULL" : value));
                                }
                            }

                            // end build user data


                            long new_content_id = content_repository.CreateGlobalID();

                            content_repository.Create(new_content_id, content.content_in_sitemap, content.content_export_rss, content.content_active, content.content_main, content.content_allow_deleted, content.content_name,
                                                      (content.content_view == null ? null : views[content.content_view]),
                                                      content.content_url, blocks[content.content_block], content.content_title, content.content_description, content.content_keywords, content.content_h1, content.content_h2, content.content_short_text, content.content_text,
                                                      content.content_publish, content.content_root, templates[content.content_template], content.content_allow_redirect, content.content_redirect_permanent, content.content_redirect_url, content.content_link, content.content_export_rss_ids, content.content_export_rss_title,
                                                      new_domain_id, user_data, content.content_order);

                            contents.Add(content.content_id, new_content_id);
                        }

                        foreach (var content in content_repository.GetByDomain(new_domain_id))
                        {
                            string user_data = string.Empty;

                            using (FieldRepository field_repository = new FieldRepository())
                            {
                                List <dynamic> fields = field_repository.GetByIDs(content.template_fields);

                                foreach (var item in fields)
                                {
                                    if (item.field_group == "Пользовательские")
                                    {
                                        var value = ((IDictionary <string, object>)content)[item.field_name];

                                        if (value != null)
                                        {
                                            if (item.field_type == "list")
                                            {
                                                value = contents.ContainsKey(value) ? contents[value] : value;
                                            }
                                            else
                                            if (item.field_type == "multiplelist")
                                            {
                                                string values = string.Empty;

                                                foreach (var id in (value ?? string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                                                {
                                                    values += string.Format("{0},", contents.ContainsKey(Int64.Parse(id)) ? contents[Int64.Parse(id)] : Int64.Parse(id));
                                                }

                                                value = string.Format("'{0}'", values).Trim(',');
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }

                                        user_data += string.Format(",{0} = {1}", item.field_name, value ?? "NULL");
                                    }
                                }
                            }

                            content_repository.UpdateRefsRoot(content.content_id, content.content_root == null ? null : contents.ContainsKey(content.content_root) ? contents[content.content_root] : content.content_root, user_data);
                        }
                    }

                    // end create contents

                    // start blocks refs content_root update

                    using (BlockRepository block_repository = new BlockRepository())
                    {
                        foreach (var block in block_repository.All(new_domain_id))
                        {
                            if (block.block_content_root == null)
                            {
                                continue;
                            }

                            block_repository.UpdateRefsRoot(block.block_id, contents[block.block_content_root]);
                        }
                    }

                    // end blocks refs content_root update

                    // create files

                    using (FileRepository file_repository = new FileRepository())
                    {
                        foreach (var file in file_repository.All(source_domain.domain_id))
                        {
                            if (file.file_ref == null)
                            {
                                continue;
                            }

                            var new_file_id = file_repository.CreateGlobalID();

                            file_repository.Save(new_file_id, file.file_extension, contents[file.file_ref].ToString(), file.file_desc, (int)file.file_size, file.file_field, (DateTime)file.file_publish, (int)file.file_order, contents[file.file_ref]);

                            try
                            {
                                System.IO.File.Copy(
                                    Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", file.file_id, file.file_extension)),
                                    Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_file_id, file.file_extension))
                                    );
                            }
                            catch
                            {
                                using (FileRepository database = new FileRepository())
                                {
                                    database.Remove(new_file_id);
                                }
                            }
                        }
                    }

                    // end create files

                    // create images

                    using (ImageRepository image_repository = new ImageRepository())
                    {
                        foreach (var image in image_repository.All(source_domain.domain_id))
                        {
                            if (image.image_ref == null)
                            {
                                continue;
                            }

                            var new_image_id = image_repository.CreateGlobalID();

                            image_repository.Save(new_image_id, image.image_extension, contents[image.image_ref].ToString(), image.image_field, image.image_desc, (int)image.image_order, contents[image.image_ref]);

                            try
                            {
                                System.IO.File.Copy(
                                    Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", image.image_id, image.image_extension)),
                                    Path.Combine(Server.MapPath("~/content/cms/files"), string.Format("{0}{1}", new_image_id, image.image_extension))
                                    );
                            }
                            catch
                            {
                                using (FileRepository database = new FileRepository())
                                {
                                    database.Remove(new_image_id);
                                }
                            }
                        }
                    }

                    // end create images
                }
            }

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public void HandleWorldAction(MinecraftPacket packet)
        {
            switch (packet)
            {
            case CP1BPlayerDigging digging:
                bool IsLegal(double x1, double y1, double z1, double x2, double y2, double z2)
                {
                    return(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2) + Math.Pow(z2 - z1, 2)) <= 6.0);
                }

                BlockBase block = Parent.GetBlock(digging.Location.X, digging.Location.Y, digging.Location.Z);
                SP07AcknowledgePlayerDigging acknowledgePlayerDigging;

                if (block == null)
                {
                    acknowledgePlayerDigging = new SP07AcknowledgePlayerDigging(Client, digging.Location, 0,
                                                                                (SP07AcknowledgePlayerDigging.ActionType)digging.Status, false);
                    Client.Send(acknowledgePlayerDigging);
                    break;
                }

                if (!IsLegal(X, Y + 1.5, Z, digging.Location.X, digging.Location.Y, digging.Location.Z))
                {
                    acknowledgePlayerDigging = new SP07AcknowledgePlayerDigging(Client, digging.Location, block.State,
                                                                                (SP07AcknowledgePlayerDigging.ActionType)digging.Status, false);
                    Client.Send(acknowledgePlayerDigging);
                    break;
                }

                acknowledgePlayerDigging = new SP07AcknowledgePlayerDigging(Client, digging.Location, block.State,
                                                                            (SP07AcknowledgePlayerDigging.ActionType)digging.Status, true);
                Client.Send(acknowledgePlayerDigging);

                // TODO block break animation

                CP1BPlayerDigging.ActionType requiredAction;

                if (Gamemode == Gamemode.Creative)
                {
                    requiredAction = CP1BPlayerDigging.ActionType.StartedDigging;
                }
                else
                {
                    requiredAction = CP1BPlayerDigging.ActionType.FinishedDigging;
                }

                if (digging.Status == requiredAction)
                {
                    BlockBase air = new BlockAir();

                    Parent.SetBlock(air, digging.Location.X, digging.Location.Y, digging.Location.Z);

                    SP0BBlockChange blockChange = new(null, digging.Location, air.State);
                    Client.Server.MulticastAsync(blockChange, Client, Parent.GetClientsWithChunkLoaded(
                                                     (int)Math.Floor((double)digging.Location.X / Chunk.X_SIZE),
                                                     (int)Math.Floor((double)digging.Location.Z / Chunk.Z_SIZE)).ToArray());
                }
                break;

            case CP2EPlayerBlockPlacement playerBlockPlacement:
                Position.Int pos = new(playerBlockPlacement.Location);

                switch (playerBlockPlacement.Face)
                {
                case Face.Top:
                    pos.Y++;
                    break;

                case Face.Bottom:
                    pos.Y--;
                    break;

                case Face.North:
                    pos.Z--;
                    break;

                case Face.East:
                    pos.X++;
                    break;

                case Face.South:
                    pos.Z++;
                    break;

                case Face.West:
                    pos.X--;
                    break;
                }

                // TODO check for collisions here

                if (Parent.GetBlock(pos.X, pos.Y, pos.Z) == null)
                {
                    Inventory.Slot held = Inventory.Slots[Inventory.HeldSlot];

                    if (!held.IsEmpty() && held.Item is BlockItem item)
                    {
                        block = BlockRepository.Create(item.BlockProtocolId);

                        if (block == null || block.State == 0)
                        {
                            break;
                        }

                        if (pos.Y < 0 || pos.Y >= Chunk.Y_SIZE)
                        {
                            return;
                        }

                        Parent.SetBlock(block, pos.X, pos.Y, pos.Z);

                        SP0BBlockChange _blockChange = new(null, pos, block.State);
                        Client.Server.MulticastAsync(_blockChange, Client, Parent.GetClientsWithChunkLoaded(
                                                         (int)Math.Floor((double)pos.X / Chunk.X_SIZE),
                                                         (int)Math.Floor((double)pos.Z / Chunk.Z_SIZE)).ToArray());
                    }
                }
                break;

            case CP1CEntityAction:
                break;
            }
        }