Beispiel #1
0
 /// <summary>
 /// Exactly what the function name is, it might be useful to change this players pos first ;)
 /// </summary>
 public void SendThisPlayerTheirOwnPos()
 {
     packet pa = new packet();
     pa.Add((byte)8);
     pa.Add(Pos.x);
     pa.Add(Pos.y);
     pa.Add(Pos.z);
     pa.Add(Rot);
     SendPacket(pa);
 }
Beispiel #2
0
 protected void CheckMotdPackets()
 {
     if (MOTD_NonAdmin.bytes == null)
     {
         MOTD_NonAdmin.Add(packet.types.MOTD);
         MOTD_NonAdmin.Add(ServerSettings.version);
         MOTD_NonAdmin.Add(ServerSettings.NAME, 64);
         MOTD_NonAdmin.Add(ServerSettings.MOTD, 64);
         MOTD_NonAdmin.Add((byte)0);
         MOTD_Admin = MOTD_NonAdmin;
         MOTD_Admin.bytes[130] = 100;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Kill this player for everyone.
 /// </summary>
 public void GlobalDie()
 {
     packet pa = new packet(new byte[2] { (byte)packet.types.SendDie, id });
     foreach (Player p in Server.Players.ToArray())
     {
         if (p != this)
         {
             p.SendPacket(pa);
         }
     }
 }
Beispiel #4
0
 public packet(packet p)
 {
     bytes = p.bytes;
 }
Beispiel #5
0
        protected void SendSpawn(Player p)
        {
            byte ID = 0xFF;
            if (p != this)
                ID = p.id;

            packet pa = new packet();
            pa.Add(packet.types.SendSpawn);
            pa.Add((byte)ID);
            pa.Add(p.USERNAME, 64);
            pa.Add(p.Pos.x);
            pa.Add(p.Pos.y);
            pa.Add(p.Pos.z);
            pa.Add(p.Rot);
            SendPacket(pa);
        }
Beispiel #6
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);
                }
            }
        }
Beispiel #7
0
 protected void SendPacket(packet pa)
 {
     try
     {
         lastPacket = (packet.types)pa.bytes[0];
     }
     catch (Exception e) { Server.Log(e); }
     for (int i = 0; i < 3; i++)
     {
         try
         {
             socket.BeginSend(pa.bytes, 0, pa.bytes.Length, SocketFlags.None, delegate(IAsyncResult result) { }, null);
             return;
         }
         catch
         {
             continue;
         }
     }
     CloseConnection();
 }
Beispiel #8
0
        protected void SendMessage(byte PlayerID, string message)
        {
            packet pa = new packet();

            for (int i = 0; i < 10; i++)
            {
                message = message.Replace("%" + i, "&" + i);
                message = message.Replace("&" + i + " &", "&");
            }
            for (char ch = 'a'; ch <= 'f'; ch++)
            {
                message = message.Replace("%" + ch, "&" + ch);
                message = message.Replace("&" + ch + " &", "&");
            }
            for (int i = 0; i < 10; i++)
            {
                message = message.Replace("%" + i, "&" + i);
                message = message.Replace("&" + i + " &", "&");
            }
            for (char ch = 'a'; ch <= 'f'; ch++)
            {
                message = message.Replace("%" + ch, "&" + ch);
                message = message.Replace("&" + ch + " &", "&");
            }

            pa.Add(packet.types.Message);
            pa.Add(PlayerID);

            try
            {
                foreach (string line in LineWrapping(message))
                {
                    if (pa.bytes.Length < 64)
                        pa.Add(line, 64);
                    else
                        pa.Set(2, line, 64);

                    SendPacket(pa);
                }
            }
            catch (Exception e)
            {
                Server.Log(e);
            }
        }
Beispiel #9
0
        protected void SendMap()
        {
            try
            {
                SendPacket(mapSendStartPacket); //Send the pre-fab map start packet

                packet pa = new packet(); //Create a packet to handle the data for the map
                pa.Add(level.TotalBlocks); //Add the total amount of blocks to the packet
                byte[] blocks = new byte[level.TotalBlocks]; //Temporary byte array so we dont have to keep modding the packet array

                byte block; //A block byte outside the loop, we save cycles by not making this for every loop iteration
                level.ForEachBlock(delegate(int pos)
                {
                    //Here we loop through the whole map and check/convert the blocks as necesary
                    //We then add them to our blocks array so we can send them to the player
                    block = level.data[pos];
                    if (block < 50) blocks[pos] = block;
                    else blocks[pos] = Blocks.CustomBlocks[block].VisibleType;
                });

                pa.Add(blocks); //add the blocks to the packet
                pa.GZip(); //GZip the packet

                int number = (int)Math.Ceiling(((double)(pa.bytes.Length)) / 1024); //The magic number for this packet

                for (int i = 1; pa.bytes.Length > 0; ++i)
                {
                    short length = (short)Math.Min(pa.bytes.Length, 1024);
                    byte[] send = new byte[1027];
                    packet.HTNO(length).CopyTo(send, 0);
                    Buffer.BlockCopy(pa.bytes, 0, send, 2, length);
                    byte[] tempbuffer = new byte[pa.bytes.Length - length];
                    Buffer.BlockCopy(pa.bytes, length, tempbuffer, 0, pa.bytes.Length - length);
                    pa.bytes = tempbuffer;
                    send[1026] = (byte)(i * 100 / number);

                    packet Send = new packet(send);
                    Send.AddStart(new byte[1] { (byte)packet.types.MapData });

                    SendPacket(Send);
                }

                pa = new packet();
                pa.Add(packet.types.MapEnd);
                pa.Add((short)level.Size.x);
                pa.Add((short)level.Size.y);
                pa.Add((short)level.Size.z);
                SendPacket(pa);

                isLoading = false;
            }
            catch (Exception e)
            {
                Server.Log(e);
            }
        }
Beispiel #10
0
 protected void SendKick(string message)
 {
     packet pa = new packet();
     pa.Add(packet.types.SendKick);
     pa.Add(message, 64);
     SendPacket(pa);
 }
Beispiel #11
0
        protected void SendBlockChange(ushort x, ushort z, ushort y, byte type)
        {
            if (x < 0 || y < 0 || z < 0 || x >= level.Size.x || y >= level.Size.y || z >= level.Size.z) return;

            packet pa = new packet();
            pa.Add(packet.types.SendBlockchange);
            pa.Add(x);
            pa.Add(y);
            pa.Add(z);

            if (type > 49) type = Blocks.CustomBlocks[type].VisibleType;
            pa.Add(type);

            SendPacket(pa);
        }