sharedutils/utils/session/sessionUtils.go

77 lines
1.9 KiB
Go
Raw Normal View History

2023-01-05 03:31:53 +00:00
package sessionUtils
2022-11-11 12:15:36 +00:00
import (
"encoding/json"
"time"
2023-01-05 03:31:53 +00:00
gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games"
sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions"
2022-11-11 12:15:36 +00:00
)
2023-01-05 03:31:53 +00:00
func ConvertServerSessionsToJSON(s sessionsModels.Session) []byte {
2022-11-11 12:15:36 +00:00
s_json, err := json.Marshal(s)
_ = err //TODO: Check Errors
return s_json
}
2023-01-05 03:31:53 +00:00
func FindSessionByID(sessionId string, sessions []sessionsModels.Session) sessionsModels.Session {
2022-11-11 12:30:08 +00:00
for _, session := range sessions {
if session.SessionId == sessionId {
return session
}
}
2023-01-05 03:31:53 +00:00
return sessionsModels.Session{ //TODO: Return Errors
2022-11-11 12:30:08 +00:00
SessionId: sessionId,
GameId: "",
2023-01-05 03:31:53 +00:00
Assets: gamesModels.GameInterfaceAssets{},
2022-11-11 12:30:08 +00:00
Expires: time.Time{},
2023-01-05 03:31:53 +00:00
Arguments: []gamesModels.Argument{},
2022-11-11 12:30:08 +00:00
}
}
2023-01-05 03:31:53 +00:00
func GetJSSessionInterface(s sessionsModels.Session) sessionsModels.JSSessionInterface {
newInterface := sessionsModels.JSSessionInterface{ //TODO: If session icon empty - use game icon
2022-11-11 23:56:43 +00:00
GameID: s.GameId,
SessionId: s.SessionId,
Expires: time.Time{},
Title: s.Assets.Title,
Icon: s.Assets.Icon,
Description: s.Assets.Description,
Backgrounds: []string{}, //TODO: Complete
}
return newInterface
}
2023-01-05 03:31:53 +00:00
var FakeSessions = sessionsModels.Sessions{ //TODO: Move to front
Sessions: []sessionsModels.Session{
2022-11-11 12:15:36 +00:00
{
GameId: "garrysmod",
SessionId: "gmod-test",
2022-11-11 12:30:08 +00:00
// Icon: "",
// Title: "Regular Skirda Gmod server",
// Status: "Super fake session",
// Version: "",
Expires: time.Time{},
2023-01-05 03:31:53 +00:00
Arguments: []gamesModels.Argument{
2022-11-11 12:15:36 +00:00
{
Body: "+connect",
Value: "127.0.0.1:27015",
},
},
},
{
2022-11-11 12:30:08 +00:00
// GameId: "half-lide-1",
// Title: "Half-Life 1 МЯСО",
// Status: "Retro shit",
2022-11-11 12:15:36 +00:00
Expires: time.Time{},
},
{
2022-11-11 12:30:08 +00:00
GameId: "minecraft",
// Title: "Test 3",
// Status: "Testing session",
// Version: "1.54.7",
2022-11-11 12:15:36 +00:00
Expires: time.Time{},
},
},
}