func readConfiguration() { // Set configuration provider configuration.SetConfigurationProvider(providers.NewIniConfigProvider("serverconfig.ini")) // Add configuration items configuration.AddConfigurationItems(config.NewServerConfigItems()) configuration.Initialize() log.Info("main", "readConfiguration", "Configuration initialized") }
// Start listening for new connections func Listen(_port int) { gameserver.port = _port log.Info("GameServer", "Listen", "Listening for connections on port: %d", _port) http.Handle("/puserver", websocket.Handler(clientConnection)) err := http.ListenAndServe(fmt.Sprintf(":%d", _port), nil) if err != nil { panic("ListenAndServe: " + err.Error()) } }
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) }
// Waits for all spawned process routines to finish // This can take a while if there are alot of tiles func waitForLoadComplete() { completedRoutines := 0 count := 0 spinner := []string{"|", "/", "-", "\\", "|", "/", "-", "\\"} for { select { case <-processExitChan: completedRoutines++ if completedRoutines == numOfProcessRoutines { log.Info("World", "LoadWorldmap", "Loading complete") break } case <-time.After(time.Millisecond * 200): fmt.Printf("\rLoading worldmap %s\r", spinner[count]) count++ if count > 7 { count = 0 } } } }