fix sessions

This commit is contained in:
Gregory Brzezinski 2022-11-11 15:30:08 +03:00
parent 58eca5ea06
commit 4319b1e1b3
4 changed files with 32 additions and 114 deletions

View File

@ -7,10 +7,7 @@ import (
type Session struct { type Session struct {
SessionId string SessionId string
GameId string GameId string
Icon string Assets GameInterfaceAssets
Title string
Status string
Version string
Expires time.Time Expires time.Time
Arguments []Argument Arguments []Argument
} }
@ -20,10 +17,8 @@ type Sessions struct {
} }
type JSSessionInterface struct { type JSSessionInterface struct {
GameID string `json:"gameId"` GameID string `json:"gameId"`
Icon string `json:"icon"` SessionId string `json:"sessionId"`
Title string `json:"title"` Expires time.Time `json:"expires"`
Status string `json:"status"` Assets GameInterfaceAssets `json:"assets"`
Version string `json:"version"`
Expires time.Time `json:"expires"`
} }

View File

@ -11,16 +11,31 @@ func ConvertServerSessionsToJSON(s Session) []byte {
return s_json return s_json
} }
func FindSessionByID(sessionId string, sessions []Session) Session {
for _, session := range sessions {
if session.SessionId == sessionId {
return session
}
}
return Session{ //TODO: Return Errors
SessionId: sessionId,
GameId: "",
Assets: GameInterfaceAssets{},
Expires: time.Time{},
Arguments: []Argument{},
}
}
var FakeSessions = Sessions{ var FakeSessions = Sessions{
Sessions: []Session{ Sessions: []Session{
{ {
GameId: "garrysmod", GameId: "garrysmod",
SessionId: "gmod-test", SessionId: "gmod-test",
Icon: "", // Icon: "",
Title: "Regular Skirda Gmod server", // Title: "Regular Skirda Gmod server",
Status: "Super fake session", // Status: "Super fake session",
Version: "", // Version: "",
Expires: time.Time{}, Expires: time.Time{},
Arguments: []Argument{ Arguments: []Argument{
{ {
Body: "+connect", Body: "+connect",
@ -29,27 +44,17 @@ var FakeSessions = Sessions{
}, },
}, },
{ {
GameId: "half-lide-1", // GameId: "half-lide-1",
Title: "Half-Life 1 МЯСО", // Title: "Half-Life 1 МЯСО",
Status: "Retro shit", // Status: "Retro shit",
Expires: time.Time{}, Expires: time.Time{},
}, },
{ {
GameId: "minecraft", GameId: "minecraft",
Title: "Test 3", // Title: "Test 3",
Status: "Testing session", // Status: "Testing session",
Version: "1.54.7", // Version: "1.54.7",
Expires: time.Time{}, Expires: time.Time{},
}, },
}, },
} }
func FindSessionByID(sessionId string, sessions []Session) Session {
for _, session := range sessions {
if session.SessionId == sessionId {
return session
}
}
var temp Session = Session{}
return temp
}

View File

@ -1,28 +0,0 @@
package sessionUtils
import (
"time"
"git.gregbrzezinski.com/Skirda/skirdagoutils/gameUtils"
)
type Session struct {
SessionId string
GameId string
Assets gameUtils.GameInterfaceAssets
Expires time.Time
Arguments []gameUtils.Argument
}
type Sessions struct {
Sessions []Session
}
type JSSessionInterface struct {
GameID string `json:"gameId"`
Icon string `json:"icon"`
Title string `json:"title"`
Status string `json:"status"`
Version string `json:"version"`
Expires time.Time `json:"expires"`
}

View File

@ -1,54 +0,0 @@
package sessionUtils
import (
"encoding/json"
)
func ConvertServerSessionsToJSON(s Session) []byte {
s_json, err := json.Marshal(s)
_ = err //TODO: Check Errors
return s_json
}
// var FakeSessions = Sessions{
// Sessions: []Session{
// {
// GameId: "garrysmod",
// SessionId: "gmod-test",
// Icon: "",
// Title: "Regular Skirda Gmod server",
// Status: "Super fake session",
// Version: "",
// Expires: time.Time{},
// Arguments: []gameUtils.Argument{
// {
// Body: "+connect",
// Value: "127.0.0.1:27015",
// },
// },
// },
// {
// GameId: "half-lide-1",
// Title: "Half-Life 1 МЯСО",
// Status: "Retro shit",
// Expires: time.Time{},
// },
// {
// GameId: "minecraft",
// Title: "Test 3",
// Status: "Testing session",
// Version: "1.54.7",
// Expires: time.Time{},
// },
// },
// }
func FindSessionByID(sessionId string, sessions []Session) Session {
for _, session := range sessions {
if session.SessionId == sessionId {
return session
}
}
var temp Session = Session{}
return temp
}