Beispiel #1
0
 internal void SendLevel(Level level)
 {
     if (status != OnlineStatus.Identified)
     {
         return;
     }
     this.level = level;
     status     = OnlineStatus.Loading;
     new Thread(
         delegate() {
         Protocol.MapBeginPacket().Send(this);
         byte[] gzipped = Utility.GZipper.GZip(
             BitConverter.GetBytes(
                 IPAddress.HostToNetworkOrder(level.Mapdata.Length)
                 ), level.Mapdata);
         for (int i = 0; i < gzipped.Length; i += 1024)
         {
             byte progress = (byte)((i / 1024 + 1) / Math.Ceiling(gzipped.Length / 1024d) * 100);
             Protocol.MapPartPacket(gzipped, i, progress).Send(this);
         }
         Protocol.MapEndPacket(level.Width, level.Depth, level.Height).Send(this);
         ReadyEvent.Raise(server, this);
         Spawn(level.Spawn);
         foreach (Body b in level.Bodies)
         {
             Protocol.SpawnPacket(b).Send(this);
         }
         Position.Set(level.Spawn);
         Visible = true;
         status  = OnlineStatus.Ready;
         level.players.Add(this);
     }).Start();
 }
Beispiel #2
0
 private void OnMove(byte id, ushort x, ushort y, ushort z, byte rotx, byte roty)
 {
     if (status != OnlineStatus.Ready)
     {
         return;
     }
     Position.Set(x, y, z, rotx, roty);
 }
Beispiel #3
0
        internal void Update()
        {
            if (!visible)
            {
                return;
            }
            Packet packet = null;
            bool   posChanged = false, farChanged = false, rotChanged = false;

            if (position.X != oldpos.X || position.Y != oldpos.Y || position.Z != oldpos.Z)
            {
                posChanged = true;
            }
            if (position.RotX != oldpos.RotX || position.RotY != oldpos.RotY)
            {
                rotChanged = true;
            }
            if (Math.Abs((int)position.X - oldpos.X) > 127 || Math.Abs((int)position.Y - oldpos.Y) > 127 ||
                Math.Abs((int)position.Z - oldpos.Z) > 127)
            {
                farChanged = true;
            }
            if (farChanged)
            {
                packet = Protocol.TeleportPacket(id, Position);
            }
            else if (posChanged && rotChanged)
            {
                unchecked {
                    packet = Protocol.MoveLookPacket(
                        id, (byte)(position.X - oldpos.X), (byte)(position.Y - oldpos.Y),
                        (byte)(position.Z - oldpos.Z), position.RotX, position.RotY);
                }
            }
            else if (posChanged)
            {
                unchecked {
                    packet = Protocol.MovePacket(
                        id, (byte)(position.X - oldpos.X), (byte)(position.Y - oldpos.Y), (byte)(position.Z - oldpos.Z));
                }
            }
            else if (rotChanged)
            {
                packet = Protocol.LookPacket(id, position.RotX, position.RotY);
            }
            if (packet != null)
            {
                oldpos.Set(position);
                packet.Send(level);
                MoveEvent.Raise(level.server, this);
            }
        }