예제 #1
0
파일: World.cs 프로젝트: serh39/uMiner
 public bool SetTile(int x, int y, int z, byte type)
 {
     if (x < 0 || y < 0 || z < 0 || x >= this.width || y >= this.height || z >= this.depth || type < 0 || !Blocks.blockNames.ContainsValue(type))
     {
         return(false);
     }
     //Handle basic physics tiles
     if (Blocks.BasicPhysics(type))
     {
         /*if (Blocks.AffectedByGravity(type))
          * {
          *  Program.server.physics.SandGravelFall(x, y, z, type);
          *  return true;
          * }
          * if (Blocks.AffectedBySponges(type) && Program.server.physics.FindSponge(x, y, z))
          * {
          *  return false;
          * }*/
         Program.server.physics.Queue(x, y, z, type);
     }
     //Handle sponge deletion
     if (GetTile(x, y, z) == Blocks.sponge && type == 0)
     {
         Program.server.physics.DeleteSponge(x, y, z);
     }
     this.blocks[(y * this.depth + z) * this.width + x] = type;
     Player.GlobalBlockchange((short)x, (short)y, (short)z, Blocks.ConvertType(type));
     return(true);
 }
예제 #2
0
파일: World.cs 프로젝트: serh39/uMiner
 public bool SetTileNoPhysics(int x, int y, int z, byte type)
 {
     if (x < 0 || y < 0 || z < 0 || x >= this.width || y >= this.height || z >= this.depth || type < 0 || !Blocks.blockNames.ContainsValue(type))
     {
         return(false);
     }
     this.blocks[(y * this.depth + z) * this.width + x] = type;
     Player.GlobalBlockchange((short)x, (short)y, (short)z, Blocks.ConvertType(type));
     return(true);
 }
예제 #3
0
파일: World.cs 프로젝트: serh39/uMiner
        public void Save()
        {
            try
            {
                byte[] saveblocks = new byte[blocks.Length];
                blocks.CopyTo(saveblocks, 0);
                for (int i = 0; i < saveblocks.Length; i++)
                {
                    switch (saveblocks[i])
                    {
                    case Blocks.unflood:
                        saveblocks[i] = Blocks.ConvertType(saveblocks[i]);
                        break;

                    default:
                        break;
                    }
                }

                GZipStream gzout = new GZipStream(new FileStream("maps/" + filename, FileMode.OpenOrCreate), CompressionMode.Compress);
                gzout.Write(BitConverter.GetBytes(0xebabefac), 0, 4);
                gzout.Write(BitConverter.GetBytes(width), 0, 2);
                gzout.Write(BitConverter.GetBytes(height), 0, 2);
                gzout.Write(BitConverter.GetBytes(depth), 0, 2);
                gzout.Write(BitConverter.GetBytes(spawnx), 0, 2);
                gzout.Write(BitConverter.GetBytes(spawny), 0, 2);
                gzout.Write(BitConverter.GetBytes(spawnz), 0, 2);
                gzout.WriteByte(this.srotx);
                gzout.WriteByte(this.sroty);
                gzout.Write(saveblocks, 0, saveblocks.Length);

                //gzout.BaseStream.Close();
                gzout.Close();
                Program.server.logger.log("Level \"" + this.name + "\" saved");
            }
            catch (Exception e)
            {
                Program.server.logger.log("Error occurred while saving map", Logger.LogType.Error);
                Program.server.logger.log(e);
            }
        }
예제 #4
0
        /*public void SendMap(ref byte[] leveldata, short width, short height, short depth)
         * {
         *  try
         *  {
         *      byte[] buffer = new byte[leveldata.Length + 4];
         *      BitConverter.GetBytes(IPAddress.HostToNetworkOrder(leveldata.Length)).CopyTo(buffer, 0);
         *      for (int i = 0; i < leveldata.Length; ++i)
         *      {
         *          buffer[4 + i] = leveldata[i];
         *      }
         *      buffer = GZip(buffer);
         *      int number = (int)Math.Ceiling(((double)buffer.Length) / 1024);
         *      for (int i = 1; buffer.Length > 0; ++i)
         *      {
         *          Packet chunk = new Packet(1028);
         *          short length = (short)Math.Min(buffer.Length, 1024);
         *          chunk.Append((byte)ServerPacket.MapChunk);
         *          chunk.Append(length);
         *          chunk.Append(byteArraySlice(ref buffer, 0, length));
         *          for (short j = length; j < 1024; j++)
         *          {
         *              chunk.Append((byte)0);
         *          }
         *          byte[] tempbuffer = new byte[buffer.Length - length];
         *          Buffer.BlockCopy(buffer, length, tempbuffer, 0, buffer.Length - length);
         *          buffer = tempbuffer;
         *          chunk.Append((byte)((i * 100.0) / number));
         *          this.SendPacket(chunk);
         *          System.Threading.Thread.Sleep(1);
         *      }
         *      Packet mapFinal = new Packet(7);
         *      mapFinal.Append((byte)ServerPacket.MapFinal);
         *      mapFinal.Append((short)width);
         *      mapFinal.Append((short)depth);
         *      mapFinal.Append((short)height);
         *      this.SendPacket(mapFinal);
         *
         *      //Spawn player
         *      this.SpawnPlayer(this, true);
         *      this.SendSpawn(new short[3] { 8 * 32 + 16, 64, 8 * 32 + 16 }, new byte[2] { 0, 0 });
         *
         *      //Spawn other players
         *      foreach (Player p in Program.server.playerlist)
         *      {
         *          if (p != null && p.loggedIn && p != this)
         *          {
         *              this.SpawnPlayer(p, false);
         *          }
         *      }
         *
         *      //Spawn self
         *      GlobalSpawnPlayer(this);
         *  }
         *  catch (IOException) { }
         *  catch (SocketException) { }
         *  catch (Exception e) { Program.server.logger.log(e); }
         *
         * } */

        public void SendMap(World w)
        {
            try
            {
                byte[] buffer = new byte[w.blocks.Length + 4];
                BitConverter.GetBytes(IPAddress.HostToNetworkOrder(w.blocks.Length)).CopyTo(buffer, 0);
                for (int i = 0; i < w.blocks.Length; ++i)
                {
                    buffer[4 + i] = Blocks.ConvertType(w.blocks[i]);
                }
                buffer = GZip(buffer);
                int number = (int)Math.Ceiling(((double)buffer.Length) / 1024);
                for (int i = 1; buffer.Length > 0; ++i)
                {
                    Packet chunk  = new Packet(1028);
                    short  length = (short)Math.Min(buffer.Length, 1024);
                    chunk.Append((byte)ServerPacket.MapChunk);
                    chunk.Append(length);
                    chunk.Append(byteArraySlice(ref buffer, 0, length));
                    for (short j = length; j < 1024; j++)
                    {
                        chunk.Append((byte)0);
                    }
                    byte[] tempbuffer = new byte[buffer.Length - length];
                    Buffer.BlockCopy(buffer, length, tempbuffer, 0, buffer.Length - length);
                    buffer = tempbuffer;
                    chunk.Append((byte)((i * 100.0) / number));
                    this.SendPacket(chunk);
                    System.Threading.Thread.Sleep(1);
                }
                Packet mapFinal = new Packet(7);
                mapFinal.Append((byte)ServerPacket.MapFinal);
                mapFinal.Append(w.width);
                mapFinal.Append(w.height);
                mapFinal.Append(w.depth);
                this.SendPacket(mapFinal);

                //Spawn player (convert map coordinates to player coordinates and set player pos)
                this.x    = (short)(w.spawnx << 5);
                this.y    = (short)(w.spawny << 5);
                this.z    = (short)(w.spawnz << 5);
                this.rotx = w.srotx;
                this.roty = w.sroty;
                this.SpawnPlayer(this, true);

                //Spawn other players
                foreach (Player p in Program.server.playerlist)
                {
                    if (p != null && p.loggedIn && p != this)
                    {
                        this.SpawnPlayer(p, false);
                    }
                }

                //Spawn self
                GlobalSpawnPlayer(this);

                this.world = w;
            }
            catch (IOException) { }
            catch (SocketException) { }
            catch (Exception e) { Program.server.logger.log(e); }
        }