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) }
package socket import ( "errors" "github.com/TF2Stadium/Helen/routes/socket/middleware" "github.com/TF2Stadium/wsevent" ) var ( //AuthServer is the wsevent server where authenticated (logged in) users/sockets //are added to AuthServer = wsevent.NewServer(middleware.JSONCodec{}, func(_ *wsevent.Client, _ struct{}) interface{} { return errors.New("No such request.") }) //UnauthServer is the wsevent server where unauthenticated users/sockets //are added to UnauthServer = wsevent.NewServer(middleware.JSONCodec{}, func(_ *wsevent.Client, _ struct{}) interface{} { return errors.New("You aren't logged in.") }) ) // Wait for all websocket requests to complete func Wait() { AuthServer.Requests.Wait() UnauthServer.Requests.Wait() }
package socket import ( "github.com/TF2Stadium/Helen/helpers" "github.com/TF2Stadium/Helen/routes/socket/middleware" "github.com/TF2Stadium/wsevent" ) var ( //AuthServer is the wsevent server where authenticated (logged in) users/sockets //are added to AuthServer = wsevent.NewServer(middleware.JSONCodec{}, func(_ *wsevent.Client, _ struct{}) interface{} { return helpers.NewTPError("No such request.", -3) }) //UnauthServer is the wsevent server where unauthenticated users/sockets //are added to UnauthServer = wsevent.NewServer(middleware.JSONCodec{}, func(_ *wsevent.Client, _ struct{}) interface{} { return helpers.NewTPError("Player isn't logged in.", -4) }) )