Example #1
0
func (s *chunkStoreBeta) LoadChunk(chunkLoc ChunkXz) (reader IChunkReader, err os.Error) {
	regionLoc := regionLocForChunkXz(chunkLoc)

	var cfr *regionFileReader
	cfr, ok := s.regionFiles[regionLoc.regionKey()]
	if !ok {
		// TODO limit number of regionFileReader objs to a maximum number of
		// most-frequently-used regions. Close regionFileReader objects when no
		// longer needed.
		filePath := regionLoc.regionFilePath(s.regionPath)
		cfr, err = newRegionFileReader(filePath)
		if err != nil {
			if errno, ok := util.Errno(err); ok && errno == os.ENOENT {
				err = NoSuchChunkError(false)
			}
			return
		}
		s.regionFiles[regionLoc.regionKey()] = cfr
	}

	chunkReader, err := cfr.ReadChunkData(chunkLoc)
	if chunkReader != nil {
		reader = chunkReader
	}

	return
}
Example #2
0
func (s *chunkStoreAlpha) LoadChunk(chunkLoc ChunkXz) (reader IChunkReader, err os.Error) {
	file, err := os.Open(s.chunkPath(chunkLoc))
	if err != nil {
		if errno, ok := util.Errno(err); ok && errno == os.ENOENT {
			err = NoSuchChunkError(false)
		}
		return
	}
	defer file.Close()

	gzipReader, err := gzip.NewReader(file)
	if err != nil {
		return
	}
	defer gzipReader.Close()
	reader, err = newNbtChunkReader(gzipReader)
	if err != nil {
		return
	}

	loadedLoc := reader.ChunkLoc()
	if loadedLoc.X != chunkLoc.X || loadedLoc.Z != chunkLoc.Z {
		err = os.NewError(fmt.Sprintf(
			"Attempted to load chunk for %+v, but got chunk identified as %+v",
			chunkLoc,
			loadedLoc,
		))
	}

	return
}
Example #3
0
func (world *WorldStore) PlayerData(user string) (playerData nbt.ITag, err os.Error) {
	file, err := os.Open(path.Join(world.WorldPath, "players", user+".dat"))
	if err != nil {
		if errno, ok := util.Errno(err); ok && errno == os.ENOENT {
			// Player data simply doesn't exist. Not an error, playerData = nil is
			// the result.
			return nil, nil
		}
		return
	}
	defer file.Close()

	gzipReader, err := gzip.NewReader(file)
	if err != nil {
		return
	}
	defer gzipReader.Close()

	playerData, err = nbt.Read(gzipReader)

	return
}