Esempio n. 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
}
Esempio n. 2
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
}