예제 #1
0
        public void CatchBlock2(Player p, ushort x, ushort z, ushort y, byte NewType, bool placed, object DataPass)
        {
            CatchPos FirstBlock = (CatchPos)DataPass;
            List<Pos> buffer = new List<Pos>();

            for (ushort xx = Math.Min((ushort)(FirstBlock.pos.x), x); xx <= Math.Max((ushort)(FirstBlock.pos.x), x); ++xx)
            {
                for (ushort zz = Math.Min((ushort)(FirstBlock.pos.z), z); zz <= Math.Max((ushort)(FirstBlock.pos.z), z); ++zz)
                {
                    for (ushort yy = Math.Min((ushort)(FirstBlock.pos.y), y); yy <= Math.Max((ushort)(FirstBlock.pos.y), y); ++yy)
                    {
                        Point3 loop = new Point3(xx, zz, yy);
                        if (p.level.GetBlock(loop) != FirstBlock.type)
                        {
                            BufferAdd(buffer, loop);
                        }
                    }
                }
            }
            //Group Max Blocks permissions here
            p.SendMessage(buffer.Count.ToString() + " blocks.");

            //Level Blockqueue .-.

            buffer.ForEach(delegate(Pos pos)
            {
                p.level.BlockChange((ushort)(pos.pos.x), (ushort)(pos.pos.z), (ushort)(pos.pos.y), FirstBlock.type2);
            });
        }
예제 #2
0
 public void Use(Player p, string[] args)
 {
     if (args.Count() != 0)
     {
         Help(p);
         return;
     }
     Point3 meep = new Point3((short)(p.Pos.x / 32), (short)(p.Pos.z / 32), (short)(p.Pos.y / 32));
     p.level.SpawnPos = meep;
     p.level.SpawnRot = p.Rot;
     p.SendMessage("Spawn location changed.");
 }
예제 #3
0
 void BufferAdd(List<Pos> list, Point3 type)
 {
     Pos pos;
     pos.pos = type;
     list.Add(pos);
 }
예제 #4
0
 public static string GetName(Point3 pos)
 {
     return GetName(pos.x, pos.z, pos.y);
 }
예제 #5
0
 private Level(Point3 size)
 {
     Size = size;
     //data = new byte[Size.x, Size.z, Size.y];
     data = new byte[TotalBlocks];
 }
예제 #6
0
 void SetBlock(Point3 pos, byte block)
 {
     SetBlock(pos.x, pos.z, pos.y, block);
 }
예제 #7
0
 void SetBlock(Point3 pos, Blocks.Types block)
 {
     SetBlock(pos.x, pos.z, pos.y, (byte)block);
 }
예제 #8
0
        private void CreateFlatLevel()
        {
            int middle = Size.y / 2;
            ForEachBlockXZY(delegate(int x, int z, int y)
            {
                if (y < middle)
                {
                    SetBlock((ushort)x, (ushort)z, (ushort)y, Blocks.Types.dirt);
                    return;
                }
                if(y==middle)
                {
                    SetBlock((ushort)x, (ushort)z, (ushort)y, Blocks.Types.grass);
                    return;
                }

            });

            SpawnPos = new Point3((short)(Size.x / 2), (short)(Size.z / 2), (short)(Size.y));
            SpawnRot = new byte[2]{0, 0};
        }
예제 #9
0
 /// <summary>
 /// get the block (byte) at an xzy pos
 /// </summary>
 /// <param name="pos">the pos to check and return</param>
 /// <returns>a byte that represents the blocktype at the given location</returns>
 public byte GetBlock(Point3 pos)
 {
     return GetBlock(pos.x, pos.z, pos.y);
 }
예제 #10
0
        /// <summary>
        /// Create a level with a specified type and a specified size
        /// </summary>
        /// <param name="size">The size to create the level.</param>
        /// <param name="type">The type of the level you want to create</param>
        /// <returns>returns the level that was created</returns>
        public static Level CreateLevel(Point3 size, LevelTypes type)
        {
            Level newlevel = new Level(size);

            switch(type)
            {
                case LevelTypes.Flat:
                    newlevel.CreateFlatLevel();
                    break;
            }

            return newlevel;
        }
예제 #11
0
        protected void HandleLogin(byte[] message)
        {
            try
            {
                if (isLoggedIn) return;
                byte version = message[0];
                USERNAME = enc.GetString(message, 1, 64).Trim();
                string verify = enc.GetString(message, 65, 32).Trim();
                byte type = message[129];
                if (!VerifyAccount(USERNAME, verify)) return;
                if (version != ServerSettings.version) { SKick("Wrong Version!."); return; }

                OnPlayerConnect e = new OnPlayerConnect(this);
                e.Call();

                //TODO Database Stuff

                Server.Log("[System]: " + ip + " logging in as " + USERNAME + ".", ConsoleColor.Green, ConsoleColor.Black);
                UniversalChat(USERNAME + " joined the game!");

                CheckDuplicatePlayers(USERNAME);

                SendMotd();

                isLoading = true;
                SendMap();
                if (!isOnline) return;
                isLoggedIn = true;

                id = FreeId();
                UpgradeConnectionToPlayer();

                //Do we want the same-ip-new-account code?

                //ushort x = (ushort)((0.5 + level.SpawnPos.x) * 32);
                //ushort y = (ushort)((1 + level.SpawnPos.y) * 32);
                //ushort z = (ushort)((0.5 + level.SpawnPos.z) * 32);

                short x = (short)((0.5 + level.SpawnPos.x) * 32);
                short y = (short)((1 + level.SpawnPos.y) * 32);
                short z = (short)((0.5 + level.SpawnPos.z) * 32);

                //x = (ushort)Math.Abs(x);
                //y = (ushort)Math.Abs(y);
                //z = (ushort)Math.Abs(z);

                Pos = new Point3(x, z, y);
                Rot = level.SpawnRot;
                oldPos = Pos;
                oldRot = Rot;

                SpawnThisPlayerToOtherPlayers();
                SpawnOtherPlayersForThisPlayer();
                SendSpawn(this);

                isLoading = false;

            }
            catch (Exception e)
            {
                Server.Log(e);
            }
        }
예제 #12
0
        protected void HandleBlockchange(byte[] message)
        {
            if (!isLoggedIn) return;

            ushort x = packet.NTHO(message, 0);
            ushort y = packet.NTHO(message, 2);
            ushort z = packet.NTHO(message, 4);
            byte action = message[6];
            byte newType = message[7];

            lastClick = new Point3(x, z, y);

            if (newType > 49 || (newType == 7 && !isAdmin))
            {
                Kick("HACKED CLIENT!");
                //TODO Send message to op's for adminium hack
                return;
            }

            byte currentType = level.GetBlock(x, z, y);
            if (currentType == (byte)Blocks.Types.zero)
            {
                Kick("HACKED CLIENT!");
                return;
            }

            //TODO Check for permissions to build and distance > max

            if (blockChange != null)
            {
                SendBlockChange(x, z, y, currentType);
                bool placing = false;
                if (action == 1) placing = true;

                BlockChangeDelegate tempBlockChange = blockChange;
                object tempPassBack = PassBackData;

                blockChange = null;
                PassBackData = null;

                ThreadPool.QueueUserWorkItem(delegate { tempBlockChange.Invoke(this, x, z, y, newType, placing, tempPassBack); });
                return;
            }

            if (action == 0) //Deleting
            {
                level.BlockChange(x, z, y, (byte)Blocks.Types.air);
            }
            else //Placing
            {
                level.BlockChange(x, z, y, newType);
            }
        }
예제 #13
0
        protected void UpdatePosition(bool ForceTp)
        {
            byte changed = 0;   //Denotes what has changed (x,y,z, rotation-x, rotation-y)

            Point3 tempOldPos = oldPos;
            Point3 tempPos = Pos;
            byte[] tempRot = Rot;
            byte[] tempOldRot = oldRot;

            oldPos = Pos; oldRot = Rot;

            int diffX = tempPos.x - tempOldPos.x;
            int diffZ = tempPos.z - tempOldPos.z;
            int diffY = tempPos.y - tempOldPos.y;
            int diffR0 = tempRot[0] - tempRot[0];
            int diffR1 = tempRot[1] - tempRot[1];

            if (ForceTp) changed = 4;
            else
            {
                //TODO rewrite local pos change code
                if (diffX == 0 && diffY == 0 && diffZ == 0 && diffR0 == 0 && diffR1 == 0)
                {
                    return; //No changes
                }
                if (Math.Abs(diffX) > 100 || Math.Abs(diffY) > 100 || Math.Abs(diffZ) > 100)
                {
                    changed = 4; //Teleport Required
                }
                else if (diffR0 == 0 && diffR1 == 0)
                {
                    changed = 1; //Pos Update Required
                }
                else
                {
                    changed += 2; //Rot Update Required

                    if (diffX != 0 || diffY != 0 || diffZ != 0)
                    {
                        changed += 1;
                    }
                }
            }

            packet pa = new packet();

            switch (changed)
            {
                case 1: //Pos Change
                    pa.Add(packet.types.SendPosChange);
                    pa.Add(id);
                    pa.Add((sbyte)(diffX));
                    pa.Add((sbyte)(diffY));
                    pa.Add((sbyte)(diffZ));
                    break;
                case 2: //Rot Change
                    pa.Add(packet.types.SendRotChange);
                    pa.Add(id);
                    pa.Add(new byte[2] { (byte)diffR0, (byte)diffR1 });
                    break;
                case 3: //Pos AND Rot Change
                    pa.Add(packet.types.SendPosANDRotChange);
                    pa.Add(id);
                    pa.Add(diffX);
                    pa.Add(diffY);
                    pa.Add(diffZ);
                    pa.Add(new byte[2] { (byte)diffR0, (byte)diffR1 });
                    break;
                case 4: //Teleport Required
                    pa.Add(packet.types.SendTeleport);
                    pa.Add(id);
                    pa.Add(tempPos.x);
                    pa.Add(tempPos.y);
                    pa.Add(tempPos.z);
                    pa.Add(Rot);
                    break;
            }

            foreach (Player p in Server.Players.ToArray())
            {
                if (p != this && p.level == level && p.isLoggedIn && !p.isLoading)
                {
                    p.SendPacket(pa);
                }
            }
        }
예제 #14
0
 public void Use(Player p, string[] args)
 {
     if (args.Length > 2)
     {
         p.SendMessage("Invalid arguments!");
         return;
     }
     else if (args.Length == 0)
     {
         Point3 meep = new Point3((short)(0.5 + p.level.SpawnPos.x * 32), (short)(0.5 + p.level.SpawnPos.z * 32), (short)(1 + p.level.SpawnPos.y * 32));
         p.SendToPos(meep, p.level.SpawnRot);
     }
     else if (args.Length == 1)
     {
         Player who = Player.Find(args[0]);
         if (who == null || who.isHidden) //Permissions needed
         {
             p.SendMessage("Player: " + args[0] + " not found!");
             return;
         }
         else if (who == p)
         {
             p.SendMessage("Why are you trying to teleport yourself to yourself?");
             return;
         }
         /*else if (!ServerSettings.higherranktp)
         {
             //Permissions to check ranks.
             p.SendMessage("You cannot teleport to a player of higher rank!");
             return;
         }*/
         else
         {
             if (p.level != who.level)
             {
                 //Need goto here
                 if (who.isLoading)
                 {
                     p.SendMessage("Waiting for " + who.color + who.USERNAME + Server.DefaultColor + " to spawn...");
                     while (who.isLoading) { }
                 }
             }
         }
         p.SendToPos(who.Pos, who.Rot);
         return;
     }
     else
     {
         Player one = Player.Find(args[0]);
         Player two = Player.Find(args[1]);
         if (one == null || two == null)
         {
             //Hehe
             p.SendMessage((one == null && two == null) ? "Players: " + args[0] + " and " + args[1] + " not found!" : "Player: " + ((one == null) ? args[0] : args[1]) + " not found!");
             return;
         }
         else if (one == p && two == p || one == p)
         {
             p.SendMessage((two == p) ? "Why are you trying to teleport yourself to yourself?" : "Why not just use /tp " + args[1] + "?");
             return;
         }
         else if (two == p)
         {
             p.SendMessage("Why not just use /summon " + args[0] + "?");
             return;
         }
         /*else if (p.permission < one.permission)
         {
         //Permissions to check ranks.
         p.SendMessage("You cannot force a player of higher rank to tp to another player!");
         }*/
         else
         {
             if (one.level != two.level)
             {
                 //Need goto here
                 if (two.isLoading)
                 {
                     p.SendMessage("Waiting for " + two.color + two.USERNAME + Server.DefaultColor + " to spawn...");
                     while (two.isLoading) { }
                 }
             }
         }
         one.SendToPos(two.Pos, two.Rot);
         p.SendMessage(one.USERNAME + " has been succesfully teleported to " + two.USERNAME + "!");
         return;
     }
 }
예제 #15
0
        public void Use(Player p, string[] args)
        {
            p.isFlying = !p.isFlying;
            if (!p.isFlying)
            {
                return;
            }
            p.SendMessage("You are now flying. &cJump!");

            Thread fly = new Thread(new ThreadStart(delegate
                {
                Point3 pos;
                Point3 oldpos = new Point3();
                List<Point3> buffer = new List<Point3>();
                while (p.isFlying)
                {
                    Thread.Sleep(20);
                    if (p.Pos.x == oldpos.x && p.Pos.z == oldpos.z && p.Pos.y == oldpos.y) continue;
                    try
                    {
                        List<Point3> tempBuffer = new List<Point3>();
                        List<Point3> toRemove = new List<Point3>();
                        ushort x = (ushort)((p.Pos.x) / 32);
                        ushort z = (ushort)((p.Pos.z) / 32);
                        ushort y = (ushort)((p.Pos.y - 60) / 32);
                        try
                        {
                            for (ushort xx = (ushort)(x - 1); xx <= x + 1; xx++)
                            {
                                for (ushort yy = (ushort)(y - 1); yy <= y; yy++)
                                {
                                    for (ushort zz = (ushort)(z - 1); zz <= z + 1; zz++)
                                    {
                                        if (p.level.GetBlock(xx,zz, yy) == (byte)Blocks.Types.air)
                                        {
                                            pos.x = (short)xx; pos.y = (short)yy; pos.z = (short)zz;
                                            tempBuffer.Add(pos);
                                        }
                                    }
                                }
                            }
                            foreach (Point3 cP in tempBuffer)
                            {
                                if (!buffer.Contains(cP))
                                {
                                    buffer.Add(cP);
                                    p.SendBlockChange((ushort)cP.x, (ushort)cP.z, (ushort)cP.y, (byte)Blocks.Types.glass);
                                }
                            }
                            foreach (Point3 cP in buffer)
                            {
                                if (!tempBuffer.Contains(cP))
                                {
                                    p.SendBlockChange((ushort)cP.x, (ushort)cP.z, (ushort)cP.y, (byte)Blocks.Types.air);
                                    toRemove.Add(cP);
                                }
                            }
                            foreach (Point3 cP in toRemove)
                            {
                                buffer.Remove(cP);
                            }
                            tempBuffer.Clear();
                            toRemove.Clear();
                        }
                        catch { }
                    }
                    catch { }
                    //
                    //p.Pos.CopyTo(oldpos, 0);
                }

                foreach (Point3 cP in buffer)
                {
                    p.SendBlockChange((ushort)cP.x, (ushort)cP.z, (ushort)cP.y, (byte)Blocks.Types.air);
                }

                p.SendMessage("Stopped flying");
            }));
            fly.Start();
        }
예제 #16
0
 public void Use(Player p, string[] args)
 {
     if (args.Count() != 0)
     {
         Help(p);
         return;
     }
     Point3 meep = new Point3((short)(p.level.SpawnPos.x * 32), (short)(p.level.SpawnPos.z * 32 + 51), (short)(p.level.SpawnPos.y * 32));
     p.SendToPos(meep, p.level.SpawnRot);
 }