Example #1
0
 public Chunk GetChunk(PointInt p)
 {
     if (!Chunks.ContainsKey(p))
     {
         Chunks.Add(p, new Chunk(GetChunkPath(p)));
     }
     return Chunks[p];
 }
Example #2
0
 public List<Chunk> GetChunks(PointInt p)
 {
     int x = p.X + 3;
     int z = p.Z + 3;
     List<Chunk> chunks = new List<Chunk>();
     for (int a = x - 6; a <= x; ++a)
     {
         for (int b = z - 6; b <= z; ++b)
         {
             chunks.Add(GetChunk(new PointInt() { X = a, Z = b }));
         }
     }
     return chunks;
 }
Example #3
0
        public string GetChunkPath(PointInt p)
        {
            // TODO: Check path seperators? ROFL

            StringBuilder builder = new StringBuilder();
            builder.Append(MinecraftServer.Instance.Path);
            builder.Append(Base36.Parse(p.X & 63));
            builder.Append("/");
            builder.Append(Base36.Parse(p.Z & 63));
            builder.Append("/c.");
            builder.Append(Base36.Parse(p.X));
            builder.Append(".");
            builder.Append(Base36.Parse(p.Z));
            builder.Append(".dat");
            return builder.ToString();
        }
Example #4
0
        public Chunk(string path)
        {
            Path = path;

            using (NBTFile file = NBTFile.Open(Path))
            {
                Data = (byte[])file.FindPayload("Data");
                //TODO: Parse Entities
                //Entities = (List<IEntity>)file.FindPayload("Entities");
                LastUpdate = (long)file.FindPayload("LastUpdate");
                Position = new PointInt() { X = (int) file.FindPayload("xPos"), Z = (int) file.FindPayload("zPos")};
                //TODO: Parse more entities
                //TileEntities = (List<IEntity>)file.FindPayload("TileEntities");
                TerrainPopulated = (byte)file.FindPayload("TerrainPopulated");
                SkyLight = (byte[])file.FindPayload("SkyLight");
                HeightMap = (byte[])file.FindPayload("HeightMap");
                BlockLight = (byte[])file.FindPayload("BlockLight");
                Blocks = (byte[])file.FindPayload("Blocks");
            }
        }
Example #5
0
        public void Run()
        {
            ReloadConfiguration();
            ReloadAdministrators();

            SessionLock();

            Watcher = new FileSystemWatcher(_Path, "session.lock");
            Watcher.Changed += new FileSystemEventHandler(Watcher_Changed);

            using (NBTFile levelFile = NBTFile.Open(_Path + "level.dat"))
            {
                SpawnPosition = new PointInt() { X = (int)levelFile.FindPayload("SpawnX"), Y = (short)(int)levelFile.FindPayload("SpawnY"), Z = (int)levelFile.FindPayload("SpawnZ") };

                RandomSeed = (long)levelFile.FindPayload("RandomSeed");
            }

            PacketRegistry = new MinecraftPacketRegistry();
            CommandManager = new CommandManager();
            ChunkManager = new ChunkManager();

            //Socket
            try
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, Port);

                Server.Bind(endPoint);
                Server.Listen(10);
                Log.Info("Socket server bound and listing at {0}.", endPoint);

                while (ResetEvent.WaitOne())
                {
                    Server.BeginAccept(OnAccept, null);
                }
                // TODO: Research SendAsync and related functions
            }
            catch (Exception e)
            {
                Log.Error(e, "Unable to initialize socket server.");
            }
        }
 public static byte[] GetSpawnPosition(PointInt position)
 {
     using (MinecraftPacketStream stream = new MinecraftPacketStream())
     {
         stream.WriteByte((byte)MinecraftOpcode.SpawnPosition);
         stream.WriteInt(position.X);
         stream.WriteInt(position.Y);
         stream.WriteInt(position.Z);
         return stream.ToArray();
     }
 }