コード例 #1
0
 protected void SendKick(string message)
 {
     packet pa = new packet();
     pa.Add((byte)14);
     pa.Add(message, 64);
     SendPacket(pa);
 }
コード例 #2
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] { 3 });

                    SendPacket(Send);
                }

                pa = new packet();
                pa.Add((byte)4);
                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);
            }
        }
コード例 #3
0
 protected void CheckMotdPackets()
 {
     if (MOTD_NonAdmin.bytes == null)
     {
         MOTD_NonAdmin.Add((byte)0);
         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;
     }
 }
コード例 #4
0
        //protected void SendDie(byte id)
        //{
        //    packet pa = new packet(new byte[2] { 12, id });
        //}
        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((byte)6);
            pa.Add(x);
            pa.Add(y);
            pa.Add(z);

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

            SendPacket(pa);
        }
コード例 #5
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);
 }
コード例 #6
0
 public packet(packet p)
 {
     bytes = p.bytes;
 }
コード例 #7
0
 /// <summary>
 /// Kill this player for everyone.
 /// </summary>
 public void GlobalDie()
 {
     packet pa = new packet(new byte[2] { 12, id });
     foreach (Player p in Server.Players.ToArray())
     {
         if (p != this)
         {
             p.SendPacket(pa);
         }
     }
 }
コード例 #8
0
        protected void UpdatePosition(bool ForceTp)
        {
            byte changed = 0;   //Denotes what has changed (x,y,z, rotation-x, rotation-y)

            int diffX = Pos.x - oldPos.x;
            int diffZ = Pos.z - oldPos.z;
            int diffY = Pos.y - oldPos.y;
            int diffR0 = Rot[0] - oldRot[0];
            int diffR1 = Rot[1] - oldRot[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;
                    }
                }
            }

            oldPos = Pos; oldRot = Rot;
            packet pa = new packet();

            switch (changed)
            {
                case 1: //Pos Change
                    pa.Add((byte)10);
                    pa.Add(id);
                    pa.Add((sbyte)(diffX));
                    pa.Add((sbyte)(diffY));
                    pa.Add((sbyte)(diffZ));
                    break;
                case 2: //Rot Change
                    pa.Add((byte)11);
                    pa.Add(id);
                    //pa.Add(new byte[2] { 128, 128 });
                    pa.Add(Rot);
                    break;
                case 3: //Pos AND Rot Change
                    pa.Add((byte)9);
                    pa.Add(id);
                    pa.Add((sbyte)(Pos.x - oldPos.x));
                    pa.Add((sbyte)(Pos.y - oldPos.y));
                    pa.Add((sbyte)(Pos.z - oldPos.z));
                    //pa.Add(new byte[2] { 128, 128 });
                    pa.Add(Rot);
                    break;
                case 4: //Teleport Required
                    pa.Add((byte)8);
                    pa.Add(id);
                    pa.Add(Pos.x);
                    pa.Add(Pos.y);
                    pa.Add(Pos.z);
                    //pa.Add(new byte[2] { 128, 128 });
                    pa.Add(Rot);
                    break;
            }

            foreach (Player p in Server.Players.ToArray())
            {
                if (p != this && p.level == level && p.isLoggedIn && !p.isLoading)
                {
                    p.SendPacket(pa);
                }
            }
        }
コード例 #9
0
        protected void SendSpawn(Player p)
        {
            byte ID = 0xFF;
            if (p != this)
                ID = p.id;

            packet pa = new packet();
            pa.Add((byte)7);
            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);
        }
コード例 #10
0
 protected void SendPacket(packet pa)
 {
     try
     {
         lastPacket = 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();
 }
コード例 #11
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((byte)13);
            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);
            }
        }