fixed broadcast bug
This commit is contained in:
@@ -37,7 +37,7 @@ func BroadcastServerToBackend() error {
|
|||||||
respIpv4orIPv6 := Ip4or6(config.IPAddress)
|
respIpv4orIPv6 := Ip4or6(config.IPAddress)
|
||||||
|
|
||||||
// Adding game session information
|
// Adding game session information
|
||||||
respIpv4orIPv6 = "https://" + respIpv4orIPv6
|
respIpv4orIPv6 = "http://" + respIpv4orIPv6
|
||||||
|
|
||||||
// Get room information
|
// Get room information
|
||||||
_, err = ReadRoomsFile()
|
_, err = ReadRoomsFile()
|
||||||
|
|||||||
@@ -81,6 +81,15 @@ func RemoveTableGameSession(db *gorm.DB) (*gorm.DB, error) {
|
|||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RemoveTableGameSessionID(db *gorm.DB, id string) (*gorm.DB, error) {
|
||||||
|
var gameSession GameSession
|
||||||
|
// Creates table of type GameSessions
|
||||||
|
db.Where("game_session_id = ?", id).Delete(&gameSession)
|
||||||
|
// returns variable DB of type *gorm.DB and error
|
||||||
|
// which is nil at the current moment
|
||||||
|
return db, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DisplayGameSessions Returns all the rows of all the game session information
|
// DisplayGameSessions Returns all the rows of all the game session information
|
||||||
// to display
|
// to display
|
||||||
func DisplayGameSessions(db *gorm.DB) ([]*GameSession, error) {
|
func DisplayGameSessions(db *gorm.DB) ([]*GameSession, error) {
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server Starts the server for the client side
|
// Server Starts the server for the client side
|
||||||
@@ -91,7 +93,7 @@ func Server(port string) error {
|
|||||||
// TODO redirect to homepage
|
// TODO redirect to homepage
|
||||||
// Set client Cookie as Session ID
|
// Set client Cookie as Session ID
|
||||||
// To be changed when we use HTTPS
|
// To be changed when we use HTTPS
|
||||||
c.SetCookie("SessionID", session.SessionKey, 3600, "/", "localhost", false, true)
|
c.SetCookie("SessionID", session.SessionKey, 3600, "/", "*", false, true)
|
||||||
// redirects to the home page
|
// redirects to the home page
|
||||||
//c.Redirect(http.StatusFound, "/")
|
//c.Redirect(http.StatusFound, "/")
|
||||||
|
|
||||||
@@ -178,6 +180,8 @@ func Server(port string) error {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
go CheckIfGameSessionIsActiveOrRemove(connect)
|
||||||
|
|
||||||
// Run gin server on the specified port
|
// Run gin server on the specified port
|
||||||
err = r.Run(":" + port)
|
err = r.Run(":" + port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -186,3 +190,29 @@ func Server(port string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckIfGameSessionIsActiveOrRemove(gorm *gorm.DB) {
|
||||||
|
fmt.Println("here")
|
||||||
|
for {
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
Gamesessions, err := DisplayGameSessions(gorm)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, _ := range Gamesessions {
|
||||||
|
req, err := http.NewRequest("GET", Gamesessions[i].Link, nil)
|
||||||
|
// Sending request to the backend server
|
||||||
|
client := &http.Client{}
|
||||||
|
_, err = client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
// remove from database game session
|
||||||
|
_, err = RemoveTableGameSessionID(gorm, Gamesessions[i].GameSessionID)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user