Compare commits
106 Commits
Author | SHA1 | Date | |
---|---|---|---|
c853ee3a55 | |||
43070c0642 | |||
b99ca4621a | |||
589fcf0579 | |||
e17b938ef2 | |||
cf26a112f2 | |||
e88fb5c1da | |||
16583fc689 | |||
55433b7d11 | |||
2a7c682ffa | |||
9fe3a02e9f | |||
d0a5e5fb0b | |||
928edc1efe | |||
a86bb964e5 | |||
0495d1efb1 | |||
3933b4e16f | |||
4465fa52c1 | |||
528846c002 | |||
b397940fef | |||
2f451f2be4 | |||
3e0fa1d5c1 | |||
8a698b8b1d | |||
d254f698d3 | |||
9e0033149d | |||
fd9bb44e28 | |||
3b41207354 | |||
77addd32dc | |||
7e2a75d11d | |||
38f9900901 | |||
4bc1db5397 | |||
145c56e9f6 | |||
f44e6b104b | |||
1cb34f3e6c | |||
ebeb05cd1a | |||
2b95a109c6 | |||
0dce90931c | |||
cee68d0d61 | |||
d21061e36d | |||
79886cbfae | |||
605da815cd | |||
9234cc2edc | |||
6ef821481e | |||
fc4ba246f1 | |||
eb875ad3d2 | |||
e9b915aa92 | |||
4d926b1cfd | |||
c1d88d8288 | |||
0cef129db6 | |||
1a2732df7a | |||
682750ff48 | |||
4cf354733c | |||
815e624c64 | |||
6f1cc3cc7c | |||
618b0b1639 | |||
143eed4221 | |||
ab2afeb177 | |||
4238de8568 | |||
b02c858b38 | |||
010a8becd7 | |||
de188c1b8f | |||
370efca124 | |||
877fb8ddf6 | |||
5c7a5256bd | |||
b2c1867430 | |||
8a16a26b35 | |||
982b60bde6 | |||
d30e5633e9 | |||
a101fb122b | |||
c1c27673d8 | |||
e8adbe4653 | |||
bf4b92b296 | |||
6ecd1f8846 | |||
5142258f2a | |||
e0905ef578 | |||
4319b1e1b3 | |||
e2502298a9 | |||
ce8d180154 | |||
58eca5ea06 | |||
6abccc2e03 | |||
c29d02423f | |||
15e727c6c3 | |||
1a0f0b9f17 | |||
b3471e847c | |||
38deb49d6f | |||
0a440b9f9d | |||
d41d09c605 | |||
7b3b12987b | |||
126835b050 | |||
bd4d86a2df | |||
7465dd9de1 | |||
83ea88a3ab | |||
f5ce5468a8 | |||
c035b05b46 | |||
948e31d4e3 | |||
a8dbeb6865 | |||
672d491e60 | |||
d645cbc860 | |||
4e446adefc | |||
e5fa39bdad | |||
0ae1cb8e0d | |||
bb446adb6f | |||
1fc099c1be | |||
39232f8664 | |||
75e96b9851 | |||
7b9dfe0cee | |||
d498c453af |
37
auth/auth.go
Normal file
37
auth/auth.go
Normal 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
43
domain/domain.go
Normal 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
33
domain/minecraftgame.go
Normal 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
43
domain/skirdagame.go
Normal 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
128
domain/skirdasession.go
Normal 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
29
domain/steamgame.go
Normal 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
161
domain/structures.go
Normal 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
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package domainutilsgo
|
||||
|
||||
import (
|
||||
"../gameUtils"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
ServerId string
|
||||
Games []gameUtils.Game
|
||||
}
|
@ -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}
|
@ -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"`
|
||||
}
|
@ -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
33
osutils/data.go
Normal 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
122
osutils/files.go
Normal 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
48
osutils/json.go
Normal 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
|
||||
}
|
75
redistruable/javaentities/java.go
Normal file
75
redistruable/javaentities/java.go
Normal 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()
|
||||
// }
|
@ -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"`
|
||||
}
|
@ -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
158
sharedDistribution/games.go
Normal 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
|
||||
}
|
63
sharedDistribution/sessions.go
Normal file
63
sharedDistribution/sessions.go
Normal 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
46
sharedauth/sharedauth.go
Normal 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
9
skirdaobjects/domains.go
Normal 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
7
skirdaobjects/events.go
Normal 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
7
skirdaobjects/games.go
Normal file
@ -0,0 +1,7 @@
|
||||
package skirdaobjects
|
||||
|
||||
// type SkirdaGameApi struct {
|
||||
// SkirdaGameId string `json:"skirdagame_id"`
|
||||
// Title string `json:"title"`
|
||||
// Type string `json:"type"`
|
||||
// }
|
Loading…
Reference in New Issue
Block a user