Skip to content

Commit 595ea6f

Browse files
committed
Updated lobby endpoint based on Gcloud
envormental tags fixed issue with cave and river tables that would start a game with only 1 player
1 parent f49c4d7 commit 595ea6f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

server/lobbyClient.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ import (
1010
"github.com/goccy/go-json"
1111
)
1212

13-
const (
14-
// LOBBY_ENDPOINT_UPSERT = "http://qalobby.fujinet.online/server" --- use for testing
15-
LOBBY_ENDPOINT_UPSERT = "http://lobby.fujinet.online/server"
16-
)
17-
1813
// Defaults for this game server
1914
// Appkey/game are hard coded, but the others could be read from a config file
2015
var DefaultGameServerDetails = GameServer{
@@ -27,8 +22,6 @@ var DefaultGameServerDetails = GameServer{
2722
},
2823
}
2924

30-
var UpdateLobby bool
31-
3225
type GameServer struct {
3326
// Properties being sent from Game Server
3427
Game string `json:"game"`
@@ -68,6 +61,7 @@ func sendStateToLobby(maxPlayers int, curPlayers int, isOnline bool, server stri
6861
panic(err)
6962
}
7063
fmt.Printf("Updating Lobby: %s", jsonPayload)
64+
7165
request, err := http.NewRequest("POST", LOBBY_ENDPOINT_UPSERT, bytes.NewBuffer(jsonPayload))
7266
if err != nil {
7367
panic(err)

server/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type GameState struct {
2929
}
3030

3131
var gameStates = make([]GameState, 7)
32+
var LOBBY_ENDPOINT_UPSERT string
33+
var UpdateLobby bool
3234

3335
type GameTable struct {
3436
Table string `json:"t"`
@@ -45,8 +47,8 @@ var tables = []GameTable{
4547
{Table: "ai3", Name: "AI Room - 3 bots", CurPlayers: 0, MaxPlayers: 6, maxBots: 3, Status: 0},
4648
{Table: "ai4", Name: "AI Room - 4 bots", CurPlayers: 0, MaxPlayers: 6, maxBots: 4, Status: 0},
4749
{Table: "ai5", Name: "AI Room - 5 bots", CurPlayers: 0, MaxPlayers: 6, maxBots: 5, Status: 0},
48-
{Table: "river", Name: "The River", CurPlayers: 0, MaxPlayers: 6, maxBots: 0, Status: 0},
49-
{Table: "cave", Name: "Cave of Caerbannog", CurPlayers: 0, MaxPlayers: 6, maxBots: 0, Status: 0},
50+
{Table: "river", Name: "The River", CurPlayers: 0, MaxPlayers: 6, maxBots: 5, Status: 0},
51+
{Table: "cave", Name: "Cave of Caerbannog", CurPlayers: 0, MaxPlayers: 6, maxBots: 5, Status: 0},
5052
}
5153

5254
type Status int
@@ -97,10 +99,14 @@ func main() {
9799
UpdateLobby = os.Getenv("GO_PROD") == "1"
98100

99101
if UpdateLobby {
100-
log.Printf("This instance will update the lobby at " + LOBBY_ENDPOINT_UPSERT)
101102
gin.SetMode(gin.ReleaseMode)
103+
LOBBY_ENDPOINT_UPSERT = "http://lobby.fujinet.online/server"
104+
} else {
105+
LOBBY_ENDPOINT_UPSERT = "http://qalobby.fujinet.online/server"
102106
}
103107

108+
log.Print("This instance will update the lobby at " + LOBBY_ENDPOINT_UPSERT)
109+
104110
// Determine port for HTTP service.
105111
port := os.Getenv("PORT")
106112
if port == "" {
@@ -136,7 +142,6 @@ func main() {
136142

137143
// Set up router and start server
138144
router.SetTrustedProxies(nil) // Disable trusted proxies because Gin told me to do it.. (neeed to investigate this further)
139-
140145
router.Run(":" + port)
141146
}
142147

@@ -272,6 +277,9 @@ func joinTable(c *gin.Context) {
272277
gameStates[tableIndex].Players = append(gameStates[tableIndex].Players, newplayer)
273278
gameStates[tableIndex].Players[len(gameStates[tableIndex].Players)-1].Playorder = gameStates[tableIndex].Table.CurPlayers // Set the play order for the new player
274279
gameStates[tableIndex].Table.CurPlayers++ // Increment the current players count
280+
if (gameStates[tableIndex].Table.Table == "cave" || gameStates[tableIndex].Table.Table == "river") && gameStates[tableIndex].Table.CurPlayers > 1 {
281+
gameStates[tableIndex].Table.maxBots = 0 // No bots allowed in cave or river if more than 2 or more human players
282+
}
275283
if gameStates[tableIndex].Table.CurPlayers >= gameStates[tableIndex].Table.MaxPlayers {
276284
gameStates[tableIndex].Table.Status = 1 // Set the status to full if max players reached
277285
c.Params = []gin.Param{{Key: "sup", Value: "1"}}
@@ -328,6 +336,7 @@ func StartNewGame(c *gin.Context) {
328336
c.JSON(http.StatusOK, "New game started on table "+tables[tableIndex].Table)
329337
}
330338
// fill up the empty slots with AI players if there are less than 6 players up to the maxiumum bots allowed at that table
339+
331340
for i := 0; i < gameStates[tableIndex].Table.maxBots; i++ {
332341
if gameStates[tableIndex].Table.CurPlayers >= (gameStates[tableIndex].Table.MaxPlayers) {
333342
break // Stop adding AI players if the maximum number of players is reached
@@ -347,6 +356,10 @@ func StartNewGame(c *gin.Context) {
347356
gameStates[tableIndex].Players = append(gameStates[tableIndex].Players, newAIPlayer)
348357
gameStates[tableIndex].Table.CurPlayers++
349358
}
359+
360+
if (gameStates[tableIndex].Table.Table == "cave" || gameStates[tableIndex].Table.Table == "river") && gameStates[tableIndex].Table.CurPlayers > 1 {
361+
gameStates[tableIndex].Table.maxBots = 6 // restore max bots to 6 for cave and river tables
362+
}
350363
gameStates[tableIndex].Table.Status = 3 // Set the table status to playing
351364
tables[tableIndex].CurPlayers = gameStates[tableIndex].Table.CurPlayers // Update the quick table view players count
352365
tables[tableIndex].Status = gameStates[tableIndex].Table.Status // Update the quick table view status

0 commit comments

Comments
 (0)