Skip to content

Commit ede31e9

Browse files
committed
Update code to enable lobby server integration
1 parent eaf5b3d commit ede31e9

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

Client/Atari/FujiLlama.bas

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ DATA colorThemeMap() = $B4,$88, $84,$08, $22,$28, $04,$08,' NTSC
212212
DATA = $A4,$78, $74,$08, $12,$18, $04,$08 ' PAL
213213
colorTheme=-1
214214

215-
' Read server endpoint stored from Lobby
215+
216216
serverEndpoint$=""
217217
query$=""
218218

219+
' Read server endpoint stored from Lobby
219220
@NReadAppKey AK_LOBBY_CREATOR_ID, AK_LOBBY_APP_ID, AK_LOBBY_KEY_SERVER, &serverEndpoint$
220-
serverEndpoint$="" ' Clear for testing - comment out to use lobby server setting
221+
'serverEndpoint$="" ' Clear for testing - comment out to use lobby server setting
221222

222223
' Parse endpoint url into server and query
223224
if serverEndpoint$<>""
@@ -231,7 +232,7 @@ if serverEndpoint$<>""
231232
else
232233
' Default to known server if not specified by lobby. Override for local testing
233234
serverEndpoint$="N:https://fujillama.spysoft.nz"
234-
'serverEndpoint$="N:http://192.168.68.100:8080"
235+
'serverEndpoint$="N:http://192.168.68.100:8080" ' Local server for testing
235236
endif
236237

237238
' Fuji-Net Setup Variblies

server/lobbyClient.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
)
1212

1313
const (
14-
LOBBY_ENDPOINT_UPSERT = "http://lobby.fujinet.online/server"
14+
// LOBBY_ENDPOINT_UPSERT = "http://qalobby.fujinet.online/server" --- use for testing
15+
LOBBY_ENDPOINT_UPSERT = "http://qalobby.fujinet.online/server"
1516
)
1617

1718
// Defaults for this game server
@@ -20,9 +21,9 @@ var DefaultGameServerDetails = GameServer{
2021
Appkey: 4,
2122
Game: "Fuji-Llama",
2223
Region: "nz",
23-
Serverurl: "https://fujillama.spysoft.nz/",
24+
Serverurl: "N:https://fujillama.spysoft.nz",
2425
Clients: []GameClient{
25-
{Platform: "atari", Url: "tnfs://ec.tnfs.io/atari/fujillama.xex"},
26+
{Platform: "atari", Url: "tnfs://34.31.166.226/atari/fujillama.xex"},
2627
},
2728
}
2829

@@ -48,10 +49,6 @@ type GameClient struct {
4849

4950
func sendStateToLobby(maxPlayers int, curPlayers int, isOnline bool, server string, instanceUrlSuffix string) {
5051

51-
//if !UpdateLobby {
52-
// return
53-
//}
54-
5552
// Start with copy of default game server details
5653
serverDetails := DefaultGameServerDetails
5754
serverDetails.Maxplayers = maxPlayers
@@ -64,12 +61,12 @@ func sendStateToLobby(maxPlayers int, curPlayers int, isOnline bool, server stri
6461

6562
serverDetails.Server = server
6663
serverDetails.Serverurl += instanceUrlSuffix
64+
//serverDetails.Serverurl += ""
6765

6866
jsonPayload, err := json.Marshal(serverDetails)
6967
if err != nil {
7068
panic(err)
7169
}
72-
log.Printf("Updating Lobby: %s", jsonPayload)
7370
fmt.Printf("Updating Lobby: %s", jsonPayload)
7471
request, err := http.NewRequest("POST", LOBBY_ENDPOINT_UPSERT, bytes.NewBuffer(jsonPayload))
7572
if err != nil {
@@ -89,7 +86,6 @@ func sendStateToLobby(maxPlayers int, curPlayers int, isOnline bool, server stri
8986
log.Printf("Lobby Response: %s", response.Status)
9087
if response.StatusCode > 300 {
9188
body, _ := io.ReadAll(response.Body)
92-
log.Println("response Body:", string(body))
9389
fmt.Println("response Body:", string(body))
9490
}
9591

server/main.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ func main() {
121121
EndedLast: -1,
122122
RoundOver: false,
123123
Gameover: false}
124-
SetupTable(i) // Initialize each table with a new deck and shuffle it
124+
setUpTable(i) // Initialize each table with a new deck and shuffle it
125+
updateLobby(i) // Update the lobby with the initial state of each table
125126
}
126127

127128
router := gin.Default()
@@ -132,7 +133,6 @@ func main() {
132133
router.GET("/join", joinTable) // Join a table
133134
router.GET("/start", StartNewGame) // start a new game on a table (this also happens automaticly when the table is filled with players), if the table is not filled it will fill the emplty slots with AI Players
134135
router.GET("/move", doVaildMoveURL) // Make a move on the table (play, fold, draw)
135-
router.GET("/updateLobby", apiUpdateLobby)
136136

137137
// Set up router and start server
138138
router.SetTrustedProxies(nil) // Disable trusted proxies because Gin told me to do it.. (neeed to investigate this further)
@@ -189,7 +189,7 @@ func NewDeck() []Card {
189189
return deck
190190
}
191191

192-
func SetupTable(tableIndex int) {
192+
func setUpTable(tableIndex int) {
193193
if tableIndex < 0 || tableIndex >= len(gameStates) {
194194
return // Invalid table index
195195
}
@@ -280,6 +280,7 @@ func joinTable(c *gin.Context) {
280280
tables[tableIndex].CurPlayers = gameStates[tableIndex].Table.CurPlayers // update the quick table view players count
281281
tables[tableIndex].Status = gameStates[tableIndex].Table.Status // update the quick table view status
282282
gameStates[tableIndex].startTime = time.Now() // Reset the waiting timer for the game state
283+
updateLobby(tableIndex) // Update the lobby with the new table state
283284
}
284285
}
285286

@@ -936,7 +937,7 @@ func resetGame(tableIndex int) {
936937
Players: Players{},
937938
LastMovePlayed: "Waiting for players to join",
938939
}
939-
SetupTable(tableIndex) // Initialize each table with a new deck and shuffle it
940+
setUpTable(tableIndex) // Initialize each table with a new deck and shuffle it
940941
}
941942

942943
// Reset the game state for the next round
@@ -976,23 +977,10 @@ func makeHandSummary(tableIndex int, playerIndex int) string {
976977
return strings.TrimSpace(summary)
977978
}
978979

979-
// Forces an update of all tables to the lobby - useful for adhoc use if the Lobby restarts or loses info
980-
func apiUpdateLobby(c *gin.Context) {
980+
// update game table info to the lobby fujinet lobby server
981+
func updateLobby(tableIndex int) {
982+
instanceUrlSuffix := "/?table=" + gameStates[tableIndex].Table.Table
983+
sendStateToLobby(gameStates[tableIndex].Table.MaxPlayers, gameStates[tableIndex].Table.CurPlayers, true, gameStates[tableIndex].Table.Name, instanceUrlSuffix)
981984

982-
for i := 0; i < len(gameStates); i++ {
983-
984-
sendStateToLobby(gameStates[i].Table.MaxPlayers, gameStates[i].Table.CurPlayers, false, gameStates[i].Table.Name, "https://fujillama.spysoft.nz/")
985-
986-
}
987-
988-
/*
989-
for _, table := range tables {
990-
value, ok := stateMap.Load(table.Table)
991-
if ok {
992-
state := value.(*GameState)
993-
state.updateLobby()
994-
}
995-
}
996-
*/
997-
c.JSON(http.StatusOK, "Lobby Updated")
985+
fmt.Println("lobby updated for :", string(gameStates[tableIndex].Table.Name))
998986
}

0 commit comments

Comments
 (0)