-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.go
167 lines (155 loc) · 5.84 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package main
import "os"
import "fmt"
import "io/ioutil"
import "github.com/tidwall/gjson"
func ArgsParse() {
// If Nonthing is set then default to --help
if len(os.Args) <= 1 {
Help()
} else {
// Args is 1 or longer so parse time!
// Order here is important!
if os.Args[1] == "--help" {
Help()
}
if os.Args[1] == "--status" {
Status()
}
if os.Args[1] == "--list-profiles" {
ListProfiles()
}
if os.Args[1] == "--list-fabric-versions" {
if len(os.Args) <= 2 {
fmt.Println("Missing Required argument run `./Mcboop --help` for help")
} else {
ListFabricVersions(os.Args[2])
}
}
if os.Args[1] == "--add-account" {
// Make sure there are enough args
if len(os.Args) <= 2 {
// Not enough Args to add an account
fmt.Println("Run `./Mcboop --help` for help")
} else {
// Enough args to add an account
auth := AuthAccount(os.Args[2], os.Args[3])
AddAccount(auth)
fmt.Println("Added account:", gjson.Get(auth, "selectedProfile.name"))
}
}
if os.Args[1] == "--list-accounts" {
// Verify that accounts.json is there!
if !CheckForFile(GetMcBoopDir() + "accounts.json") {
fmt.Println("Accounts json not found!")
os.Exit(0)
}
users := ListAccounts()
fmt.Println("")
fmt.Println("Current added accounts")
fmt.Println("================")
for i := 0; i < len(users); i++ {
if users[i] == GetDefaultAccount() {
fmt.Println(users[i], "<- Default")
} else {
fmt.Println(users[i])
}
}
fmt.Println("================")
fmt.Println("")
}
if os.Args[1] == "--list-mc-versions" {
release, snapshot, list := ListMCVersions()
fmt.Println("")
fmt.Println("Here are a list of playable versions")
fmt.Println("")
for i := 0; i < len(list); i++ {
if (i + 1) >= len(list) {
fmt.Print(list[i])
} else {
fmt.Print(list[i] + ", ")
}
}
fmt.Println("")
fmt.Println("")
fmt.Println("Current stable is:", release)
fmt.Println("Current snapshot is:", snapshot)
fmt.Println("")
}
if os.Args[1] == "--run" {
runGame()
}
}
}
func Help() {
// System will exit when you call this!
fmt.Println("")
fmt.Println("==== McBoop Help ====")
fmt.Println("")
fmt.Println("<> Signify required args, [] Signify optional args")
fmt.Println("")
fmt.Println("./McBoop --help => Shows this page.")
fmt.Println("")
fmt.Println("./McBoop --status => Shows mojang status.")
fmt.Println("")
fmt.Println("./McBoop --add-account <username> <password> => Add a new account, The first account added becomes the default. ( This can be changed later ) ")
fmt.Println("")
fmt.Println("./Mcboop --list-accounts => List all saved accounts.")
fmt.Println("")
fmt.Println("./McBoop --list-mc-versions => List all playable MC versions.")
fmt.Println("")
fmt.Println("./Mcboop --run <version> => Runs Minecraft <version>.")
fmt.Println("")
fmt.Println("./Mcboop --user <username> => Used with `--run` to select a spefic user to run the game with")
fmt.Println("")
fmt.Println("./Mcboop --profile <profile name> => Used with `--run` to run in a non-default profile")
fmt.Println("")
fmt.Println("./Mcboop --ram <max amount> => Used with `--run` to set maximum amount of RAM ( Default is 4G )")
fmt.Println("")
fmt.Println("./Mcboop --list-profiles => List all profiles")
fmt.Println("")
fmt.Println("./McBoop --forge => Used with `--run` will try to install and run the forge installer jar inside the profile directory this file must be named `forge.jar`")
fmt.Println("")
fmt.Println("./Mcboop --no-verify-client => Used with `--run` will not verify client jar")
fmt.Println("")
fmt.Println("./McBoop --list-fabric-versions => List all Fabric versions")
fmt.Println("")
fmt.Println("./McBoop --fabric [fabric version] => Used with `--run` if [fabric version] is not defined will install the latest version for Minecraft")
fmt.Println("")
os.Exit(0)
}
func Status() {
// System will exit upon calling this
status := gjson.Parse(GetRemoteText("https://status.mojang.com/check"))
fmt.Println("")
fmt.Println("==== Minecraft server status ====")
fmt.Println("")
fmt.Println("Minecraft.net status:", status.Get("#.minecraft\\.net").Array()[0].String())
fmt.Println("Session.Minecraft.net status:", status.Get("#.session\\.minecraft\\.net").Array()[0].String())
fmt.Println("Textures.Minecraft.net Status:", status.Get("#.textures\\.minecraft\\.net").Array()[0].String())
fmt.Println("Mojang.com status:", status.Get("#.mojang\\.com").Array()[0].String())
fmt.Println("Account.Mojang.com status:", status.Get("#.account\\.mojang\\.com").Array()[0].String())
fmt.Println("Authserver.Mojang.com status:", status.Get("#.authserver\\.mojang\\.com").Array()[0].String())
fmt.Println("Sessionserver.Mojang.com status:", status.Get("#.sessionserver\\.mojang\\.com").Array()[0].String())
fmt.Println("Api.Mojang.com status:", status.Get("#.api\\.mojang\\.com").Array()[0].String())
fmt.Println("")
os.Exit(0)
}
func ListMCVersions() (string, string, []string) {
versions := gjson.Parse(GetRemoteText("https://launchermeta.mojang.com/mc/game/version_manifest.json"))
var list []string
for i := 0; i < len(versions.Get("versions.#.id").Array()); i++ {
list = append(list, versions.Get("versions.#.id").Array()[i].String())
}
return versions.Get("latest.release").String(), versions.Get("latest.snapshot").String(), list
}
func ListProfiles() {
files, _ := ioutil.ReadDir(GetMcBoopDir() + "profiles")
fmt.Println("")
fmt.Println("==== Currently installed profiles ====")
for i := 0; i < len(files); i++ {
fmt.Println("\"" + files[i].Name() + "\"")
}
fmt.Println("")
os.Exit(0)
}