-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
149 lines (141 loc) · 2.71 KB
/
main.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
package main
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"log"
"net"
"net/http"
"net/url"
"strings"
"github.com/Masterminds/semver/v3"
"github.com/xmdhs/gomclauncher/auth"
aflag "github.com/xmdhs/gomclauncher/flag"
"github.com/xmdhs/gomclauncher/internal"
"github.com/xmdhs/gomclauncher/lang"
"github.com/xmdhs/gomclauncher/launcher"
)
func main() {
if v {
version()
}
if tidy {
f.Tidy()
return
}
if f.Proxy != "" {
proxy, err := url.Parse(f.Proxy)
if err != nil {
panic(err)
}
auth.Transport.Proxy = http.ProxyURL(proxy)
}
if credit {
credits()
}
if f.Verlist != "" {
f.Arunlist()
}
if f.Runlist {
s := aflag.Find(launcher.Minecraft + `/versions`)
for _, v := range s {
if aflag.Test(launcher.Minecraft + `/versions/` + v + `/` + v + ".json") {
fmt.Println(v)
}
}
}
if f.Download != "" {
f.Outmsg = false
f.D()
}
if list {
f.Listname()
}
if f.ApiAddress != "" {
f.Authlib()
} else {
f.ApiAddress = "https://authserver.mojang.com"
}
if remove {
f.Remove(ms)
return
}
if ms {
f.MsLogin()
} else {
if f.Email != "" {
f.Aonline()
} else {
f.UUID = aflag.UUIDgen(f.Name)
f.AccessToken = f.UUID
}
}
if f.Runflag != "" {
s := strings.Split(f.Runflag, " ")
f.Flag = s
}
f.Gameinfo.RAM = f.RAM
if f.Run != "" {
if f.Name == "" && f.Email == "" {
fmt.Println(lang.Lang("nousername"))
} else {
f.Arun()
}
}
if update {
check()
}
}
type up struct {
Version string `json:"version"`
Msg string `json:"msg"`
}
func check() {
version, err := checkByDns()
if err != nil {
log.Println(err)
return
}
b, err := base64.StdEncoding.DecodeString(version)
if err != nil {
log.Println(err)
return
}
u := up{}
err = json.Unmarshal(b, &u)
if err != nil {
fmt.Println(lang.Lang("checkupdateerr"))
fmt.Println(err)
return
}
s, err := semver.NewVersion(u.Version)
if err != nil {
fmt.Println(lang.Lang("checkupdateerr"))
fmt.Println(err)
return
}
if s.GreaterThan(semver.MustParse(launcher.Launcherversion)) {
fmt.Println(lang.Lang("checkupdate"), u.Version)
fmt.Println(lang.Lang("nowversion"), launcher.Launcherversion)
fmt.Println(lang.Lang("updateinfo"))
fmt.Println(u.Msg)
}
}
var Errtxt = errors.New("LookupTXT err")
func checkByDns() (string, error) {
l, err := net.LookupTXT("gml.xmdhs.com")
if err != nil {
return "", fmt.Errorf("checkByDns: %w", err)
}
if len(l) != 1 {
return "", fmt.Errorf("checkByDns: %w", Errtxt)
}
return l[0], nil
}
func version() {
fmt.Println("gomclauncher-" + internal.Launcherversion + "-" + internal.GitHash)
fmt.Println("Build date: " + buildDate)
fmt.Println("Build on: " + buildOn)
fmt.Println("Repository: https://github.com/xmdhs/gomclauncher")
}