From b2c1867430aa53f6445a2447dbee9b8b2cc2a604 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Tue, 24 Jan 2023 16:46:17 +0300 Subject: [PATCH] new domain, games, sessions --- domain/domain.go | 61 ++++++++++++++++ games/minecraftgame/minecraftgame.go | 27 +++++++ games/skirdagame/skirdagame.go | 32 +++++++++ games/steamgame/steamgame.go | 28 ++++++++ sharedauth/sharedauth.go | 37 ++++++++++ skirdasession/skirdasession.go | 103 +++++++++++++++++++++++++++ 6 files changed, 288 insertions(+) create mode 100644 domain/domain.go create mode 100644 games/minecraftgame/minecraftgame.go create mode 100644 games/skirdagame/skirdagame.go create mode 100644 games/steamgame/steamgame.go create mode 100644 sharedauth/sharedauth.go create mode 100644 skirdasession/skirdasession.go diff --git a/domain/domain.go b/domain/domain.go new file mode 100644 index 0000000..995b6b5 --- /dev/null +++ b/domain/domain.go @@ -0,0 +1,61 @@ +package domain + +import ( + "errors" + + "git.gregbrzezinski.com/Skirda/skirdaGoLauncher/sharedutils/games/skirdagame" + "git.gregbrzezinski.com/Skirda/skirdaGoLauncher/sharedutils/skirdasession" +) + +type SkirdaDomain struct { + DomainId string + skirdagame.SkirdaGames + skirdasession.SkirdaSessions +} + +func (domain SkirdaDomain) BuildDomain(newGames []skirdagame.SkirdaGame, newSessions []skirdasession.SkirdaSession) { + domain.AddGames(newGames) + domain.AddSessions(newSessions) +} + +type Domains []SkirdaDomain + +func (domains Domains) Set(newDomains []SkirdaDomain) { + domains = append([]SkirdaDomain{}, newDomains...) +} + +func (domains Domains) FindGameByID(gameId string) (skirdagame.SkirdaGame, error) { + for _, domain := range domains { + game, _ := domain.FindGameByID(gameId) + if game.GetSkirdaGameId() == gameId { + return game, nil + } + } + + return nil, errors.New("") +} + +func (domains Domains) GetGames() skirdagame.SkirdaGames { + allGames := skirdagame.SkirdaGames{} + for _, domain := range domains { + allGames = append(allGames, domain.SkirdaGames...) + } + return allGames +} + +func (domains Domains) GetSessions() skirdasession.SkirdaSessions { + plainSessions := skirdasession.SkirdaSessions{} + for _, domain := range domains { + plainSessions = append(plainSessions, domain.SkirdaSessions...) + } + return plainSessions +} + +func (domains Domains) FindDomain(domainId string) (SkirdaDomain, error) { + for _, domain := range domains { + if domain.DomainId == domainId { + return domain, nil + } + } + return SkirdaDomain{}, errors.New("not any domain founded") +} diff --git a/games/minecraftgame/minecraftgame.go b/games/minecraftgame/minecraftgame.go new file mode 100644 index 0000000..1a91372 --- /dev/null +++ b/games/minecraftgame/minecraftgame.go @@ -0,0 +1,27 @@ +package minecraftgame + +import "git.gregbrzezinski.com/Skirda/skirdaGoLauncher/sharedutils/games/skirdagame" + +const gameType = "minecraft" + +type MinecraftGame struct { + SkirdaGameId string + Assets skirdagame.GameUIAssets + // CurrentVersion string +} + +func (game MinecraftGame) GetSkirdaGameId() string { + return game.SkirdaGameId +} + +func (game MinecraftGame) GetInterfaceAsset() skirdagame.GameUIAssets { + return game.Assets +} + +func (game MinecraftGame) GetLaunchArgs() []string { + return []string{"", ""} +} + +func (game MinecraftGame) GetType() string { + return gameType +} diff --git a/games/skirdagame/skirdagame.go b/games/skirdagame/skirdagame.go new file mode 100644 index 0000000..af6909c --- /dev/null +++ b/games/skirdagame/skirdagame.go @@ -0,0 +1,32 @@ +package skirdagame + +import "errors" + +type SkirdaGame interface { + GetSkirdaGameId() string + GetInterfaceAsset() GameUIAssets + GetLaunchArgs() []string + GetType() string +} + +type GameUIAssets struct { + // GameID string `json:"gameId"` + Title string `json:"title"` + Icon string `json:"icon"` + Description string `json:"description"` +} + +type SkirdaGames []SkirdaGame + +func (games SkirdaGames) AddGames(game []SkirdaGame) { + games = append(games, game...) +} + +func (games SkirdaGames) FindGameByID(gameId string) (SkirdaGame, error) { + for _, game := range games { + if game.GetSkirdaGameId() == gameId { + return game, nil + } + } + return nil, errors.New("") +} diff --git a/games/steamgame/steamgame.go b/games/steamgame/steamgame.go new file mode 100644 index 0000000..9fd0dc7 --- /dev/null +++ b/games/steamgame/steamgame.go @@ -0,0 +1,28 @@ +package steamgame + +import "git.gregbrzezinski.com/Skirda/skirdaGoLauncher/sharedutils/games/skirdagame" + +const gameType = "steam" + +type SteamGame struct { + SkirdaGameId string + SteamId string + Assets skirdagame.GameUIAssets + // CurrentVersion string +} + +func (game SteamGame) GetSkirdaGameId() string { + return game.SkirdaGameId +} + +func (game SteamGame) GetInterfaceAsset() skirdagame.GameUIAssets { + return game.Assets +} + +func (game SteamGame) GetLaunchArgs() []string { + return []string{"", ""} +} + +func (game SteamGame) GetType() string { + return gameType +} diff --git a/sharedauth/sharedauth.go b/sharedauth/sharedauth.go new file mode 100644 index 0000000..be7c0ba --- /dev/null +++ b/sharedauth/sharedauth.go @@ -0,0 +1,37 @@ +package sharedauth + +import "time" + +type InstallIdRegisterReq struct { + InstallId InstallId +} + +type InstallId string + +func (id InstallId) Validate() bool { + //TODO: More checks + return id != "" +} + +type RedirResp struct { + RedirectUrl string +} + +type LauncherSession struct { + // Username string + // DiscordId string + SessionToken string + InstallId string + Expiry time.Time +} + +type ProfileResp struct { + Username string +} + +type ValidateReq struct { + LauncherToken string +} + +type ValidateResp struct { +} diff --git a/skirdasession/skirdasession.go b/skirdasession/skirdasession.go new file mode 100644 index 0000000..b85a63d --- /dev/null +++ b/skirdasession/skirdasession.go @@ -0,0 +1,103 @@ +package skirdasession + +import ( + "errors" +) + +type SkirdaSession interface { + GetSessionId() string + GetGameId() string + GetUIAssets() SessionUIAssets + GetGameType() string + GetSessionData() string +} + +// type SkirdaSession struct { +// SkirdaSessionId string +// SkirdaGameId string +// Assets SessionUIAssets +// } + +type SkirdaSessions []SkirdaSession + +type SessionUIAssets struct { + // GameID string `json:"gameId"` + Title string `json:"title"` + Icon string `json:"icon"` + Description string `json:"description"` +} + +func (sessions SkirdaSessions) FindSessionById(sessionId string) (SkirdaSession, error) { + for _, session := range sessions { + if session.GetSessionId() == sessionId { + return session, nil + } + } + return nil, errors.New("no any sessions founded") +} + +func (sessions SkirdaSessions) AddSessions(newSessions []SkirdaSession) { + sessions = append(sessions, newSessions...) +} + +type MinecraftSession struct { + SkirdaSessionId string + SkirdaGameId string + Assets SessionUIAssets + Version string +} + +func (session MinecraftSession) GetSessionId() string { + return session.SkirdaSessionId +} + +func (session MinecraftSession) GetUIAssets() SessionUIAssets { + return session.Assets +} + +func (session MinecraftSession) GetGameId() string { + return session.SkirdaGameId +} + +func (session MinecraftSession) GetMinecraftVersion() string { + return session.SkirdaGameId +} + +func (session MinecraftSession) GetGameType() string { + return "minecraft" +} + +func (session MinecraftSession) GetSessionData() string { + return session.Version +} + +type SteamSession struct { + SkirdaSessionId string + SkirdaGameId string + Assets SessionUIAssets + // Data SteamSessionData +} + +type SteamSessionData struct { + kke string +} + +func (session SteamSession) GetSessionId() string { + return session.SkirdaSessionId +} + +func (session SteamSession) GetUIAssets() SessionUIAssets { + return session.Assets +} + +func (session SteamSession) GetGameId() string { + return session.SkirdaGameId +} + +func (session SteamSession) GetGameType() string { + return "steam" +} + +func (session SteamSession) GetSessionData() string { + return "" +}