コード例 #1
0
ファイル: Manager.go プロジェクト: toophy/go-gameserver
func loadMoves(_hood *hood.Hood) {
	log.Verbose("Pokemon.Manager", "loadMoves", "Loading pokemon moves from database")

	var moves []entities.Move
	if err := _hood.Find(&moves); err != nil {
		log.Error("Pokemon.Manager", "loadMoves", "Error while loading moves: %s", err.Error())
	} else {
		for _, moveEntity := range moves {
			move := NewMove(&moveEntity)
			movesStore[move.GetMoveId()] = move
		}
	}
}
コード例 #2
0
ファイル: Manager.go プロジェクト: toophy/go-gameserver
func loadPokemon(_hood *hood.Hood) {
	log.Verbose("Pokemon.Manager", "loadPokemon", "Loading pokemon from database")

	var pokemon []entities.Pokemon
	if err := _hood.Find(&pokemon); err != nil {
		log.Error("Pokemon.Manager", "loadPokemon", "Error while loading pokemon: %s", err.Error())
	} else {
		for _, pokemonEntity := range pokemon {
			poke := NewPokemon(&pokemonEntity)

			if err := poke.LinkMoves(_hood); err != nil {
				log.Error("Pokemon.Manager", "loadPokemon", "Failed to link moves to Pokemon %d. Error: %s", poke.GetPokemonId(), err.Error())
			} else {
				pokemonStore[poke.GetPokemonId()] = poke
			}
		}
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: toophy/go-gameserver
func initializeDatabase() {
	log.Verbose("main", "initializeDatabase", "Creating database connection")

	username, _ := configuration.GetString(config.CONFIG_DB_USER)
	password, _ := configuration.GetString(config.CONFIG_DB_PASSWORD)
	scheme, _ := configuration.GetString(config.CONFIG_DB_SCHEME)
	connectionString := fmt.Sprintf("%v/%v/%v", scheme, username, password)

	hd, err := hood.Open("mymysql", connectionString)
	if err != nil {
		log.Error("main", "initializeDatabase", "Unable to connect to database scheme '%s' with supplied credentials '%s'", scheme, username)
		panic("Unable to connect to database")
	}
	hd.Log = DEBUG_SQL

	mainDatabase = hd

	log.Info("main", "initializeDatabase", "Database connection initialized: %s", connectionString)
}