sharedutils/distribution/sessionUtils.go

74 lines
1.6 KiB
Go

package distribution
import (
"encoding/json"
"time"
)
func ConvertServerSessionsToJSON(s Session) []byte {
s_json, err := json.Marshal(s)
_ = err //TODO: Check Errors
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{},
}
}
func GetJSSessionInterface(s Session) JSSessionInterface {
newInterface := JSSessionInterface{ //TODO: If session icon empty - use game icon
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
}
var FakeSessions = Sessions{ //TODO: Move to front
Sessions: []Session{
{
GameId: "garrysmod",
SessionId: "gmod-test",
// Icon: "",
// Title: "Regular Skirda Gmod server",
// Status: "Super fake session",
// Version: "",
Expires: time.Time{},
Arguments: []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{},
},
},
}