Exemplo n.º 1
0
        public void LoadMap(string mapName)
        {
            try {
                map = Map.Load(this, mapName);
            } catch (Exception ex) {
                log.Log("Could not open the specified file ({0}): {1}", LogType.Error, mapName, ex.Message);
            }

            // or generate a default one
            if (map == null)
            {
                log.Log("World.Init: Generating default flatgrass level.", LogType.SystemActivity);
                map = new Map(this, 64, 64, 64);

                map.spawn.Set(map.widthX / 2 * 32 + 16, map.widthY / 2 * 32 + 16, map.height * 32, 0, 0);

                MapCommands.GenerateFlatgrass(map, false);

                if (!map.Save())
                {
                    throw new Exception("Could not save file.");
                }
            }
        }
Exemplo n.º 2
0
        void Load(Player player, Command cmd)
        {
            lock ( loadLock ) {
                if (world.loadInProgress || world.loadSendingInProgress)
                {
                    player.Message("Loading already in progress, please wait.");
                    return;
                }
                world.loadInProgress = true;
            }

            if (!player.Can(Permissions.SaveAndLoad))
            {
                world.NoAccessMessage(player);
                world.loadInProgress = false;
                return;
            }

            string mapName = cmd.Next();

            if (mapName == null)
            {
                player.Message("Syntax: " + Color.Help + "/load mapName");
                world.loadInProgress = false;
                return;
            }

            string mapFileName = mapName + ".fcm";

            if (!File.Exists(mapFileName))
            {
                player.Message("No backup file \"" + mapName + "\" found.");
                world.loadInProgress = false;
                return;
            }

            Map newMap = Map.Load(world, mapFileName);

            if (newMap == null)
            {
                player.Message("Could not load \"" + mapFileName + "\". Check logfile for details.");
                world.loadInProgress = false;
                return;
            }

            if (newMap.widthX != world.map.widthX ||
                newMap.widthY != world.map.widthY ||
                newMap.height != world.map.height)
            {
                player.Message("Map sizes of \"" + mapName + "\" and the current map do not match.");
                world.loadInProgress = false;
                return;
            }

            world.log.Log("{0} is loading the map \"{1}\".", LogType.UserActivity, player.name, mapName);
            player.Message("Loading map \"" + mapName + "\"...");
            world.BeginLockDown();
            MapSenderParams param = new MapSenderParams()
            {
                map    = newMap,
                player = player,
                world  = world
            };

            world.tasks.Add(MapSender.StreamLoad, param, true);
        }