public void CacheFromStorage()
        {
            var area_dir = StoragePath;

            if (!Directory.Exists(area_dir))
            {
                return;
            }
            var area_names = Directory.GetFiles(area_dir, "*.json", SearchOption.TopDirectoryOnly);

            foreach (var area in area_names)
            {
                var mapObj = StorageManager.AreaBucket.Load(Path.GetFileNameWithoutExtension(area));

                if (mapObj == null)
                {
                    continue;
                }

                var mapFile = Directory.GetFiles($@"{ServerContext.StoragePath}\maps", $"lod{mapObj.Number}.map",
                                                 SearchOption.TopDirectoryOnly).FirstOrDefault();

                if (mapFile != null && File.Exists(mapFile))
                {
                    mapObj.Data = File.ReadAllBytes(mapFile);
                    mapObj.Hash = Crc16Provider.ComputeChecksum(mapObj.Data);
                    {
                        StorageManager.AreaBucket.Save(mapObj);
                    }

                    mapObj.OnLoaded();
                    ServerContext.GlobalMapCache[mapObj.Number] = mapObj;
                }
            }
        }
Exemplo n.º 2
0
        public static void LoadMap(Area mapObj, string mapFile, bool save = false)
        {
            mapObj.Data = File.ReadAllBytes(mapFile);
            mapObj.Hash = Crc16Provider.ComputeChecksum(mapObj.Data);
            {
                if (save)
                {
                    StorageManager.AreaBucket.Save(mapObj);
                }
            }

            mapObj.OnLoaded();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (propertyGrid1.SelectedObject == null)
            {
                return;
            }

            if (propertyGrid1.SelectedObject is MonsterTemplate)
            {
                var template = (MonsterTemplate)propertyGrid1.SelectedObject;

                try
                {
                    StorageManager.MonsterBucket.Save(template);
                    Console.WriteLine("New MonsterTemplate Added. You must restart server to take affect.");
                    Close();
                }
                catch
                {
                    Console.WriteLine("{0} was not created. Something went wrong.", template.Name);
                }
            }

            if (propertyGrid1.SelectedObject is Area)
            {
                var template = (Area)propertyGrid1.SelectedObject;

                try
                {
                    if (!Directory.Exists(ServerContext.STORAGE_PATH + "\\maps"))
                    {
                        Directory.CreateDirectory(ServerContext.STORAGE_PATH + "\\maps");
                    }

                    var mapFile = Directory.GetFiles($@"{ServerContext.STORAGE_PATH}\maps", $"lor{template.ID}.map",
                                                     SearchOption.TopDirectoryOnly).FirstOrDefault();

redo:

                    if (mapFile != null)
                    {
                        template.Data = File.ReadAllBytes(mapFile);
                        template.Hash = Crc16Provider.ComputeChecksum(template.Data);

                        StorageManager.AreaBucket.Save(template);
                        Console.WriteLine("New Area Added. You must restart server to take affect.");
                        Close();
                    }
                    else
                    {
                        using (var fod = new OpenFileDialog())
                        {
                            fod.Multiselect        = false;
                            fod.CheckFileExists    = true;
                            fod.AutoUpgradeEnabled = true;
                            fod.Filter             = "MAP File|*.map";
                            if (fod.ShowDialog() == DialogResult.OK)
                            {
                                mapFile = fod.FileName;

                                var file = ServerContext.STORAGE_PATH + "\\maps\\" + Path.GetFileName(mapFile);
                                if (!File.Exists(file))
                                {
                                    Console.WriteLine("Copying over map file to storage....");
                                    File.Copy(mapFile, file);
                                    Console.WriteLine("Copying over map file to storage....  Done");
                                }

                                goto redo;
                            }
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("{0} was not created. Something went wrong.", template.Name);
                }
            }


            if (propertyGrid1.SelectedObject is SkillTemplate)
            {
                var template = (SkillTemplate)propertyGrid1.SelectedObject;
                try
                {
                    StorageManager.SKillBucket.Save(template);
                    Console.WriteLine("New Skill Added. You must restart server to take affect.");
                    Close();
                }
                catch
                {
                    Console.WriteLine("{0} was not created. Something went wrong.", template.Name);
                }
            }

            if (propertyGrid1.SelectedObject is SpellTemplate)
            {
                var template = (SpellTemplate)propertyGrid1.SelectedObject;
                try
                {
                    StorageManager.SpellBucket.Save(template);
                    Console.WriteLine("New Spell Added. You must restart server to take affect.");
                    Close();
                }
                catch
                {
                    Console.WriteLine("{0} was not created. Something went wrong.", template.Name);
                }
            }

            if (propertyGrid1.SelectedObject is ItemTemplate)
            {
                var template = (ItemTemplate)propertyGrid1.SelectedObject;
                try
                {
                    StorageManager.ItemBucket.Save(template);
                    Console.WriteLine("New Item Template Added. You must restart server to take affect.");
                    Close();
                }
                catch
                {
                    Console.WriteLine("{0} was not created. Something went wrong.", template.Name);
                }
            }

            if (propertyGrid1.SelectedObject is MundaneTemplate)
            {
                var template = (MundaneTemplate)propertyGrid1.SelectedObject;
                try
                {
                    StorageManager.MundaneBucket.Save(template);
                    Console.WriteLine("New Mundane Added. You must restart server to take affect.");
                    Close();
                }
                catch
                {
                    Console.WriteLine("{0} was not created. Something went wrong.", template.Name);
                }
            }
        }