Beispiel #1
0
 private void SendSpawn(Player player)
 {
     Server.Log("Spawning " + player.UserId + " for " + UserId, LogTypesEnum.Debug);
     var p = new Packet {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);
 }
Beispiel #2
0
        private void SendMotd()
        {
            string motd = Configuration.ServerMotd;
            string name = Configuration.ServerName;

            var p = new Packet {Id = PacketType.Identification};
            p.AddVar(ProtocolVersion);
            p.AddVar(name);
            p.AddVar(motd);
            p.AddVar((byte) (IsAdmin ? 100 : 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);
        }
Beispiel #3
0
        private void SendPacket(Packet p)
        {
            //Server.Log(p.id + " sending", LogTypesEnum.debug);
            var data = new byte[p.Bytes.Count + 1];
            data[0] = (byte) p.Id;
            p.Bytes.CopyTo(data, 1);

            SendRaw(data);
        }
Beispiel #4
0
        private static void SendGlobalMessageActual(string message)
        {
            var packet = new Packet { Id = PacketType.Message };
            packet.AddVar(0);
            packet.AddVar(message);

            foreach (Player p in PlayerHandler.Players.Values.ToArray())
            {
                if (p.IsActive)
                {
                    p.SendPacket(packet);
                }
            }
        }
Beispiel #5
0
 private void SendDie(Player player)
 {
     var p = new Packet {Id = PacketType.DespawnPlayer};
     p.AddVar(player.UserId);
     SendPacket(p);
 }
Beispiel #6
0
 internal void SendBlockChange(ushort x, ushort y, ushort z, byte type)
 {
     var p = new Packet {Id = PacketType.SetBlockOutgoing};
     p.AddVar(x);
     p.AddVar(y);
     p.AddVar(z);
     p.AddVar((Block.Blocks.ContainsKey(type) ? Block.Blocks[type].BaseType : (byte)0));
     SendPacket(p);
 }
Beispiel #7
0
 internal void SendKick(string message)
 {
     var p = new Packet {Id = PacketType.Disconnect};
     p.AddVar(message);
     SendPacket(p);
 }
Beispiel #8
0
        internal static void SendLevelChat(Player player, string message)
        {
            string toSend = player.Tag + ": " + message;

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

            var packet = new 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);
                }
            }

            if(true)
            {

            }
        }
Beispiel #9
0
 public void SendMessage(string message)
 {
     var packet = new Packet {Id = PacketType.Message};
     packet.AddVar(UserId);
     packet.AddVar(message);
     SendPacket(packet);
 }
Beispiel #10
0
        private void UpdatePlayerPos()
        {
            if (_isInvisible) return;

            var packet = new Packet();

            if (_delta.IsZero())
            {
                return;
            }
            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
                    {
                        //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);
                }
            }
        }
Beispiel #11
0
        /*
        private void SendFullPosPacketTeleport(Player player)
        {
            var p = new Packet {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);
        }
        */
        private void SendTeleportThisPlayer(Pos newPosition)
        {
            OldPosition = Position;
            Position = newPosition;

            newPosition.X = 64;
            newPosition.Y = 64;
            newPosition.Z = 64;

            var p = new Packet {Id = PacketType.PositionAndOrientationTeleport};
            p.AddVar(255);
            p.AddVar(Position.X);
            p.AddVar(Position.Y);
            p.AddVar(Position.Z);
            p.AddVar(Position.Yaw);
            p.AddVar(Position.Pitch);
            SendPacket(p);
        }
Beispiel #12
0
        internal static void SendGlobalMessage(string message)
        {
            Server.Log("!" + message, LogTypesEnum.Chat);

            var packet = new Packet {Id = PacketType.Message};
            packet.AddVar(0);
            packet.AddVar(message);

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