Compare commits

...

5 Commits

Author SHA1 Message Date
a60fec8491 refactoring 2023-01-05 22:22:48 +03:00
94566bdc6f clean old code 2023-01-05 09:45:08 +03:00
6c6020ef94 refactoring 2023-01-05 06:47:54 +03:00
2fa9396049 separate to different packages 2023-01-05 06:31:53 +03:00
19790ea5c5 separate to different packages 2023-01-05 06:31:30 +03:00
13 changed files with 90 additions and 141 deletions

View File

@ -1,5 +1,9 @@
package distribution
type Distributiuon struct {
Domains []Domain
import (
domainModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/domain"
)
type Distributiuon struct { //TODO: Fix mistake
Domains []domainModels.Domain
}

View File

@ -1,11 +0,0 @@
package distribution
type Domain struct {
DiscordGroupID string
Games Games
Sessions Sessions
}
type Domains struct {
Domains []Domain
}

View File

@ -1,13 +0,0 @@
package distribution
var fakeDomains = Domains{ //TODO: Move to back
Domains: []Domain{defaultDomain},
}
var defaultDomain = Domain{
DiscordGroupID: "0",
Games: Games{
SteamGames: SteamFakeGamesList,
},
Sessions: FakeSessions,
}

View File

@ -1,29 +0,0 @@
package distribution
var garrysmodGame = SteamGame{ //TODO: Move to front
GameId: "garrysmod",
SteamId: "4000",
Args: []Argument{},
Platforms: map[string]bool{
"linux": true,
"windows": true,
},
Assets: GameInterfaceAssets{
Title: "Garry's Mod",
Icon: "icon.png",
Description: "",
},
}
var openarena = SteamGame{
GameId: "half-life-1",
SteamId: "70",
Args: []Argument{},
Assets: GameInterfaceAssets{
Title: "Half Life",
Icon: "icon.png",
Description: "asdadasd",
},
}
var SteamFakeGamesList = []SteamGame{garrysmodGame, openarena}

View File

@ -1,73 +0,0 @@
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{},
},
},
}

View File

@ -0,0 +1,16 @@
package domainModels
import (
gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games"
sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions"
)
type Domain struct {
DiscordGroupID string
Games gamesModels.Games
Sessions sessionsModels.Sessions
}
type Domains struct {
Domains []Domain
}

View File

@ -1,7 +1,7 @@
package distribution
package gamesModels
type SteamGame struct {
GameId string
GameId string //TODO: To UUID
SteamId string
Args []Argument
OptionalArgs []Argument
@ -9,6 +9,10 @@ type SteamGame struct {
Platforms map[string]bool
}
type LocalGame struct {
GameId string
}
type GameInterfaceAssets struct {
Title string
Icon string
@ -20,8 +24,9 @@ type GameInterfaceBackground struct {
File string
}
type Games struct {
type Games struct { //TODO: to domain
SteamGames []SteamGame
LocalGames []LocalGame
}
type JSGameInterface struct {

View File

@ -1,18 +1,20 @@
package distribution
package sessionsModels
import (
"time"
gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games"
)
type Session struct {
SessionId string
GameId string
Assets GameInterfaceAssets
Assets gamesModels.GameInterfaceAssets
Expires time.Time
Arguments []Argument
Arguments []gamesModels.Argument
}
type Sessions struct {
type Sessions struct { //TODO: to domain
Sessions []Session
}

View File

@ -0,0 +1,3 @@
package domainUtils
// sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions"

View File

@ -1,12 +1,14 @@
package distribution
package gameUtils
func FindGameByID(id string, list Games) SteamGame {
import gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games"
func FindGameByID(id string, list gamesModels.Games) gamesModels.SteamGame {
for _, game := range list.SteamGames {
if game.GameId == id {
return game
}
}
var temp SteamGame = SteamGame{}
var temp gamesModels.SteamGame = gamesModels.SteamGame{}
return temp
}
@ -20,8 +22,8 @@ func FindGameByID(id string, list Games) SteamGame {
// return game
// }
func GetJSGameInterface(game SteamGame) JSGameInterface {
newInterface := JSGameInterface{
func GetJSGameInterface(game gamesModels.SteamGame) gamesModels.JSGameInterface {
newInterface := gamesModels.JSGameInterface{
GameID: game.GameId,
Title: game.Assets.Title,
Icon: game.Assets.Icon,
@ -30,6 +32,6 @@ func GetJSGameInterface(game SteamGame) JSGameInterface {
return newInterface
}
func ArgToStr(a Argument) string {
func ArgToStr(a gamesModels.Argument) string {
return a.Body + " " + a.Value
}

43
utils/session/session.go Normal file
View File

@ -0,0 +1,43 @@
package sessionUtils
import (
"encoding/json"
"time"
gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games"
sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions"
)
func ConvertServerSessionsToJSON(s sessionsModels.Session) []byte {
s_json, err := json.Marshal(s)
_ = err //TODO: Check Errors
return s_json
}
func FindSessionByID(sessionId string, sessions []sessionsModels.Session) sessionsModels.Session {
for _, session := range sessions {
if session.SessionId == sessionId {
return session
}
}
return sessionsModels.Session{ //TODO: Return Errors
SessionId: sessionId,
GameId: "",
Assets: gamesModels.GameInterfaceAssets{},
Expires: time.Time{},
Arguments: []gamesModels.Argument{},
}
}
func GetJSSessionInterface(s sessionsModels.Session) sessionsModels.JSSessionInterface {
newInterface := sessionsModels.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
}