Пример #1
0
        static void BoxHandler(NetworkClient client, HypercubeMap map, Vector3S location, byte mode, Block block)
        {
            if (mode != 1)
                return;

            switch (client.CS.MyEntity.BuildState) {
                case 0:
                    client.CS.MyEntity.ClientState.SetCoord(location, 0);
                    client.CS.MyEntity.BuildState = 1;
                    break;
                case 1:
                    var coord1 = client.CS.MyEntity.ClientState.GetCoord(0);
                    var blocks = Math.Abs(location.X - coord1.X)*Math.Abs(location.Y - coord1.Y)*
                                 Math.Abs(location.Z - coord1.Z);
                    var replaceBlock = client.CS.MyEntity.ClientState.GetString(0);

                    if (blocks < 50000) {
                        map.BuildBox(client, coord1.X, coord1.Y, coord1.Z, location.X, location.Y, location.Z, block,
                            String.IsNullOrEmpty(replaceBlock)
                                ? ServerCore.Blockholder.UnknownBlock
                                : ServerCore.Blockholder.GetBlock(replaceBlock), false, 1, true, false);

                        Chat.SendClientChat(client, "§SBox created.");
                    }
                    else
                        Chat.SendClientChat(client, "§EBox too large.");

                    client.CS.MyEntity.SetBuildmode("");
                    break;
            }
        }
Пример #2
0
        public Entity(HypercubeMap map, string name, Vector3S location, byte rot, byte look)
        {
            Name = name;
            Location = location;
            Rot = rot;
            Look = look;
            Map = map;
            Model = "default";
            Visible = true;
            Id = ServerCore.FreeEids.Pop();

            BuildMaterial = ServerCore.Blockholder.GetBlock("");
            Lastmaterial = ServerCore.Blockholder.GetBlock(1);
            ClientState = new BuildState();
            BuildMode = new BmStruct {Name = ""};

            ClientId = (byte)Map.FreeIds.Pop();
        }
Пример #3
0
 /// <summary>
 /// Determines if a block is valid to be sent in the EnvSetMapAppearence packet.
 /// By spec: Sprites and half-blocks are not allowed to be a side/edge block.
 /// </summary>
 /// <param name="block"></param>
 /// <returns></returns>
 public static bool AppearanceAllowed(Block block)
 {
     switch (block.Name) {
         case "Sapling":
         case "Yellow Flower":
         case "Red Flower":
         case "Brown Mushroom":
         case "Red Mushroom":
         case "Stair":
         case "Cobblestone Slab":
         case "Rope":
         case "Fire":
         case "Snow":
             return false;
         default:
             return true;
     }
 }
Пример #4
0
        static void CreateTPHandler(NetworkClient client, HypercubeMap map, Vector3S location, byte mode, Block block)
        {
            if (mode != 1)
                return;

            var state = client.CS.MyEntity.BuildState;

            switch (state) {
                case 0:
                    client.CS.MyEntity.ClientState.SetCoord(location.X, location.Y, location.Z, 1);
                    client.CS.MyEntity.BuildState = 1;
                    return;
                case 1:
                    var destCoord = client.CS.MyEntity.ClientState.GetCoord(0);
                    var destRot = client.CS.MyEntity.ClientState.GetInt(0);
                    var destLook = client.CS.MyEntity.ClientState.GetInt(1);
                    var startCoord = client.CS.MyEntity.ClientState.GetCoord(1);
                    var endCoord = new Vector3S { X = location.X, Y = location.Y, Z = location.Z };
                    var teleName = client.CS.MyEntity.ClientState.GetString(0);
                    var destMap = HypercubeMap.GetMap(client.CS.MyEntity.ClientState.GetString(1));

                    // -- Move things around so the smaller is the start, the larger being the end.
                    if (startCoord.X > location.X) {
                        endCoord.X = startCoord.X;
                        startCoord.X = location.X;
                    }

                    if (startCoord.Y > location.Y) {
                        endCoord.Y = startCoord.Y;
                        startCoord.Y = location.Y;
                    }

                    if (startCoord.Z > location.Z) {
                        endCoord.Z = startCoord.Z;
                        startCoord.Z = location.Z;
                    }

                    client.CS.CurrentMap.Teleporters.CreateTeleporter(teleName, startCoord, endCoord, destCoord, (byte)destLook, (byte)destRot, destMap);
                    Chat.SendClientChat(client, "§STeleporter created.");
                    client.CS.MyEntity.SetBuildmode("");
                    break;
            }
        }
Пример #5
0
        public BlockContainer()
        {
            NumberList = new Block[255];
            NameList = new SortedDictionary<string, Block>(StringComparer.InvariantCultureIgnoreCase);
            _blocksfile = new Settings("Blocks.txt", LoadBlocks);
            ServerCore.Setting.RegisterFile(_blocksfile);

            UnknownBlock = new Block
                {
                    Id = 99,
                    Name = "Unknown",
                    OnClient = 46,
                    CPELevel = 0,
                    CPEReplace = 46,
                    DeletePermissions = PermissionContainer.SplitPermissions("player.op"),
                    Special = true,
                };

            _blocksfile.LoadFile();
            _blocksfile.SaveFile();
        }
Пример #6
0
        public void BuildSphere(NetworkClient client, short x, short y, short z, float radius, Block material, Block replaceMaterial, bool hollow, short priority, bool undo, bool physics)
        {
            var rounded = (int)Math.Round(radius, 1);
            var power = (float)Math.Pow(radius, 2);

            for (var ix = -rounded; ix < rounded; ix++) {
                for (var iy = -rounded; iy < rounded; iy++) {
                    for (var iz = -rounded; iz < rounded; iz++) {
                        var squareDistance = (int)(Math.Pow(ix, 2) + Math.Pow(iy, 2) + Math.Pow(iz, 2));

                        if (!(squareDistance <= power))
                            continue;

                        var allowed = false;

                        if (hollow) {
                            if (Math.Pow(ix + 1, 2) + Math.Pow(iy, 2) + Math.Pow(iz, 2) > power)
                                allowed = true;

                            if (Math.Pow(ix - 1, 2) + Math.Pow(iy, 2) + Math.Pow(iz, 2) > power)
                                allowed = true;

                            if (Math.Pow(ix, 2) + Math.Pow(iy + 1, 2) + Math.Pow(iz, 2) > power)
                                allowed = true;

                            if (Math.Pow(ix, 2) + Math.Pow(iy - 1, 2) + Math.Pow(iz, 2) > power)
                                allowed = true;

                            if (Math.Pow(ix, 2) + Math.Pow(iy, 2) + Math.Pow(iz + 1, 2) > power)
                                allowed = true;

                            if (Math.Pow(ix, 2) + Math.Pow(iy, 2) + Math.Pow(iz - 1, 2) > power)
                                allowed = true;
                        } else {
                            allowed = true;
                        }

                        if (!allowed)
                            continue;

                        if (replaceMaterial.Id == 99 || replaceMaterial == GetBlock((short)(x + ix), (short)(y + iy), (short)(z + iz)))
                            BlockChange(client.CS.Id, (short)(x + ix), (short)(y + iy), (short)(z + iz), material, GetBlock((short)(x + ix), (short)(y + iy), (short)(z + iz)), undo, physics, true, priority);
                    }
                }
            }
        }
Пример #7
0
        public void BuildLine(NetworkClient client, short x, short y, short z, short x2, short y2, short z2, Block material, short priority, bool undo, bool physics)
        {
            var dx = x2 - x;
            var dy = y2 - y;
            var dz = z2 - z;

            var blocks = 1;

            if (blocks < Math.Abs(dx))
                blocks = Math.Abs(dx);

            if (blocks < Math.Abs(dy))
                blocks = Math.Abs(dy);

            if (blocks < Math.Abs(dz))
                blocks = Math.Abs(dz);

            var mx = dx / (float) blocks;
            var my = dy / (float)blocks;
            var mz = dz / (float)blocks;

            for (var i = 0; i < blocks; i++) {
                var item = new BlockQueueItem {
                    Last = GetBlock((short)(x + mx * i), (short)(y + my * i), (short)(z + mz * i)),
                    Map = this,
                    Material = material,
                    Physics = physics,
                    PlayerId = client.CS.Id,
                    Priority = priority,
                    Undo = undo,
                    X = (short)(x + mx * i),
                    Y = (short)(y + my * i),
                    Z = (short)(z + mz * i),
                };

                ActionQueue.Enqueue(item);
            }
        }
Пример #8
0
        public void BuildBox(NetworkClient client, short x, short y, short z, short x2, short y2, short z2, Block material, Block replaceMaterial, bool hollow, short priority, bool undo, bool physics)
        {
            if (x > x2) {
                var temp = x;
                x = x2;
                x2 = temp;
            }
            if (y > y2) {
                var temp = y;
                y = y2;
                y2 = temp;
            }
            if (z > z2) {
                var temp = z;
                z = z2;
                z2 = temp;
            }

            for (var ix = x; ix < x2 + 1; ix++) {
                for (var iy = y; iy < y2 + 1; iy++) {
                    for (var iz = z; iz < z2 + 1; iz++) {
                        if (replaceMaterial.Id != 99 && replaceMaterial != GetBlock(ix, iy, iz))
                            continue;

                        var item = new BlockQueueItem {
                            Last = GetBlock(ix, iy, iz),
                            Map = this,
                            Material = material,
                            Physics = physics,
                            PlayerId = client.CS.Id,
                            Priority = priority,
                            Undo = undo,
                            X = ix,
                            Y = iy,
                            Z = iz,
                        };

                        if (ix == x || ix == x2 || iy == y || iy == y2 || iz == z || iz == z2)
                            ActionQueue.Enqueue(item);
                        else if (hollow == false)
                            ActionQueue.Enqueue(item);
                    }
                }
            }
        }
Пример #9
0
        public void BlockChange(short clientId, short x, short y, short z, Block type, Block lastType, bool undo, bool physics, bool send, short priority)
        {
            if (!HCSettings.Building)
                return;

            SetBlockId(x, y, z, (byte)(type.Id), clientId);

            if (undo) {
                NetworkClient client;

                ServerCore.Nh.IntLoggedClients.TryGetValue(clientId, out client);

                if (client != null) {
                    if (client.CS.CurrentIndex == -1)
                        client.CS.CurrentIndex = 0;

                    if (client.CS.CurrentIndex != (client.CS.UndoObjects.Count - 1)) {
                        for (var i = client.CS.CurrentIndex; i < client.CS.UndoObjects.Count - 1; i++)
                            client.CS.UndoObjects.RemoveAt(i);
                    }

                    if (client.CS.UndoObjects.Count >= 50000)
                        client.CS.UndoObjects.RemoveAt(0);

                    var newUndo = new Undo {X = x, Y = y, Z = z, OldBlock = lastType, NewBlock = type};

                    client.CS.UndoObjects.Add(newUndo);
                    client.CS.CurrentIndex = client.CS.UndoObjects.Count - 1;
                }
            }

            if (send)
                BlockchangeQueue.Enqueue(new QueueItem(x, y, z, priority));

            if (!physics || !HCSettings.Physics)
                return;

            var randomGen = new Random();

            for (short ix = -1; ix < 2; ix++) {
                for (short iy = -1; iy < 2; iy++) {
                    for (short iz = -1; iz < 2; iz++) {

                        if (!BlockInBounds((short)(x + ix), (short)(y + iy), (short)(z + iz)))
                            continue;

                        var index = BlockIndex(x + ix, y + iy, z + iz);

                        if ((_physicsBitmask[index / 8] & (1 << (index % 8))) != 0)
                            continue;

                        var blockQueue = GetBlock((short)(x + ix), (short)(y + iy), (short)(z + iz));

                        if (blockQueue.Physics <= 0 && string.IsNullOrEmpty(blockQueue.PhysicsPlugin))
                            continue;

                        _physicsBitmask[index/8] = (byte)(_physicsBitmask[index/8] | (1 << (index%8)));
                        PhysicsQueue.Enqueue(new QueueItem((short)(x + ix), (short)(y + iy), (short)(z + iz), DateTime.UtcNow.AddMilliseconds(blockQueue.PhysicsDelay + randomGen.Next(blockQueue.PhysicsRandom))));
                    }
                }
            }
        }
Пример #10
0
        void PhysicsInfiniteWater(Block physicBlock, short x, short y, short z)
        {
            short playerId = -1;

            if (HCSettings.History)
                playerId = History.GetLastPlayer(x, y, z);

            if (GetBlockId(x, y, (short)(z - 1)) == 0)
                BlockChange(playerId, x, y, (short)(z - 1), physicBlock, GetBlock(x, y, (short)(z - 1)), true, true, true, 1);
            else if (GetBlockId((short)(x + 1), y, z) == 0)
                BlockChange(playerId, (short)(x + 1), y, z, physicBlock, GetBlock((short)(x + 1), y, z), true, true, true, 1);
            else if (GetBlockId((short)(x - 1), y, z) == 0)
                BlockChange(playerId, (short)(x - 1), y, z, physicBlock, GetBlock((short)(x - 1), y, z), true, true, true, 1);
            else if (GetBlockId(x, (short)(y + 1), z) == 0)
                BlockChange(playerId, x, (short)(y + 1), z, physicBlock, GetBlock(x, (short)(y + 1), z), true, true, true, 1);
            else if (GetBlockId(x, (short)(y - 1), z) == 0)
                BlockChange(playerId, x, (short)(y - 1), z, physicBlock, GetBlock(x, (short)(y - 1), z), true, true, true, 1);
        }
Пример #11
0
 public void SendBlockToAll(short x, short y, short z, Block type)
 {
     foreach(var c in ClientsList)
         SendBlock(c, x, y, z, type);
 }
Пример #12
0
        /// <summary>
        /// Updates the settings for a certain block, and saves it to file.
        /// </summary>
        /// <param name="toUpdate">The block to be updated on file.</param>
        public void UpdateBlock(Block toUpdate)
        {
            _blocksfile.SelectGroup(toUpdate.Id.ToString());

            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["Name"] = toUpdate.Name;
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["OnClient"] = toUpdate.OnClient.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["Physics"] = toUpdate.Physics.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["PhysicsDelay"] = toUpdate.PhysicsDelay.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["PhysicsRandom"] = toUpdate.PhysicsRandom.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["PhysicsPlugin"] = toUpdate.PhysicsPlugin;
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["Kills"] = toUpdate.Kills.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["Color"] = toUpdate.Color.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["CPELevel"] = toUpdate.CPELevel.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["CPEReplace"] = toUpdate.CPEReplace.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["Special"] = toUpdate.Special.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["ReplaceOnLoad"] = toUpdate.ReplaceOnLoad.ToString();
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["PlacePerms"] =
                PermissionContainer.PermissionsToString(toUpdate.PlacePermissions);
            _blocksfile.SettingsDictionary[toUpdate.Id.ToString()]["DeletePerms"] =
                PermissionContainer.PermissionsToString(toUpdate.DeletePermissions);

            _blocksfile.SaveFile();
        }
Пример #13
0
        private static void HistoryHandler(NetworkClient client, HypercubeMap map, Vector3S location, byte mode, Block block)
        {
            Chat.SendClientChat(client,
                map.HCSettings.History
                    ? map.History.LookupString(location.X, location.Z, location.Y)
                    : "§EHistory is not enabled on this map.");

            client.CS.MyEntity.SetBuildmode("");
        }
Пример #14
0
        /// <summary>
        /// Creates a new block and saves it to file.
        /// </summary>
        /// <param name="name">Name of the block.</param>
        /// <param name="onClient">The block ID to send to the client.</param>
        /// <param name="deletePerms">Comma seperated list of permissions required to delete this block.</param>
        /// <param name="physics">The physics type to be processed for this block.</param>
        /// <param name="physicsDelay">The amount of time between physics ticks for this block.</param>
        /// <param name="physicsRandom">A random time added to the base physics delay.</param>
        /// <param name="physicsPlugin">The plugin that will be called to handle physics.</param>
        /// <param name="replacePhysics">If the block should be re-added to the physics queue after physics has completed.</param>
        /// <param name="kills">True if a player will be killed upon contact with this block.</param>
        /// <param name="color">The color code for this block.</param>
        /// <param name="cpeLevel">The CustomBlocks level that this block is in.</param>
        /// <param name="cpeReplace">The block to replace this block with if the client doesn't support the above CPE Level.</param>
        /// <param name="special">True to show this block on the custom materials list.</param>
        /// <param name="replaceOnLoad">-1 for none. Replaces this block with another on map load.</param>
        /// <param name="placePerms">Comma seperated list of permissions required to delete this block.</param>
        public void CreateBlock(string name, byte onClient, string placePerms, string deletePerms, int physics, int physicsDelay, int physicsRandom, string physicsPlugin, bool replacePhysics, bool kills, int color, int cpeLevel, int cpeReplace, bool special, int replaceOnLoad)
        {
            if (GetBlock(name).Name != "Unknown") // -- Block already exists, do not overwrite.
                return;

            var newBlock = new Block {
                Id = GetNextId(),
                Name = name,
                OnClient = onClient,
                Physics = physics,
                PhysicsDelay = physicsDelay,
                PhysicsRandom = physicsRandom,
                PhysicsPlugin = physicsPlugin,
                RepeatPhysics = replacePhysics,
                Kills = kills,
                Color = color,
                CPELevel = cpeLevel,
                CPEReplace = cpeReplace,
                Special = special,
                ReplaceOnLoad = replaceOnLoad,
                PlacePermissions = PermissionContainer.SplitPermissions(placePerms),
                DeletePermissions = PermissionContainer.SplitPermissions(deletePerms),
            };

            NumberList[newBlock.Id] = newBlock;
            NameList.Add(newBlock.Name, newBlock);

            _blocksfile.SelectGroup(newBlock.Id.ToString());
            _blocksfile.Write("Name", newBlock.Name);
            _blocksfile.Write("OnClient", newBlock.OnClient.ToString());
            _blocksfile.Write("Physics", newBlock.Physics.ToString());
            _blocksfile.Write("PhysicsDelay", newBlock.PhysicsDelay.ToString());
            _blocksfile.Write("PhysicsRandom", newBlock.PhysicsRandom.ToString());
            _blocksfile.Write("PhysicsPlugin", newBlock.PhysicsPlugin);
            _blocksfile.Write("RepeatPhysics", newBlock.RepeatPhysics.ToString());
            _blocksfile.Write("Kills", newBlock.Kills.ToString());
            _blocksfile.Write("Color", newBlock.Color.ToString());
            _blocksfile.Write("CPELevel", newBlock.CPELevel.ToString());
            _blocksfile.Write("CPEReplace", newBlock.CPEReplace.ToString());
            _blocksfile.Write("Special", newBlock.Special.ToString());
            _blocksfile.Write("ReplaceOnLoad", newBlock.ReplaceOnLoad.ToString());
            _blocksfile.Write("PlacePerms", PermissionContainer.PermissionsToString(newBlock.PlacePermissions));
            _blocksfile.Write("DeletePerms", PermissionContainer.PermissionsToString(newBlock.DeletePermissions));
        }
Пример #15
0
        public void ClientChangeBlock(NetworkClient client, short x, short y, short z, byte mode, Block newBlock)
        {
            if (!HCSettings.Building) {
                Chat.SendClientChat(client, "Building is disabled on this map at this time.");
                SendBlock(client, x, y, z, GetBlock(x, y, z));
                return;
            }

            if (!BlockInBounds(x, y, z))
                return;

            var mapBlock = GetBlock(x, y, z);

            if (mode == 0)
                newBlock = ServerCore.Blockholder.GetBlock(0);

            if (newBlock == mapBlock && newBlock != ServerCore.Blockholder.GetBlock(0))
                return;

            if (!client.HasAllPermissions(Buildperms.Values.ToList())) {
                Chat.SendClientChat(client, "§EYou are not allowed to build here.");
                SendBlock(client, x, y, z, mapBlock);
                return;
            }

            if (!client.HasAllPermissions(mapBlock.DeletePermissions.Values.ToList()) && mode == 0) {
                Chat.SendClientChat(client, "§EYou are not allowed to delete this block type.");
                SendBlock(client, x, y, z, mapBlock);
                return;
            }

            if (!client.HasAllPermissions(newBlock.PlacePermissions.Values.ToList()) && mode > 0) {
                Chat.SendClientChat(client, "§EYou are not allowed to place this block type.");
                SendBlock(client, x, y, z, mapBlock);
                return;
            }

            ServerCore.Luahandler.RunFunction("E_BlockChange", client, x, y, z, newBlock);
            BlockChange(client.CS.Id, x, y, z, newBlock, mapBlock, true, true, true, 250);
        }
Пример #16
0
        public void SendBlock(NetworkClient client, short x, short y, short z, Block type)
        {
            var setblock = new SetBlockServer {X = x, Y = y, Z = z};

            if (type.CPELevel > client.CS.CustomBlocksLevel)
                setblock.Block = (byte)type.CPEReplace;
            else
                setblock.Block = type.OnClient;

            client.SendQueue.Enqueue(setblock);
        }
Пример #17
0
        /// <summary>
        /// Parses the blocks ISettings object to load the blocks for the server.
        /// </summary>
        public void LoadBlocks()
        {
            NameList.Clear();
            FillBlocks();

            foreach (var id in _blocksfile.SettingsDictionary.Keys) {
                _blocksfile.SelectGroup(id);

                var newblock = new Block {
                    Id = int.Parse(id),
                    Name = _blocksfile.Read("Name", ""),
                    OnClient = (byte) _blocksfile.Read("OnClient", 46),
                    Physics = _blocksfile.Read("Physics", 0),
                    PhysicsDelay = _blocksfile.Read("PhysicsDelay", 0),
                    PhysicsRandom = _blocksfile.Read("PhysicsRandom", 0),
                    PhysicsPlugin = _blocksfile.Read("PhysicsPlugin", ""),
                    RepeatPhysics = bool.Parse(_blocksfile.Read("RepeatPhysics", "false")),
                    Kills = bool.Parse(_blocksfile.Read("Kills", "false")),
                    Color = _blocksfile.Read("Color", 0),
                    CPELevel = _blocksfile.Read("CPELevel", 0),
                    CPEReplace = _blocksfile.Read("CPEReplace", 0),
                    Special = bool.Parse(_blocksfile.Read("Special", "false")),
                    ReplaceOnLoad = _blocksfile.Read("ReplaceOnLoad", -1),
                    PlacePermissions = PermissionContainer.SplitPermissions(_blocksfile.Read("PlacePerms", "player.build")),
                    DeletePermissions = PermissionContainer.SplitPermissions(_blocksfile.Read("DeletePerms", "player.delete")),
                };
                NumberList[newblock.Id] = newblock;
                NameList.Add(newblock.Name, newblock);
            }

            if (NameList.Count == 0)
                CreateBlocks();

            ServerCore.Logger.Log("BlockContainer", "Blocks loaded", LogType.Info);
        }