Beispiel #1
0
func NewGame(worldPath string) (game *Game, err os.Error) {
	worldStore, err := worldstore.LoadWorldStore(worldPath)
	if err != nil {
		return nil, err
	}

	game = &Game{
		players:          make(map[EntityId]*player.Player),
		playerNames:      make(map[string]*player.Player),
		workQueue:        make(chan func(*Game), 256),
		playerConnect:    make(chan *player.Player),
		playerDisconnect: make(chan EntityId),
		time:             worldStore.Time,
		worldStore:       worldStore,
	}

	game.entityManager.Init()

	game.serverId = fmt.Sprintf("%016x", rand.NewSource(worldStore.Seed).Int63())
	//game.serverId = "-"

	game.shardManager = shardserver.NewLocalShardManager(worldStore.ChunkStore, &game.entityManager)

	// TODO: Load the prefix from a config file
	gamerules.CommandFramework = command.NewCommandFramework("/")

	go game.mainLoop()
	return
}
Beispiel #2
0
func cmdChunk(args []string) (err error) {
	if len(args) < 3 || len(args) > 4 {
		os.Stderr.WriteString("usage: " + os.Args[0] + " chunk <world path> <chunk x> <chunk z> [dimension]\n")
		return
	}

	worldPath := args[0]
	x, err := strconv.Atoi(args[1])
	if err != nil {
		return
	}
	z, err := strconv.Atoi(args[2])
	if err != nil {
		return
	}

	dimension := DimensionNormal
	if len(args) >= 4 {
		var dimInt int
		dimInt, err = strconv.Atoi(args[3])
		if err != nil {
			return
		}
		dimension = DimensionId(dimInt)
	}

	worldStore, err := worldstore.LoadWorldStore(worldPath)
	if err != nil {
		return
	}

	chunkLoc := ChunkXz{ChunkCoord(x), ChunkCoord(z)}

	store, err := worldStore.ChunkStoreForDimension(dimension)
	if err != nil {
		return
	}

	chunkResult := <-store.ReadChunk(chunkLoc)
	if chunkResult.Err != nil {
		return chunkResult.Err
	}

	fmt.Printf("Chunk %#v data:\n", chunkLoc)
	displayNbt(1, chunkResult.Reader.RootTag())

	return
}
Beispiel #3
0
func cmdLevel(args []string) (err error) {
	if len(args) != 1 {
		os.Stderr.WriteString("usage: " + os.Args[0] + " level <world path>\n")
		return
	}

	worldPath := args[0]

	worldStore, err := worldstore.LoadWorldStore(worldPath)
	if err != nil {
		return
	}

	displayNbt(1, worldStore.LevelData)

	return
}
Beispiel #4
0
func NewGame(worldPath string, listener net.Listener, serverDesc, maintenanceMsg string, maxPlayerCount int) (game *Game, err error) {
	worldStore, err := worldstore.LoadWorldStore(worldPath)
	if err != nil {
		return nil, err
	}

	authserver, err := server_auth.NewServerAuth("http://www.minecraft.net/game/checkserver.jsp")
	if err != nil {
		return
	}

	game = &Game{
		players:          make(map[EntityId]*player.Player),
		playerNames:      make(map[string]*player.Player),
		workQueue:        make(chan func(*Game), 256),
		playerConnect:    make(chan *player.Player),
		playerDisconnect: make(chan EntityId),
		time:             worldStore.Time,
		worldStore:       worldStore,
	}

	game.entityManager.Init()

	game.serverId = fmt.Sprintf("%016x", rand.NewSource(worldStore.Seed).Int63())
	//game.serverId = "-"

	game.shardManager = shardserver.NewLocalShardManager(worldStore.ChunkStore, &game.entityManager)

	// TODO: Load the prefix from a config file
	gamerules.CommandFramework = command.NewCommandFramework("/")

	// Start accepting connections.
	game.connHandler = NewConnHandler(listener, &GameInfo{
		game:           game,
		maxPlayerCount: maxPlayerCount,
		serverDesc:     serverDesc,
		maintenanceMsg: maintenanceMsg,
		serverId:       game.serverId,
		shardManager:   game.shardManager,
		entityManager:  &game.entityManager,
		worldStore:     game.worldStore,
		authserver:     authserver,
	})

	return
}