diff --git a/auth/auth.go b/auth/auth.go new file mode 100644 index 0000000..22c7409 --- /dev/null +++ b/auth/auth.go @@ -0,0 +1,5 @@ +package sharedauth + +type InstallId struct { + InstallId string +} diff --git a/distribution/distribution.go b/distribution/distribution.go deleted file mode 100644 index 6c33460..0000000 --- a/distribution/distribution.go +++ /dev/null @@ -1,5 +0,0 @@ -package distribution - -type Distributiuon struct { - Domains []Domain -} diff --git a/distribution/domainModels.go b/distribution/domainModels.go deleted file mode 100644 index c2d01f5..0000000 --- a/distribution/domainModels.go +++ /dev/null @@ -1,11 +0,0 @@ -package distribution - -type Domain struct { - DiscordGroupID string - Games Games - Sessions Sessions -} - -type Domains struct { - Domains []Domain -} diff --git a/distribution/domainUtils.go b/distribution/domainUtils.go deleted file mode 100644 index 6bf7b8a..0000000 --- a/distribution/domainUtils.go +++ /dev/null @@ -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, -} diff --git a/distribution/fakeGames.go b/distribution/fakeGames.go deleted file mode 100644 index 86873f4..0000000 --- a/distribution/fakeGames.go +++ /dev/null @@ -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} diff --git a/distribution/gameTypes.go b/distribution/gameTypes.go deleted file mode 100644 index 2ac346c..0000000 --- a/distribution/gameTypes.go +++ /dev/null @@ -1,37 +0,0 @@ -package distribution - -type SteamGame struct { - GameId string - SteamId string - Args []Argument - OptionalArgs []Argument - Assets GameInterfaceAssets - Platforms map[string]bool -} - -type GameInterfaceAssets struct { - Title string - Icon string - Description string - Backgrounds []GameInterfaceBackground -} - -type GameInterfaceBackground struct { - File string -} - -type Games struct { - SteamGames []SteamGame -} - -type JSGameInterface struct { - GameID string `json:"gameId"` - Title string `json:"title"` - Icon string `json:"icon"` - Description string `json:"description"` -} - -type Argument struct { - Body string - Value string -} diff --git a/distribution/gameUtils.go b/distribution/gameUtils.go deleted file mode 100644 index 15aad2c..0000000 --- a/distribution/gameUtils.go +++ /dev/null @@ -1,35 +0,0 @@ -package distribution - -func FindGameByID(id string, list Games) SteamGame { - for _, game := range list.SteamGames { - if game.GameId == id { - return game - } - } - var temp SteamGame = SteamGame{} - return temp -} - -// func findSteamGameByID(id string) SteamGame { -// for _, game := range localGames.St { -// if game.GameId == id { -// return game -// } -// } -// var game SteamGame = SteamGame{} -// return game -// } - -func GetJSGameInterface(game SteamGame) JSGameInterface { - newInterface := JSGameInterface{ - GameID: game.GameId, - Title: game.Assets.Title, - Icon: game.Assets.Icon, - Description: game.Assets.Description, - } - return newInterface -} - -func ArgToStr(a Argument) string { - return a.Body + " " + a.Value -} diff --git a/distribution/sessionTypes.go b/distribution/sessionTypes.go deleted file mode 100644 index 6d9ff63..0000000 --- a/distribution/sessionTypes.go +++ /dev/null @@ -1,27 +0,0 @@ -package distribution - -import ( - "time" -) - -type Session struct { - SessionId string - GameId string - Assets GameInterfaceAssets - Expires time.Time - Arguments []Argument -} - -type Sessions struct { - Sessions []Session -} - -type JSSessionInterface struct { - GameID string `json:"gameId"` - SessionId string `json:"sessionId"` - Expires time.Time `json:"expires"` - Title string `json:"title"` - Icon string `json:"icon"` - Description string `json:"description"` - Backgrounds []string `json:"backgrounds"` -} diff --git a/distribution/sessionUtils.go b/distribution/sessionUtils.go deleted file mode 100644 index 63cccbb..0000000 --- a/distribution/sessionUtils.go +++ /dev/null @@ -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{}, - }, - }, -} diff --git a/go.mod b/go.mod deleted file mode 100644 index c86a0e0..0000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module git.gregbrzezinski.com/Skirda/skirdagoutils - -go 1.18 diff --git a/jsonUtils/jsonUtils.go b/jsonUtils/jsonUtils.go deleted file mode 100644 index 77b7b0f..0000000 --- a/jsonUtils/jsonUtils.go +++ /dev/null @@ -1,18 +0,0 @@ -package jsonutils - -//TODO: Rename package -import ( - "encoding/json" - "io" -) - -func ConvertToJSON(g interface{}) []byte { - g_json, err := json.Marshal(g) - _ = err //TODO: Check Errors - return g_json -} - -func ConvertResponseFromJSON(body io.ReadCloser, inter interface{}) { - json_err := json.NewDecoder(body).Decode(&inter) - _ = json_err //TODO work with errors -} diff --git a/sharedDistribution/games.go b/sharedDistribution/games.go new file mode 100644 index 0000000..31a4e0a --- /dev/null +++ b/sharedDistribution/games.go @@ -0,0 +1,158 @@ +package sharedDistribution + +type SkirdaGame interface { + // SkirdaGameId string + GetSkirdaGameId() string + GetInterfaceAsset(gameId string) JSGameInterface + GetLaunchArgs() []string + // Launch(gameId string) error +} + +type SkirdaGames struct { + Steam []SteamGame + Minecraft MinecraftGame //TODO: To slice +} + +func (games SkirdaGames) GetGameTypeById(skirdaGameId string) (string, error) { + if games.Minecraft.GetSkirdaGameId() == skirdaGameId { + return "minecraft", nil + } + + for _, game := range games.Steam { + if game.GetSkirdaGameId() == skirdaGameId { + return "steam", nil + } + } + return "", nil //TODO: Right error return +} + +func (games SkirdaGames) Test(skirdaGameId string) (interface{}, error) { + return games.Minecraft, nil +} + +func (games SkirdaGames) GetInterfaceAssets() []JSGameInterface { + assets := []JSGameInterface{} + + assets = append(assets, games.Minecraft.GetInterfaceAsset()) + for _, game := range games.Steam { + assets = append(assets, game.GetInterfaceAsset()) + } + return assets +} + +func (games SteamGame) Test(skirdaGameId string) (interface{}, error) { + return SteamGame{}, nil +} + +func (game SteamGame) GetSkirdaGameId() string { + return game.SkirdaGameId +} + +func (game MinecraftGame) GetSkirdaGameId() string { + return game.SkirdaGameId +} + +func (game MinecraftGame) GetMinecraftVersion() string { + return game.CurrentVersion +} + +func (games SkirdaGames) GetLaunchCmd(skirdaGameId string, os string) (string, []string, error) { + gameType, err := games.GetGameTypeById(skirdaGameId) + if err != nil { + return "", nil, nil + } + + switch gameType { + case "minecraft": + switch os { + case "windows": + + return "notepad", []string{""}, nil + default: + return "", []string{}, nil + } + default: + return "", nil, nil + } +} + +// func (games SkirdaGames) FindGameByID(gameId string) (SkirdaGame, error) { +// for _, game := range games { +// if game.GetSkirdaGameId() == gameId { +// return game, nil +// } +// } +// kek := SkirdaGame +// return game, nil //TODO: Right error return +// } + +// func (game MinecraftGame) GetLaunchArgs() (string, []string, error) { +// switch os := runtime.GOOS; os { +// case "windows": +// return "java", []string{"-version"}, nil +// default: +// return "", []string{}, nil +// } + +// } + +func (game SteamGame) GetInterfaceAsset() JSGameInterface { + return JSGameInterface{ + GameID: game.SkirdaGameId, + Title: game.Assets.Title, + Icon: game.Assets.Icon, + Description: game.Assets.Description, + } +} + +func (game MinecraftGame) GetInterfaceAsset() JSGameInterface { + return JSGameInterface{ + GameID: game.SkirdaGameId, + Title: game.Assets.Title, + Icon: game.Assets.Icon, + Description: game.Assets.Description, + } +} + +type MinecraftGame struct { + SkirdaGameId string + Assets GameInterfaceAssets + CurrentVersion string +} + +type SteamGame struct { + SkirdaGameId string + SteamId string + Args []Argument + OptionalArgs []Argument + //TODO: Settings?? + Assets GameInterfaceAssets + Platforms map[string]bool +} + +type LocalGame struct { + GameId string +} + +type GameInterfaceAssets struct { + Title string + Icon string + Description string + Backgrounds []GameInterfaceBackground +} + +type GameInterfaceBackground struct { + File string +} + +type JSGameInterface struct { + GameID string `json:"gameId"` + Title string `json:"title"` + Icon string `json:"icon"` + Description string `json:"description"` +} + +type Argument struct { + Body string + Value string +} diff --git a/sharedDistribution/sessions.go b/sharedDistribution/sessions.go new file mode 100644 index 0000000..26b3121 --- /dev/null +++ b/sharedDistribution/sessions.go @@ -0,0 +1,63 @@ +package sharedUtils + +import ( + "time" +) + +type SkirdaSessions []SkirdaSession + +func (sessions SkirdaSessions) FindSessionById(sessionId string) (SkirdaSession, error) { + for _, session := range sessions { + if session.GetSessionId() == sessionId { + return session, nil + } + } + return sessions[0], nil //TODO: Temp error return +} + +func (sessions SkirdaSessions) GetInterfaceAssets() []JSSessionInterface { + assets := []JSSessionInterface{} + + for _, session := range sessions { + assets = append(assets, session.GetInterfaceAsset()) + } + return assets +} + +type SkirdaSession struct { + SkirdaSessionId string + SkirdaGameId string + Args []string + NegativeArgs []string +} + +type JSSessionInterface struct { + GameID string `json:"gameId"` + SessionId string `json:"sessionId"` + Expires time.Time `json:"expires"` + Title string `json:"title"` + Icon string `json:"icon"` + Description string `json:"description"` + Backgrounds []string `json:"backgrounds"` +} + +func (session SkirdaSession) GetSessionId() string { + return session.SkirdaSessionId +} + +func (session SkirdaSession) GetGameId() string { + return session.SkirdaGameId +} + +func (session SkirdaSession) GetInterfaceAsset() JSSessionInterface { + // gameId := SkirdaGame.GetSkirdaGameId() + return JSSessionInterface{ + GameID: "", + SessionId: "", + Expires: time.Time{}, + Title: "Test Session", + Icon: "", + Description: "", + Backgrounds: []string{}, + } +} diff --git a/updateUtils/updateTypes.go b/updateUtils/updateTypes.go deleted file mode 100644 index 8d4674f..0000000 --- a/updateUtils/updateTypes.go +++ /dev/null @@ -1,7 +0,0 @@ -package updateutils - -type LastVersion struct { //Rename to Version - Epic int - Sprint int - Build int -}