Compare commits

..

No commits in common. "main" and "hyper-refactoring" have entirely different histories.

16 changed files with 3 additions and 819 deletions

View File

@ -1,37 +1,5 @@
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 {
type InstallId struct {
InstallId string
}

View File

@ -1,43 +0,0 @@
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")
// }

View File

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

View File

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

View File

@ -1,128 +0,0 @@
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 ""
}

View File

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

View File

@ -1,161 +0,0 @@
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,33 +0,0 @@
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')
}

View File

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

View File

@ -1,48 +0,0 @@
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

@ -1,75 +0,0 @@
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,4 +1,4 @@
package sharedDistribution
package sharedUtils
import (
"time"

View File

@ -1,46 +0,0 @@
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"`
}

View File

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

View File

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

View File

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