Esempio n. 1
0
        void UpdatePlayerPos()
        {
            //TODO create pos change packet
            Packet packet = new Packet();

            if (delta.IsZero())
            {
                return;
            }
            else
            {
                if (delta.NeedTp())
                {
                    packet.id = PacketType.PositionAndOrientationTeleport;
                    packet.AddVar(UserId);
                    packet.AddVar(position.x);
                    packet.AddVar(position.y);
                    packet.AddVar(position.z);
                    packet.AddVar(position.yaw);
                    packet.AddVar(position.pitch);
                }
                else
                {
                    if (delta.PosChanged())
                    {
                        if (delta.RotChanged())
                        {
                            //Pos AND Rot
                            packet.id = PacketType.PositionAndOrientationUpdate;
                            packet.AddVar(UserId);
                            packet.AddVar((byte)delta.x);
                            packet.AddVar((byte)delta.y);
                            packet.AddVar((byte)delta.z);
                            packet.AddVar(position.yaw);
                            packet.AddVar(position.pitch);

                        }
                        else
                        {
                            //TODO
                            //Just Pos
                            packet.id = PacketType.PositionUpdate;
                            packet.AddVar(UserId);
                            packet.AddVar((byte)delta.x);
                            packet.AddVar((byte)delta.y);
                            packet.AddVar((byte)delta.z);
                        }
                    }
                    else
                    {
                        if (delta.RotChanged())
                        {
                            packet.id = PacketType.OrientationUpdate;
                            packet.AddVar(UserId);
                            packet.AddVar(position.yaw);
                            packet.AddVar(position.pitch);
                        }
                    }
                }
            }

            foreach (Player p in level.players.ToArray())
            {
                if (p._isActive && p != this)
                {
                    p.SendPacket(packet);
                }
            }
        }
Esempio n. 2
0
 void SendSpawn(Player player)
 {
     Server.Log("Spawning " + player.UserId + " for " + UserId, LogTypesEnum.debug);
     Packet p = new Packet();
     p.id = PacketType.SpawnPlayer;
     p.AddVar(player.UserId);
     p.AddVar(player.username);
     p.AddVar(player.position.x);
     p.AddVar(player.position.y);
     p.AddVar(player.position.z);
     p.AddVar(player.position.yaw);
     p.AddVar(player.position.pitch);
     SendPacket(p);
 }
Esempio n. 3
0
        void SendTeleportThisPlayer(pos newPosition)
        {
            oldPosition = position;
            position = newPosition;

            Packet p = new Packet();
            p.id = PacketType.PositionAndOrientationTeleport;
            p.AddVar((byte)255);
            p.AddVar(position.x);
            p.AddVar(position.y);
            p.AddVar(position.z);
            p.AddVar(position.yaw);
            p.AddVar(position.pitch);
            SendPacket(p);
        }
Esempio n. 4
0
        void SendMotd()
        {
            string motd = Configuration.SERVER_MOTD;
            string name = Configuration.SERVER_NAME;

            Packet p = new Packet();
            p.id = PacketType.Identification;
            p.AddVar(PROTOCOL_VERSION);
            p.AddVar(name);
            p.AddVar(motd);
            if (isAdmin) p.AddVar((byte)100);
            else p.AddVar((byte)0);

            Server.Log("Send MOTD", LogTypesEnum.debug);
            SendPacket(p);
            //Console.WriteLine(p.bytes.Count);

            //byte[] buffer = new byte[130];
            //buffer[0] = PROTOCOL_VERSION;
            //StringFormat(Configuration.SERVER_NAME, 64).CopyTo(buffer, 1);
            //StringFormat(Configuration.SERVER_MOTD, 64).CopyTo(buffer, 65);
            //if (isAdmin)
            //    buffer[129] = 100;
            //else
            //    buffer[129] = 0;
            //SendRaw(0, buffer);
        }
Esempio n. 5
0
        void SendPacket(Packet p)
        {
            //Server.Log(p.id + " sending", LogTypesEnum.debug);
            byte[] data = new byte[p.bytes.Count + 1];
            data[0] = (byte)p.id;
            p.bytes.CopyTo(data, 1);

            SendRaw(data);
        }
Esempio n. 6
0
 void SendDie(Player player)
 {
     Packet p = new Packet();
     p.id = PacketType.DespawnPlayer;
     p.AddVar(player.UserId);
     SendPacket(p);
 }
Esempio n. 7
0
 void SendFullPosPacketTeleport(Player player)
 {
     Packet p = new Packet();
     p.id = PacketType.PositionAndOrientationTeleport;
     p.AddVar(player.UserId);
     p.AddVar(player.position.x);
     p.AddVar(player.position.y);
     p.AddVar(player.position.z);
     p.AddVar(player.position.yaw);
     p.AddVar(player.position.pitch);
     SendPacket(p);
 }
Esempio n. 8
0
 internal void SendMessage(string message)
 {
     Packet packet = new Packet();
     packet.id = PacketType.Message;
     packet.AddVar(UserId);
     packet.AddVar(message);
     SendPacket(packet);
 }
Esempio n. 9
0
 internal void SendKick(string message)
 {
     Packet p = new Packet();
     p.id = PacketType.Disconnect;
     p.AddVar(message);
     SendPacket(p);
 }
Esempio n. 10
0
 internal void SendBlockChange(ushort x, ushort y, ushort z, byte type)
 {
     Packet p = new Packet();
     p.id = PacketType.SetBlockOutgoing;
     p.AddVar(x);
     p.AddVar(y);
     p.AddVar(z);
     p.AddVar(type);
     SendPacket(p);
 }
Esempio n. 11
0
        internal static void SendLevelChat(Player player, string message)
        {
            string username = player.username;

            string toSend = "<" + username + ">: " + message;

            Server.Log("!" + toSend, LogTypesEnum.chat);

            Packet packet = new Packet();
            packet.id = PacketType.Message;
            packet.AddVar(player.UserId);
            packet.AddVar(toSend);

            foreach (Player p in player.level.players.ToArray())
            {
                if (p._isActive)
                {
                    p.SendPacket(packet);
                }
            }
        }
Esempio n. 12
0
        internal static void SendGlobalMessage(string message)
        {
            Server.Log("!" + message, LogTypesEnum.chat);

            Packet packet = new Packet();
            packet.id = PacketType.Message;
            packet.AddVar((byte)0);
            packet.AddVar(message);

            foreach (Player p in PlayerHandler.Players.Values.ToArray())
            {
                if (p._isActive)
                {
                    p.SendPacket(packet);
                }
            }
        }