Ejemplo n.º 1
0
        public override bool Execute(VM vm)
        {
            string[]     CharacterInfos = new string[9];
            Blueprint    Blueprint      = new Blueprint(64, 64);
            XmlHouseData lotInfo;

            VMWorldActivator activator = new VMWorldActivator(vm, vm.Context.World);

            if (TS1)
            {
                Blueprint = activator.LoadFromIff(HouseFile);
            }
            else
            {
                using (var stream = new MemoryStream(XMLData))
                {
                    lotInfo = XmlHouseData.Parse(stream);
                }

                Blueprint = activator.LoadFromXML(lotInfo);
            }


            vm.Activator = activator;



            if (VM.UseWorld)
            {
                vm.Context.World.InitBlueprint(Blueprint);
                vm.Context.Blueprint = Blueprint;
            }
            vm.SetGlobalValue(11, JobLevel);

            AppearanceType type;

            foreach (XmlCharacter Char in Characters)
            {
                uint vsimID = (0);
                Enum.TryParse(Char.Appearance, out type);

                var vheadPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(Char.Head, 16), false);
                var vbodyPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(Char.Body, 16), false);
                var vHeadID          = vheadPurchasable != null ? vheadPurchasable.OutfitID :
                                       Convert.ToUInt64(Char.Head, 16);
                var vBodyID = vbodyPurchasable != null ? vbodyPurchasable.OutfitID :
                              Convert.ToUInt64(Char.Body, 16);

                VMAvatar visitor = vm.Activator.CreateAvatar
                                       (vm, Convert.ToUInt32(Char.ObjID, 16), Char, true, Convert.ToInt16(Char.Id));

                if (!vm.Entities.Contains(visitor))
                {
                    vm.SendCommand(new VMNetSimJoinCmd
                    {
                        ActorUID    = vsimID,
                        HeadID      = vHeadID,
                        BodyID      = vBodyID,
                        SkinTone    = (byte)type,
                        Gender      = Char.Gender == "male" ? true : false,
                        Name        = Char.Name,
                        Permissions = VMTSOAvatarPermissions.Visitor
                    });
                }
            }


            return(true);
        }
Ejemplo n.º 2
0
        public void ResetVM()
        {
            VMNetDriver driver;

            driver = new VMServerDriver(Port, NetClosed);

            var vm = new VM(new VMContext(null), new VMNullHeadlineProvider());

            state = vm;
            vm.Init();
            vm.VM_SetDriver(driver);
            vm.OnChatEvent += Vm_OnChatEvent;

            Console.WriteLine("Select the lot type");
            Console.WriteLine("1-Empty");
            Console.WriteLine("2-Blueprint");
            Console.WriteLine("3-House");

            string path = "";
            int    lot  = Convert.ToInt32(Console.ReadLine());

            if (lot == 1)
            {
                if (Settings.Default.DebugLot != String.Empty)
                {
                    path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/" + Settings.Default.DebugLot;
                }
                else
                {
                    path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/empty_lot.xml";
                }
            }
            else if (lot == 2)
            {
                Console.WriteLine("Specify lot name");
                path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/" + Console.ReadLine() + ".xml";
            }
            else if (lot == 3)
            {
                Console.WriteLine("Specify house name");
                path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/" + Console.ReadLine() + ".iff";
                TS1  = true;
            }


            XmlHouseData lotInfo;
            IffFile      HouseInfo = null;
            string       filename  = Path.GetFileName(path);

            if (!TS1)
            {
                try
                {
                    //try to load from FSOV first.
                    LoadState(vm, "Content/LocalHouse/" + filename.Substring(0, filename.Length - 4) + ".fsov");
                }
                catch (Exception)
                {
                    try
                    {
                        Console.WriteLine("Failed FSOV load... Trying Backup");
                        LoadState(vm, "Content/LocalHouse/" + filename.Substring(0, filename.Length - 4) + "_backup.fsov");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("CRITICAL::: Failed FSOV load... Trying Blueprint (first run or something went wrong)");
                        short jobLevel = -1;

                        //quick hack to find the job level from the chosen blueprint
                        //the final server will know this from the fact that it wants to create a job lot in the first place...

                        try
                        {
                            if (filename.StartsWith("nightclub") || filename.StartsWith("restaurant") || filename.StartsWith("robotfactory"))
                            {
                                jobLevel = Convert.ToInt16(filename.Substring(filename.Length - 9, 2));
                            }
                        }
                        catch (Exception) { }

                        //vm.SendCommand(new VMBlueprintRestoreCmd
                        //{
                        // JobLevel = jobLevel,
                        // XMLData = File.ReadAllBytes(path)
                        //});

                        using (var stream = new MemoryStream(File.ReadAllBytes(path)))
                        {
                            lotInfo = XmlHouseData.Parse(stream);
                        }

                        VMWorldActivator activator = new VMWorldActivator(vm, vm.Context.World);

                        vm.Activator = activator;

                        var blueprint = activator.LoadFromXML(lotInfo);

                        if (VM.UseWorld)
                        {
                            vm.Context.World.InitBlueprint(blueprint);
                            vm.Context.Blueprint = blueprint;
                        }


                        vm.Context.Clock.Hours = 10;

                        vm.MyUID = uint.MaxValue - 1;
                    }
                }
            }
            else
            {
                if (File.Exists(path))
                {
                    HouseInfo = new IffFile(path);
                }

                VMWorldActivator activator = new VMWorldActivator(vm, vm.Context.World);

                vm.Activator = activator;

                var blueprint = activator.LoadFromIff(HouseInfo);

                if (VM.UseWorld)
                {
                    vm.Context.World.InitBlueprint(blueprint);
                    vm.Context.Blueprint = blueprint;
                }


                vm.Context.Clock.Hours = 10;

                vm.MyUID = uint.MaxValue - 1;
            }



            Console.WriteLine("Select the server type");
            Console.WriteLine("1-Host");
            Console.WriteLine("2-Dedicated");

            int host = Convert.ToInt32(Console.ReadLine());

            if (host == 1)
            {
                vm.SendCommand(new VMNetSimJoinCmd
                {
                    ActorUID = uint.MaxValue - 1,
                    Name     = "server"
                });
            }
            else if (host == 2)
            {
                Dedicated = true;
            }
        }