Skip to content

Commit

Permalink
Updated server port struct (#95)
Browse files Browse the repository at this point in the history
* Updated server port struct

* Updated ping server struct, added callback hostname

---------

Co-authored-by: Nikolai Danylchyk <[email protected]>
  • Loading branch information
kennycoder and ext-ndanylchyk authored Mar 3, 2023
1 parent 32712b1 commit 8aa8a37
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions services/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ Please create a .env file in the same with the following variables:
CLIENT_ID=<CLIENT_ID>.apps.googleusercontent.com
CLIENT_SECRET=<CLIENT_SECRET>
LISTEN_PORT=8081
CALLBACK_HOSTNAME=http://localhost:8081/callback
CLIENT_LAUNCHER_PORT=8082
PROFILE_SERVICE=http://localhost:8080
PING_SERVICE=http://localhost:8083
JWT_KEY=<JWT_KEY>
```

* `LISTEN_PORT` is the local port for this Docker container
* `CALLBACK_HOSTNAME` is the full URL to which authentication provider will redirect to. Should be a hostname registered in the https://console.cloud.google.com/apis/credentials (OAuth 2.0 Client IDs) or similar. Points back to this application
* `CLIENT_LAUNCHER_PORT` is the port that the launcher uses. There shouldn't be any reason to change this value.

# Building locally
Expand Down
34 changes: 27 additions & 7 deletions services/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
// Oauth config from env vars
googleOauthConfig.ClientID = os.Getenv("CLIENT_ID")
googleOauthConfig.ClientSecret = os.Getenv("CLIENT_SECRET")
googleOauthConfig.RedirectURL = "http://localhost:" + os.Getenv("LISTEN_PORT") + "/callback"
googleOauthConfig.RedirectURL = os.Getenv("CALLBACK_HOSTNAME")

r := gin.Default()

Expand Down Expand Up @@ -209,15 +209,35 @@ func handleUpdateStats(id string, c *gin.Context) {

// WIP: Needs an endpoint to fetch the ping servers
func handlePingServers(id string, c *gin.Context) {
// TODO: fetch servers from some tbd endpoint
client := &http.Client{}
req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("%s/list", os.Getenv("PING_SERVICE")), c.Request.Body)
if shared.HandleError(c, http.StatusInternalServerError, "fetch ping servers", err) {
return
}

var pingServers []models.PingServer = []models.PingServer{
{Name: "agones-ping-udp-service", Namespace: "agones-system", Region: "asia-east1", Address: "104.155.211.151", Protocol: "UDP"},
{Name: "agones-ping-udp-service", Namespace: "agones-system", Region: "europe-west1", Address: "34.22.151.131", Protocol: "UDP"},
{Name: "agones-ping-udp-service", Namespace: "agones-system", Region: "us-central1", Address: "35.227.137.95", Protocol: "UDP"},
response, err := client.Do(req)
if shared.HandleError(c, http.StatusInternalServerError, "fetch ping servers", err) {
return
}

c.JSON(http.StatusOK, pingServers)
defer response.Body.Close()

if response.StatusCode == 200 {
var pingServers map[string]models.PingServer
err := json.NewDecoder(response.Body).Decode(&pingServers)
if shared.HandleError(c, http.StatusInternalServerError, "decoding ping servers", err) {
return
}

c.JSON(http.StatusOK, pingServers)
return
} else {
err := fmt.Errorf("unable to update profile stats, error code: %d", response.StatusCode)
if shared.HandleError(c, http.StatusBadRequest, "stats update", err) {
return
}

}
}

// WIP: Handles the play request from the game client
Expand Down
1 change: 1 addition & 0 deletions services/frontend/models/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type PingServer struct {
Region string
Address string
Protocol string
Port uint64
}

func FindMatchingServer(regions []string) OMServerResponse {
Expand Down

0 comments on commit 8aa8a37

Please sign in to comment.