Esempio n. 1
0
func main() {
	helpers.InitLogger()
	config.SetupConstants()

	if config.Constants.ProfilerEnable {
		address := "localhost:" + config.Constants.ProfilerPort
		go func() {
			graceful.Run(address, 1*time.Second, nil)
		}()
		helpers.Logger.Debug("Running Profiler at %s", address)
	}

	pid := &pid.Instance{}
	if pid.Create() == nil {
		defer pid.Remove()
	}

	authority.RegisterTypes()
	helpers.InitAuthorization()
	database.Init()
	migrations.Do()
	stores.SetupStores()
	models.PaulingConnect()
	models.FumbleConnect()
	models.InitializeLobbySettings("./lobbySettingsData.json")

	StartPaulingListener()
	chelpers.InitDB()
	if config.Constants.SteamIDWhitelist != "" {
		go chelpers.WhitelistListener()
	}
	// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)
	helpers.Logger.Debug("Starting the server")

	// init http server

	// init socket.io server
	server := wsevent.NewServer()
	nologin := wsevent.NewServer()

	broadcaster.Init(server, nologin)
	socket.ServerInit(server, nologin)
	routes.SetupHTTPRoutes(server, nologin)

	if val := os.Getenv("DEPLOYMENT_ENV"); strings.ToLower(val) != "production" {
		// init static FileServer
		// TODO be careful to set this to correct location when deploying
		http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, r.URL.Path[1:])
		})
	}
	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   config.Constants.AllowedCorsOrigins,
		AllowCredentials: true,
	}).Handler(http.DefaultServeMux)

	// start the server
	helpers.Logger.Debug("Serving at %s", config.Constants.Domain)
	graceful.Run(":"+config.Constants.Port, 1*time.Second, corsHandler)
}
Esempio n. 2
0
func TestServerSetup(t *testing.T) {
	if shouldTestLive {
		config.SetupConstants()
		InitServerConfigs()

		commId := "76561198067132047" // your commId, so it wont be kicking you out everytime

		info := ServerRecord{
			Host:         host,
			RconPassword: password,
		}

		svr = NewServer()
		svr.Map = "cp_process_final"
		svr.Type = LobbyTypeHighlander
		svr.League = LeagueUgc
		svr.ServerPassword = "******"
		svr.Info = info

		svr.AllowPlayer(commId)

		setupErr := svr.Setup()
		assert.Nil(t, setupErr, "Setup error")

		playerIsAllowed := svr.IsPlayerAllowed(commId)
		assert.True(t, playerIsAllowed, "Player isn't allowed, he should")

		svr.DisallowPlayer(commId)

		playerIsntAllowed := svr.IsPlayerAllowed(commId)
		assert.False(t, playerIsntAllowed, "Player is allowed, he shouldn't")

		svr.End()
	}
}
Esempio n. 3
0
func CleanupDB() {
	cleaningMutex.Lock()
	defer cleaningMutex.Unlock()

	o.Do(func() {
		os.Setenv("DEPLOYMENT_ENV", "test")
		config.SetupConstants()
		database.Init()
		authority.RegisterTypes()
		migrations.Do()
		stores.SetupStores()
	})

	tables := []string{
		"admin_log_entries",
		"banned_players_lobbies",
		"chat_messages",
		"http_sessions",
		"lobbies",
		"lobby_slots",
		"player_bans",
		"player_settings",
		"player_stats",
		"players",
		"server_records",
		"spectators_players_lobbies",
		"requirements",
	}
	for _, table := range tables {
		database.DB.Exec("TRUNCATE TABLE " + table + " RESTART IDENTITY")
	}

}
Esempio n. 4
0
func TestDatabasePing(t *testing.T) {
	if os.Getenv("DEPLOYMENT_ENV") == "" {
		os.Setenv("DEPLOYMENT_ENV", "test")
		defer os.Unsetenv("DEPLOYMENT_ENV")
	}
	config.SetupConstants()

	helpers.Logger.Debug("[Test.Database] IsTest? " + strconv.FormatBool(IsTest))
	Init()
	assert.Nil(t, DB.DB().Ping())
}
Esempio n. 5
0
func TestCleanup() {
	if os.Getenv("DEPLOYMENT_ENV") == "" {
		os.Setenv("DEPLOYMENT_ENV", "test")
		defer os.Unsetenv("DEPLOYMENT_ENV")
	}
	config.SetupConstants()
	database.Init()

	database.DB.Exec("DROP SCHEMA public CASCADE;")
	database.DB.Exec("CREATE SCHEMA public;")

	Do()
}
Esempio n. 6
0
func CleanupDB() {
	cleaningMutex.Lock()
	defer cleaningMutex.Unlock()
	if os.Getenv("DEPLOYMENT_ENV") == "" {
		os.Setenv("DEPLOYMENT_ENV", "test")
		defer os.Unsetenv("DEPLOYMENT_ENV")
	}
	config.SetupConstants()
	database.Init()

	database.DB.Exec("DROP SCHEMA public CASCADE;")
	database.DB.Exec("CREATE SCHEMA public;")

	migrations.Do()

	stores.SetupStores()
}
Esempio n. 7
0
File: main.go Progetto: N1xx1/Helen
func main() {
	authority.RegisterTypes()
	helpers.InitLogger()
	helpers.InitAuthorization()
	config.SetupConstants()
	database.Init()
	migrations.Do()
	stores.SetupStores()
	models.PaulingConnect()
	go models.ReadyTimeoutListener()
	StartListener()
	chelpers.CheckLogger()
	if config.Constants.SteamIDWhitelist != "" {
		chelpers.InitSteamIDWhitelist(config.Constants.SteamIDWhitelist)
	}
	// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)
	helpers.Logger.Debug("Starting the server")

	// init http server
	routes.SetupHTTPRoutes()

	// init socket.io server
	socketServer, err := socketio.NewServer(nil)
	if err != nil {
		helpers.Logger.Fatal(err.Error())
	}
	broadcaster.Init(socketServer)
	defer broadcaster.Stop()
	routes.SetupSocketRoutes(socketServer)
	http.Handle("/socket.io/", socketServer)

	// init static FileServer
	// TODO be careful to set this to correct location when deploying
	http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, r.URL.Path[1:])
	})
	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   config.Constants.AllowedCorsOrigins,
		AllowCredentials: true,
	}).Handler(http.DefaultServeMux)

	// start the server
	helpers.Logger.Debug("Serving at localhost:" + config.Constants.Port + "...")
	graceful.Run(":"+config.Constants.Port, 10*time.Second, corsHandler)
}
Esempio n. 8
0
func main() {
	helpers.InitLogger()
	config.SetupConstants()
	database.Init()
	migrations.Do()
	stores.SetupStores()
	models.InitServerConfigs()

	// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)
	helpers.Logger.Debug("Starting the server")

	r := mux.NewRouter()

	// init http server
	routes.SetupHTTPRoutes(r)
	http.Handle("/", r)

	// init socket.io server
	socketServer, err := socketio.NewServer(nil)
	if err != nil {
		helpers.Logger.Fatal(err.Error())
	}
	socket.InitBroadcaster(socketServer)
	routes.SetupSocketRoutes(socketServer)
	r.Handle("/socket.io/", socketServer)

	// init static FileServer
	// TODO be careful to set this to correct location when deploying
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/",
		http.FileServer(http.Dir(config.Constants.StaticFileLocation))))

	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   config.Constants.AllowedCorsOrigins,
		AllowCredentials: true,
	}).Handler(r)

	// start the server
	helpers.Logger.Debug("Serving at localhost:" + config.Constants.Port + "...")
	graceful.Run(":"+config.Constants.Port, 10*time.Second, corsHandler)
}
Esempio n. 9
0
func TestInitConfigs(t *testing.T) {
	config.SetupConstants()
	InitServerConfigs()
}
Esempio n. 10
0
func main() {
	helpers.InitLogger()

	flag.Parse()
	if *flagGen {
		key := securecookie.GenerateRandomKey(64)
		if len(key) == 0 {
			logrus.Fatal("Couldn't generate random key")
		}

		base64Key := base64.StdEncoding.EncodeToString(key)
		fmt.Println(base64Key)
		return
	}

	config.SetupConstants()
	go rpc.StartRPC()

	if config.Constants.ProfilerEnable {
		address := "localhost:" + config.Constants.ProfilerPort
		go func() {
			graceful.Run(address, 1*time.Second, nil)
		}()
		logrus.Info("Running Profiler at %s", address)
	}

	pid := &pid.Instance{}
	if pid.Create() == nil {
		defer pid.Remove()
	}

	authority.RegisterTypes()
	helpers.InitAuthorization()
	database.Init()
	migrations.Do()
	stores.SetupStores()
	models.InitializeLobbySettings("./lobbySettingsData.json")

	models.ConnectRPC()
	models.DeleteUnusedServerRecords()
	go models.Ping()

	chelpers.InitGeoIPDB()
	if config.Constants.SteamIDWhitelist != "" {
		go chelpers.WhitelistListener()
	}
	// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)

	mux := http.NewServeMux()
	routes.SetupHTTP(mux)
	socket.RegisterHandlers()

	if val := os.Getenv("DEPLOYMENT_ENV"); strings.ToLower(val) != "production" {
		// init static FileServer
		// TODO be careful to set this to correct location when deploying
		mux.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, r.URL.Path[1:])
		})
	}
	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   config.AllowedCorsOrigins,
		AllowCredentials: true,
	}).Handler(context.ClearHandler(mux))

	// start the server
	logrus.Info("Serving on", config.HTTPAddress())
	graceful.Run(config.Constants.Address, 1*time.Second, corsHandler)
}