Skip to content

Commit

Permalink
更改所使用的 ua
Browse files Browse the repository at this point in the history
  • Loading branch information
xmdhs committed Feb 10, 2024
1 parent d7bcbb4 commit ecc3ca2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
gml.json
.minecraft
.minecraft
*.exe
6 changes: 6 additions & 0 deletions internal/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package internal

const (
Launcherbrand string = "GML"
Launcherversion string = "1.4.15"
)
16 changes: 15 additions & 1 deletion internal/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"time"
)
Expand All @@ -23,6 +24,19 @@ func Getarch() string {
}
}

var ua string

func init() {
b, _ := debug.ReadBuildInfo()
var hash string
for _, v := range b.Settings {
if v.Key == "vcs.revision" {
hash = v.Value
}
}
ua = fmt.Sprintf("gomclauncher/%s (%v)", Launcherversion, hash)
}

func HttpGet(cxt context.Context, aurl string, t *http.Transport, header http.Header) (*http.Response, *time.Timer, error) {
ctx, cancel := context.WithCancel(cxt)
rep, err := http.NewRequestWithContext(ctx, "GET", aurl, nil)
Expand All @@ -36,7 +50,7 @@ func HttpGet(cxt context.Context, aurl string, t *http.Transport, header http.He
rep.Header = header
}
rep.Header.Set("Accept", "*/*")
rep.Header.Set("User-Agent", "Mozilla/5.0(Windows NT 10.0;Win64;x64;rv:115.0) Gecko/20100101 Firefox/115.0")
rep.Header.Set("User-Agent", ua)
c := http.Client{
Transport: t,
}
Expand Down
6 changes: 4 additions & 2 deletions launcher/info.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package launcher

import "github.com/xmdhs/gomclauncher/internal"

const (
Launcherbrand string = "GML"
Launcherversion string = "1.4.15"
Launcherbrand string = internal.Launcherbrand
Launcherversion string = internal.Launcherversion
)

const Minecraft string = ".minecraft"

0 comments on commit ecc3ca2

Please sign in to comment.