Compare commits

..

106 Commits

Author SHA1 Message Date
c853ee3a55 Merge remote-tracking branch 'origin/main' 2023-04-12 01:40:04 +03:00
43070c0642 corrected isLetter to hex letters (not alphabetic letters) 2023-04-12 01:36:37 +03:00
b99ca4621a change structs 2023-04-04 01:51:45 +03:00
589fcf0579 Fix naming in reflect field 2023-04-01 04:57:05 +03:00
e17b938ef2 reduce validation code and improve algorithm 2023-03-28 01:26:29 +03:00
cf26a112f2 Merge remote-tracking branch 'origin/main' 2023-03-27 01:41:06 +03:00
e88fb5c1da add type to apiGame 2023-03-27 00:40:27 +03:00
16583fc689 add uuid validation 2023-03-27 00:17:39 +03:00
55433b7d11 change skirdaDomainApi 2023-03-26 17:31:23 +03:00
2a7c682ffa Share SkirdaGame to launcher 2023-03-26 15:23:18 +03:00
9fe3a02e9f add shared type for api 2023-03-26 00:26:13 +03:00
d0a5e5fb0b move domains in back repo 2023-03-25 01:23:15 +03:00
928edc1efe change name of userId field 2023-03-25 01:22:27 +03:00
a86bb964e5 add requestId string 2023-03-21 02:32:33 +03:00
0495d1efb1 change sharedUser 2023-03-13 14:29:37 +03:00
3933b4e16f change sharedUser 2023-03-13 13:38:16 +03:00
4465fa52c1 fix json reflect in RedirStruct 2023-03-13 12:20:46 +03:00
528846c002 change skirdaDomain 2023-03-11 20:24:24 +03:00
b397940fef add userDomain type and field in domain 2023-03-11 16:52:09 +03:00
2f451f2be4 fix user id name 2023-03-11 16:02:51 +03:00
3e0fa1d5c1 add json reflections to SkirdaUser 2023-03-11 15:59:36 +03:00
8a698b8b1d add domains array to user 2023-03-11 15:54:52 +03:00
d254f698d3 new domain acrhitecture 2023-03-09 17:01:26 +03:00
9e0033149d Merge remote-tracking branch 'origin/main' 2023-03-09 16:55:10 +03:00
fd9bb44e28 fix steam pointers for structs methods and make new user and domains struct 2023-03-09 16:54:19 +03:00
3b41207354 add json reflections for SkirdaDomain 2023-03-03 11:40:43 +03:00
77addd32dc fix json reflection name 2023-02-18 21:21:33 +03:00
7e2a75d11d Merge remote-tracking branch 'origin/main' 2023-02-15 01:16:04 +03:00
38f9900901 fix naming and error return in json read util 2023-02-15 01:15:59 +03:00
4bc1db5397 add func to generate java version string 2023-02-15 01:15:42 +03:00
145c56e9f6 add method to fill VersionNum from string values 2023-02-13 19:57:53 +03:00
f44e6b104b Merge remote-tracking branch 'origin/main'
# Conflicts:
#	domain/structures.go
2023-02-12 23:35:06 +03:00
1cb34f3e6c rename fields and comment 2023-02-12 22:09:55 +03:00
ebeb05cd1a delete commented 2023-02-12 22:09:55 +03:00
2b95a109c6 add method find OsSpecifics to java versions 2023-02-12 22:04:53 +03:00
0dce90931c comment obsolete session code 2023-02-12 19:58:53 +03:00
cee68d0d61 move skirda session to domain package 2023-02-12 19:58:39 +03:00
d21061e36d add test struct 2023-02-12 19:58:30 +03:00
79886cbfae delete mod file 2023-02-12 19:58:22 +03:00
605da815cd Merge remote-tracking branch 'origin/main'
# Conflicts:
#	domain/domain.go
#	domain/minecraftgame.go
#	domain/steamgame.go
#	domain/structures.go
2023-02-12 19:44:17 +03:00
9234cc2edc merge games into one package 2023-02-12 19:43:44 +03:00
6ef821481e Merge remote-tracking branch 'origin/main' 2023-02-12 02:35:07 +03:00
fc4ba246f1 add shared structures 2023-02-12 02:34:22 +03:00
eb875ad3d2 fix imports 2023-02-12 02:33:58 +03:00
e9b915aa92 Merge remote-tracking branch 'origin/main' 2023-02-12 02:16:17 +03:00
4d926b1cfd add structures file for minecraft 2023-02-12 02:15:55 +03:00
c1d88d8288 add mod file 2023-02-12 02:06:53 +03:00
0cef129db6 add os stat to file validate method 2023-02-08 21:48:19 +03:00
1a2732df7a disable panic in reat dir error 2023-02-08 15:51:35 +03:00
682750ff48 Add file stat method 2023-02-06 16:19:35 +03:00
4cf354733c delete javaentites 2023-02-04 20:47:49 +03:00
815e624c64 Add osutils files 2023-02-04 20:47:42 +03:00
6f1cc3cc7c Add method ListDir 2023-02-04 14:13:00 +03:00
618b0b1639 Add fields in minecraft game 2023-02-03 21:37:09 +03:00
143eed4221 Add versions in minecraft game 2023-02-03 18:11:13 +03:00
ab2afeb177 add FindOsUrl function 2023-02-03 01:53:20 +03:00
4238de8568 fix file 2023-02-03 01:36:40 +03:00
b02c858b38 Add javaentities
# Conflicts:
#	redistruable/javaentities/java.go
2023-02-03 01:35:04 +03:00
010a8becd7 Add java entities
# Conflicts:
#	redistruable/javaentities/java.go
2023-02-03 01:34:48 +03:00
de188c1b8f add methods to sessions 2023-02-01 22:56:35 +03:00
370efca124 add osutils 2023-02-01 16:31:46 +03:00
877fb8ddf6 add get arguments 2023-01-30 09:23:23 +03:00
5c7a5256bd rename get interface method 2023-01-30 07:43:46 +03:00
b2c1867430 new domain, games, sessions 2023-01-24 16:46:17 +03:00
8a16a26b35 add profile struct 2023-01-15 17:03:31 +03:00
982b60bde6 new structs for api 2023-01-15 15:20:34 +03:00
d30e5633e9 rename package 2023-01-15 15:20:25 +03:00
a101fb122b Merge branch 'hyper-refactoring' 2023-01-15 00:26:26 +03:00
c1c27673d8 hyper refactoring 2023-01-15 00:17:27 +03:00
e8adbe4653 add sessions interface 2022-11-12 02:56:43 +03:00
bf4b92b296 rename packages 2022-11-11 17:22:34 +03:00
6ecd1f8846 add distribution model 2022-11-11 15:44:39 +03:00
5142258f2a add todo 2022-11-11 15:44:28 +03:00
e0905ef578 Merge remote-tracking branch 'origin/main' 2022-11-11 15:30:18 +03:00
4319b1e1b3 fix sessions 2022-11-11 15:30:08 +03:00
e2502298a9 Удалить 'sessionUtils/sessionUtils.go' 2022-11-11 12:19:05 +00:00
ce8d180154 Удалить 'sessionUtils/sessionTypes.go' 2022-11-11 12:18:59 +00:00
58eca5ea06 add domains utils 2022-11-11 15:15:42 +03:00
6abccc2e03 move session to games 2022-11-11 15:15:36 +03:00
c29d02423f delete fake session from utils and add assets to utils 2022-11-07 15:22:09 +03:00
15e727c6c3 Add backgorunds to games 2022-11-07 15:06:45 +03:00
1a0f0b9f17 fix import cases 2022-11-04 23:02:25 +03:00
b3471e847c fix imports 2022-11-04 21:35:40 +03:00
38deb49d6f rename module 2022-11-04 21:24:06 +03:00
0a440b9f9d create module 2022-11-04 21:14:25 +03:00
d41d09c605 Change to client import 2022-11-04 03:56:27 +03:00
7b3b12987b Add session id to fake game 2022-11-04 03:29:21 +03:00
126835b050 change fake game title 2022-11-04 03:29:10 +03:00
bd4d86a2df Merge remote-tracking branch 'origin/main'
# Conflicts:
#	sessionUtils/sessionTypes.go
2022-11-04 03:05:39 +03:00
7465dd9de1 add sessionId field 2022-11-04 03:03:38 +03:00
83ea88a3ab add func find session by id 2022-11-04 03:03:31 +03:00
f5ce5468a8 merge session utils 2022-11-04 03:03:05 +03:00
c035b05b46 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	sessionUtils/sessionUtils.go
2022-11-04 02:23:38 +03:00
948e31d4e3 fake sessions and arguments in sessions 2022-11-04 02:22:51 +03:00
a8dbeb6865 new fake games 2022-11-04 02:22:01 +03:00
672d491e60 new sessions struct 2022-11-04 02:21:44 +03:00
d645cbc860 New steam arguments 2022-11-03 23:12:26 +03:00
4e446adefc new version system 2022-11-02 22:57:15 +03:00
e5fa39bdad add win platform to fake gmod 2022-11-02 22:56:44 +03:00
0ae1cb8e0d rename method 2022-11-02 13:30:27 +03:00
bb446adb6f add fake sessions 2022-11-02 12:53:47 +03:00
1fc099c1be add decode json method 2022-11-02 12:53:30 +03:00
39232f8664 add TODO 2022-11-02 12:53:22 +03:00
75e96b9851 Create universal json decode util 2022-11-02 02:42:40 +03:00
7b9dfe0cee change type of update version struct 2022-11-02 02:42:10 +03:00
d498c453af add update type 2022-11-02 02:19:46 +03:00
23 changed files with 1042 additions and 150 deletions

37
auth/auth.go Normal file
View File

@ -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 {
}

43
domain/domain.go Normal file
View File

@ -0,0 +1,43 @@
package domain
// type Domains []SkirdaDomain
// func (domains Domains) Set(newDomains []SkirdaDomain) {
// domains = append([]SkirdaDomain{}, newDomains...)
// }
//func (domains Domains) FindGameByID(gameId string) (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() SkirdaGames {
// allGames := SkirdaGames{}
// for _, domain := range domains {
// allGames = append(allGames, domain.SkirdaGames...)
// }
// return allGames
//}
// func (domains Domains) GetSessions() SkirdaSessions {
// plainSessions := SkirdaSessions{}
// for _, domain := range domains {
// plainSessions = append(plainSessions, 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")
// }

33
domain/minecraftgame.go Normal file
View File

@ -0,0 +1,33 @@
package domain
// const gameType = "minecraft"
type MinecraftGame struct {
SkirdaGameId string
Assets GameUIAssets
Versions []string
}
func (game MinecraftGame) GetSkirdaGameId() string {
return game.SkirdaGameId
}
func (game MinecraftGame) GetUIAssets() GameUIAssets {
return game.Assets
}
func (game MinecraftGame) GetLaunchArgs() []string {
return []string{"", ""}
}
func (game MinecraftGame) GetType() string {
return "minecraft"
}
func (game MinecraftGame) GetArguments() Arguments {
return Arguments{}
}
func (game MinecraftGame) GetVersions() []string {
return game.Versions
}

43
domain/skirdagame.go Normal file
View File

@ -0,0 +1,43 @@
package domain
import "errors"
type SkirdaGame interface {
GetSkirdaGameId() string
GetUIAssets() GameUIAssets
GetLaunchArgs() []string
GetType() string
GetArguments() Arguments
}
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("")
}
type Argument struct {
Body string
Value string
}
type Arguments struct {
Required []Argument
Optional []Argument
}

128
domain/skirdasession.go Normal file
View File

@ -0,0 +1,128 @@
package domain
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
// GetGameId implements SkirdaSession
func (SkirdaSessions) GetGameId() string {
panic("unimplemented")
}
// GetGameType implements SkirdaSession
func (SkirdaSessions) GetGameType() string {
panic("unimplemented")
}
// GetSessionData implements SkirdaSession
func (SkirdaSessions) GetSessionData() string {
panic("unimplemented")
}
// GetSessionId implements SkirdaSession
func (SkirdaSessions) GetSessionId() string {
panic("unimplemented")
}
// GetUIAssets implements SkirdaSession
func (SkirdaSessions) GetUIAssets() SessionUIAssets {
panic("unimplemented")
}
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 ""
}

29
domain/steamgame.go Normal file
View File

@ -0,0 +1,29 @@
package domain
type SteamGame struct {
SkirdaGameId string
SteamId string
Assets GameUIAssets
Arguments Arguments
// CurrentVersion string
}
func (game SteamGame) GetSkirdaGameId() string {
return game.SkirdaGameId
}
func (game SteamGame) GetUIAssets() GameUIAssets {
return game.Assets
}
func (game SteamGame) GetLaunchArgs() []string {
return []string{"", ""}
}
func (game SteamGame) GetType() string {
return "steam"
}
func (game SteamGame) GetArguments() Arguments {
return game.Arguments
}

161
domain/structures.go Normal file
View File

@ -0,0 +1,161 @@
package domain
import "strconv"
type JavaVersion struct {
VersionNums `json:"version"`
Specifics []JavaVersionSpecifics `json:"specifics"`
}
func (jVer *JavaVersion) GetVersionString() string {
return strconv.Itoa(jVer.Major) + "." + strconv.Itoa(jVer.Minor) + "." + strconv.Itoa(jVer.Patch)
}
type JavaVersionSpecifics struct {
Os string `json:"os"`
Arch string `json:"arch"`
URL string `json:"URL"`
Sha1 string `json:"SHA1"`
}
func (jv *JavaVersion) FindOs(os string, arch string) *JavaVersionSpecifics {
for _, s := range jv.Specifics {
if s.Os == os && s.Arch == arch {
return &s
}
}
return nil
}
type VersionNums struct {
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
}
func (v *VersionNums) FillFromString(maj string, min string, patch string) error {
iMaj, err := strconv.Atoi(maj)
if err != nil {
return err
}
iMin := 0
iMin, err = strconv.Atoi(min)
if err != nil {
return err
}
iPatch := 0
iPatch, err = strconv.Atoi(patch)
if err != nil {
return err
}
v.Major = iMaj
v.Minor = iMin
v.Patch = iPatch
return nil
}
type Version struct {
AssetIndex AssetIndex `json:"assetIndex"`
Downloads struct {
Client Artifact `json:"client"`
Server Artifact `json:"server"`
Mods struct {
Required []ModArtifact `json:"required"`
} `json:"mods"`
} `json:"downloads"`
ID string `json:"id"`
Libraries []Lib `json:"libraries"`
//ClientLog LogCfg
MainClass string `json:"mainClass"`
GameArgs []Argument
JVMArgs []Argument
Type string `json:"type"`
JavaVersion JavaVersion `json:"javaVersion"`
}
type AssetIndex struct {
ID string `json:"id"`
TotalSize uint64 `json:"totalSize"`
Artifact
}
// type Argument struct {
// Value string `json:"value"`
// Rules []Rule `json:"rules"`
// }
type JavaVersionClientDistribution struct { //TODO Rename
Component string `json:"component"`
MajorVersion int `json:"majorVersion"`
}
type Rule struct {
Action RuleAct `json:"action" mapstructure:"action"`
// OS information. All fields are regexes.
OS struct {
Name string `json:"name" mapstructure:"name"`
Version string `json:"version" mapstructure:"version"`
Arch string `json:"arch" mapstructure:"arch"`
} `json:"os" mapstructure:"os"`
Features struct {
IsDemoUser *bool `json:"is_demo_user" mapstructure:"is_demo_user"`
HasCustomResolution *bool `json:"has_custom_resolution" mapstructure:"has_custom_resolution"`
} `json:"features" mapstructure:"features"`
}
type RuleAct string
const (
ActAllow RuleAct = "allow"
ActDisallow RuleAct = "disallow"
)
type LibClassifiers struct {
JavaDoc *Artifact `json:"javadoc"`
NativesLinux *Artifact `json:"natives-linux"`
NativesMacOS *Artifact `json:"natives-osx"`
NativesWin *Artifact `json:"natives-windows"`
Sources *Artifact `json:"sources"`
}
type Lib struct {
Downloads struct {
MainJar *Artifact `json:"artifact"`
LibClassifiers `json:"classifiers"`
} `json:"downloads"`
NativeSuffixes struct {
Linux string `json:"linux"`
MacOS string `json:"osx"`
Windows string `json:"windows"`
} `json:"natives"`
Name string `json:"name"`
Rules []Rule `json:"rules"`
ExtractRules struct {
Exclude []string `json:"exclude"`
} `json:"extract"`
}
type Artifact struct {
SHA1 string `json:"sha1"`
Size uint64 `json:"size"`
URL string `json:"url"`
}
type ModArtifact struct {
Artifact
File string
Name string
Version string
}
type VersionMeta struct {
ID string `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
Installed bool
}

View File

@ -1,10 +0,0 @@
package domainutilsgo
import (
"../gameUtils"
)
type Domain struct {
ServerId string
Games []gameUtils.Game
}

View File

@ -1,39 +0,0 @@
package gameUtils
var garrysmodGame = SteamGame{
GameId: "garrysmod",
SteamId: "4000",
Args: []string{},
Platforms: map[string]bool{"linux": true},
Assets: GameInterfaceAssets{
Title: "Garry's Mod",
Icon: "icon.png",
Description: "",
},
}
var openarena = SteamGame{
GameId: "openarena",
SteamId: "",
//Executable: "/usr/games/openarena",
Args: []string{},
Assets: GameInterfaceAssets{
Title: "Open Arena",
Icon: "icon.png",
Description: "asdadasd",
},
}
var minecraft = SteamGame{
GameId: "minecraft",
SteamId: "",
Args: []string{},
Assets: GameInterfaceAssets{
Title: "Minecraft",
Icon: "icon.png",
Description: "Minecraft Game",
},
Platforms: map[string]bool{},
}
var SteamFakeGamesList = []SteamGame{garrysmodGame, openarena, minecraft}

View File

@ -1,26 +0,0 @@
package gameUtils
type SteamGame struct {
GameId string
SteamId string
Args []string
Assets GameInterfaceAssets
Platforms map[string]bool
}
type GameInterfaceAssets struct {
Title string
Icon string
Description 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"`
}

View File

@ -1,41 +0,0 @@
package gameUtils
import (
"encoding/json"
)
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 ConvertServerGamesToJSON(g Games) []byte {
g_json, err := json.Marshal(g)
_ = err //TODO: Check Errors
return g_json
}

33
osutils/data.go Normal file
View File

@ -0,0 +1,33 @@
package osutils
import (
"github.com/pkg/errors"
"unicode"
)
func UuidValidate(uuid string) error {
if len(uuid) != 36 {
return errors.New("uuid length not valid")
}
for i, r := range uuid {
switch i {
case 8, 13, 18, 23:
if r != '-' {
return errors.New("uuid separator not valid")
}
break
default:
if !isLetter(r) && !unicode.IsDigit(r) {
return errors.Errorf("uuid char on %i not valid", i)
}
}
}
return nil
}
func isLetter(r rune) bool {
l := unicode.ToLower(r)
return (l >= 'a' && l <= 'f')
}

122
osutils/files.go Normal file
View File

@ -0,0 +1,122 @@
package osutils
import (
"crypto/sha1"
"encoding/hex"
"io"
"io/fs"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"strings"
)
func IsDirectory(path string) (bool, error) {
fileInfo, err := os.Stat(path)
if err != nil {
return false, err
}
return fileInfo.IsDir(), err
}
func RecursiceWalk(pathToWalk string) ([]string, error) {
paths := []string{}
err := filepath.Walk(pathToWalk,
func(path string, info os.FileInfo, err error) error {
if err != nil {
println(err)
return err
}
// fmt.Println(path[len(path)-4:])
libBool, err := IsDirectory(path)
if err != nil {
println("error in checking lib or dir")
}
if !libBool {
// println(path)
paths = append(paths, path)
}
return nil
})
if err != nil {
log.Println(err)
}
return paths, nil
}
func ListDir(path string) ([]fs.FileInfo, error) {
files, err := ioutil.ReadDir(path)
if err != nil {
return []fs.FileInfo{}, err
}
return files, nil
}
func GetParentDir(filePath string) (string, error) {
cuttedPath := strings.Split(filePath, "/")
cuttedPath = cuttedPath[:len(cuttedPath)-1]
finalPath := path.Join("/", path.Join(cuttedPath...))
return finalPath, nil
}
type FileValidationInfo struct {
Path string
fs.FileInfo
SHA1 string
}
func ValidateFile(filePath string) (*FileValidationInfo, error) {
info := FileValidationInfo{
Path: filePath,
FileInfo: nil,
SHA1: "",
}
info.Path = filePath
stat, err := os.Stat(filePath)
if err != nil {
return &info, err
}
info.FileInfo = stat
hash, err := GetFileHash(filePath)
if err != nil {
return &info, err
}
info.SHA1 = hash
return &info, nil
}
func GetFileHash(filePath string) (string, error) {
//Initialize variable returnMD5String now in case an error has to be returned
var returnSHA1String string
//Open the filepath passed by the argument and check for any error
file, err := os.Open(filePath)
if err != nil {
return "", err
}
//Tell the program to call the following function when the current function returns
defer file.Close()
//Open a new SHA1 hash interface to write to
hash := sha1.New()
//Copy the file in the hash interface and check for any error
if _, err := io.Copy(hash, file); err != nil {
return returnSHA1String, err
}
//Get the 20 bytes hash
hashInBytes := hash.Sum(nil)[:20]
//Convert the bytes to a string
returnSHA1String = hex.EncodeToString(hashInBytes)
return returnSHA1String, nil
}

48
osutils/json.go Normal file
View File

@ -0,0 +1,48 @@
package osutils
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
func WriteStructAsJSON(data interface{}, JsonPath string) error {
file, _ := json.MarshalIndent(data, "", " ")
directory, err := GetParentDir(JsonPath)
if err != nil {
return err
}
err = os.MkdirAll(directory+"/", os.ModePerm)
if err != nil {
return err
}
err = ioutil.WriteFile(JsonPath, file, 0644)
if err != nil {
return err
}
return nil
}
func ReadJsonFromDisk(target interface{}, filePath string) error {
// Open our jsonFile
jsonFile, err := os.Open(filePath)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
return err
}
// fmt.Println("Successfully Opened users.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
// we unmarshal our byteArray which contains our
// jsonFile's content into 'users' which we defined above
json.Unmarshal(byteValue, &target)
return nil
}

View File

@ -0,0 +1,75 @@
package javaentities
// type JavaVersion struct {
// Component string
// Type string
// Name string
// Major int
// Minor int
// Patch int
// }
// type JavaMetas struct {
// JavaVersions []JavaMeta `json:"javaVersions"`
// }
// func (jm JavaMetas) FindSpecificJavaOsByMajor(version JavaVersion) (SpecificJavaVersion, error) {
// for _, v := range jm.JavaVersions {
// if version.Major == v.Version.Major {
// jv, err := v.getOsJava()
// if err != nil {
// continue
// }
// return jv, nil
// }
// }
// return SpecificJavaVersion{}, errors.New("cant find os url")
// }
// func (jm JavaMetas) FindSpecificJava(MajorVersion string)
// type JavaMeta struct {
// Version struct {
// Major int `json:"major"`
// Minor int `json:"minor"`
// Patch int `json:"patch"`
// } `json:"version"`
// Name string
// Specifics `json:"specifics"`
// }
// type SpecificJavaVersion struct {
// Os string `json:"os"`
// Arch string `json:"arch"`
// URL string `json:"URL"`
// Sha1 string `json:"SHA1"`
// }
// type Specifics []SpecificJavaVersion
// func (s Specifics) getOsJava() (SpecificJavaVersion, error) {
// for _, v := range s {
// if v.Os == runtime.GOOS {
// return v, nil
// }
// }
// return SpecificJavaVersion{}, errors.New("not java for current os")
// }
// func (v *JavaVersion) CheckNotExists(launcherPath string) bool {
// javaBinPath := path.Join(launcherPath, ".redist", "java", v.GetString())
// _, err := os.Stat(javaBinPath)
// return err != nil
// }
// func (v *JavaVersion) GetString() string {
// var stringBuilder strings.Builder
// stringBuilder.WriteString(strconv.Itoa(v.Major))
// stringBuilder.WriteRune('.')
// stringBuilder.WriteString(strconv.Itoa(v.Minor))
// stringBuilder.WriteRune('.')
// stringBuilder.WriteString(strconv.Itoa(v.Patch))
// return stringBuilder.String()
// }

View File

@ -1,23 +0,0 @@
package sessionUtils
import (
"time"
)
type Session struct {
GameId string
Icon string
Title string
Status string
Version string
Expires time.Time
}
type JSSessionInterface struct {
GameID string `json:"gameId"`
Icon string `json:"icon"`
Title string `json:"title"`
Status string `json:"status"`
Version string `json:"version"`
Expires time.Time `json:"expires"`
}

View File

@ -1,11 +0,0 @@
package sessionUtils
import (
"encoding/json"
)
func ConvertServerSessionsToJSON(s Session) []byte {
s_json, err := json.Marshal(s)
_ = err //TODO: Check Errors
return s_json
}

158
sharedDistribution/games.go Normal file
View File

@ -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
}

View File

@ -0,0 +1,63 @@
package sharedDistribution
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{},
}
}

46
sharedauth/sharedauth.go Normal file
View File

@ -0,0 +1,46 @@
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 `json:"redirecturl"`
RequestId string `json:"requestid"`
}
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 {
}
type SkirdaUserResp struct {
SkirdaUserId string `json:"skirdauser_id"`
Username string `json:"username"`
Token string `json:"token"`
}

9
skirdaobjects/domains.go Normal file
View File

@ -0,0 +1,9 @@
package skirdaobjects
import "skirdaGoLauncher/games/localgame"
type SkirdaDomainApi struct {
SkirdaDomainId string `json:"skirdaDomainId"`
Games []localgame.LocalSkirdaGame2 `json:"games"`
Events []SkirdaEventApi `json:"events"`
}

7
skirdaobjects/events.go Normal file
View File

@ -0,0 +1,7 @@
package skirdaobjects
type SkirdaEventApi struct {
SkirdaEventId string `json:"skirdaevent_id"`
SkirdaGameId string `json:"skirdagame_id"`
Title string `json:"title"`
}

7
skirdaobjects/games.go Normal file
View File

@ -0,0 +1,7 @@
package skirdaobjects
// type SkirdaGameApi struct {
// SkirdaGameId string `json:"skirdagame_id"`
// Title string `json:"title"`
// Type string `json:"type"`
// }