Skip to content

Commit 25dfa3f

Browse files
fix: 更新版本 (#42)
* fix: 更新版本 * chore: update go 1.25 * chore: update lint * chore: update lint config * ci(chore): Fix stylings --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2e3e816 commit 25dfa3f

13 files changed

Lines changed: 192 additions & 186 deletions

File tree

.github/workflows/golint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup Go environment
1313
uses: actions/setup-go@v5
1414
with:
15-
go-version: '1.24'
15+
go-version: '1.25'
1616
cache: false
1717

1818
- name: Sort imports
@@ -22,7 +22,7 @@ jobs:
2222
goimports-reviser -imports-order std,blanked,general,company,project -recursive ./..
2323
2424
- name: golangci-lint
25-
uses: golangci/golangci-lint-action@v6
25+
uses: golangci/golangci-lint-action@v7
2626
with:
2727
version: latest
2828
skip-cache: true

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Go
2121
uses: actions/setup-go@v5
2222
with:
23-
go-version: '1.24'
23+
go-version: '1.25'
2424

2525
- name: Run GoReleaser
2626
uses: goreleaser/goreleaser-action@v4

.golangci.yml

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
1-
linters-settings:
2-
errcheck:
3-
exclude-functions:
4-
- fmt:.*
5-
- io/ioutil:^Read.*
6-
7-
goimports:
8-
local-prefixes: github.com/Mrs4s/go-cqhttp
9-
10-
gocritic:
11-
disabled-checks:
12-
- exitAfterDefer
13-
14-
forbidigo:
15-
# Forbid the following identifiers
16-
forbid:
17-
- ^fmt\.Errorf$ # consider errors.Errorf in github.com/pkg/errors
1+
version: "2"
182

193
linters:
20-
# please, do not use `enable-all`: it's deprecated and will be removed soon.
21-
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
22-
disable-all: true
23-
fast: false
4+
# please, do not use `default: all`: inverted configuration with all linters
5+
# and disabled linters is not scalable during updates of golangci-lint.
6+
default: none
247
enable:
258
- bodyclose
269
- durationcheck
27-
- gofmt
28-
- goimports
2910
- errcheck
3011
- exhaustive
3112
- bidichk
3213
- gocritic
33-
- gosimple
3414
- govet
3515
- ineffassign
3616
#- nolintlint
3717
- staticcheck
38-
- stylecheck
3918
- unconvert
4019
- usestdlibvars
4120
- unparam
@@ -47,9 +26,46 @@ linters:
4726
- revive
4827
- forbidigo
4928
- makezero
29+
settings:
30+
errcheck:
31+
exclude-functions:
32+
- fmt:.*
33+
- io/ioutil:^Read.*
34+
35+
gocritic:
36+
disabled-checks:
37+
- exitAfterDefer
38+
39+
forbidigo:
40+
# Forbid the following identifiers
41+
forbid:
42+
- pattern: ^fmt\.Errorf$ # consider errors.Errorf in github.com/pkg/errors
43+
exclusions:
44+
generated: lax
45+
rules:
46+
- path: (.+)\.go$
47+
text: "Error return value of .((os.)?std(out|err)..*|.*Close|.*Seek|.*Flush|os.Remove(All)?|.*print(f|ln)?|os.(Un)?Setenv). is not check"
48+
paths:
49+
- db
50+
- cmd/api-generator
51+
- internal/encryption
52+
53+
formatters:
54+
enable:
55+
- gofmt
56+
- goimports
57+
settings:
58+
goimports:
59+
local-prefixes:
60+
- github.com/Mrs4s/go-cqhttp
61+
exclusions:
62+
paths:
63+
- db
64+
- cmd/api-generator
65+
- internal/encryption
5066

5167
run:
52-
# default concurrency is a available CPU number.
68+
# default concurrency is an available CPU number.
5369
# concurrency: 4 # explicitly omit this value to fully utilize available resources.
5470
timeout: 5m
5571
issues-exit-code: 1
@@ -58,18 +74,12 @@ run:
5874
# output configuration options
5975
output:
6076
formats:
61-
- format: colored-line-number
77+
text:
6278
path: stdout
63-
print-issued-lines: true
64-
print-linter-name: true
79+
print-issued-lines: true
80+
print-linter-name: true
81+
colors: true
6582

6683
issues:
6784
# Fix found issues (if it's supported by the linter)
6885
fix: true
69-
exclude-use-default: false
70-
exclude:
71-
- "Error return value of .((os.)?std(out|err)..*|.*Close|.*Seek|.*Flush|os.Remove(All)?|.*print(f|ln)?|os.(Un)?Setenv). is not check"
72-
exclude-dirs:
73-
- db
74-
- cmd/api-generator
75-
- internal/encryption

cmd/gocq/main.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/hex"
99
"errors"
1010
"fmt"
11-
"net/url"
1211
"os"
1312
"path"
1413
"sync"
@@ -212,7 +211,7 @@ func LoginInteract() {
212211
time.Sleep(time.Second * 5)
213212
}
214213
log.Info("开始尝试登录并同步消息...")
215-
app := auth.AppList["linux"]["3.2.15-30366"]
214+
app := auth.AppList["linux"]["3.2.26-46494"]
216215
log.Infof("使用协议: %s", app.CurrentVersion)
217216
cli = newClient(app)
218217
cli.UseDevice(device)
@@ -431,19 +430,15 @@ func PasswordHashDecrypt(encryptedPasswordHash string, key []byte) ([]byte, erro
431430
}
432431

433432
func newClient(app *auth.AppInfo) *client.QQClient {
434-
signUrls := make([]string, 0, len(base.SignServers))
435-
for _, s := range base.SignServers {
436-
u, err := url.Parse(s.URL)
437-
if err != nil || u.Hostname() == "" {
438-
continue
439-
}
440-
signUrls = append(signUrls, u.String())
433+
var uin uint32
434+
if base.Account != nil && base.Account.Uin > 0 {
435+
uin = uint32(base.Account.Uin)
441436
}
442-
c := client.NewClientEmpty()
437+
c := client.NewClientMD5(uin, [16]byte{})
443438
c.UseVersion(app)
444439
signer := newSigner()
445440
c.UseSignProvider(signer)
446-
c.AddSignServer(signUrls...)
441+
signer.AddSignServer(base.SignServers...)
447442
signer.init()
448443
// TODO 服务器更新通知
449444
// c.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {

cmd/gocq/sign.go

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
log "github.com/sirupsen/logrus"
2222

2323
"github.com/Mrs4s/go-cqhttp/internal/base"
24+
"github.com/Mrs4s/go-cqhttp/modules/config"
2425
)
2526

2627
const serverLatencyDown = math.MaxUint32
@@ -39,6 +40,7 @@ type (
3940

4041
remote struct {
4142
server string
43+
token string
4244
latency atomic.Uint32
4345
}
4446
)
@@ -50,27 +52,18 @@ func newSigner() *signer {
5052
}
5153
}
5254

53-
func (c *signer) init() {
54-
go func() {
55-
c.check()
56-
ticker := time.NewTicker(30 * time.Minute)
57-
defer ticker.Stop()
58-
select {
59-
case <-c.doneChan:
60-
return
61-
case <-ticker.C:
62-
c.check()
63-
}
64-
}()
65-
}
55+
func (c *signer) init() {}
6656

6757
// Release 释放资源
6858
func (c *signer) Release() {
6959
close(c.doneChan)
7060
}
7161

7262
// Sign 对数据包签名
73-
func (c *signer) Sign(cmd string, seq uint32, data []byte) (*sign.Response, error) {
63+
func (c *signer) Sign(cmd string, seq uint32, data []byte, uin uint32, guid, qua string) (*sign.Response, error) {
64+
if !sign.ContainSignPKG(cmd) {
65+
return nil, nil
66+
}
7467
sortFlag := false
7568
defer func() {
7669
if sortFlag {
@@ -81,7 +74,7 @@ func (c *signer) Sign(cmd string, seq uint32, data []byte) (*sign.Response, erro
8174
c.lock.RLock()
8275
defer c.lock.RUnlock()
8376
for _, instance := range c.instances {
84-
resp, err := instance.sign(cmd, seq, data, c.extraHeaders)
77+
resp, err := instance.sign(cmd, seq, data, uin, guid, qua, c.extraHeaders)
8578
if err == nil {
8679
return resp, nil
8780
}
@@ -110,12 +103,16 @@ func (c *signer) AddRequestHeader(header map[string]string) {
110103
}
111104

112105
// AddSignServer 添加签名服务器
113-
func (c *signer) AddSignServer(signServers ...string) {
106+
func (c *signer) AddSignServer(signServers ...config.SignServer) {
114107
c.lock.Lock()
115108
defer c.lock.Unlock()
116-
c.instances = append(c.instances, io.Map(signServers, func(s string) *remote {
117-
return &remote{server: s}
118-
})...)
109+
for _, s := range signServers {
110+
u, err := url.Parse(s.URL)
111+
if err != nil || u.Hostname() == "" {
112+
continue
113+
}
114+
c.instances = append(c.instances, &remote{server: u.String(), token: s.Token})
115+
}
119116
}
120117

121118
// GetSignServer 获取签名服务器
@@ -136,37 +133,40 @@ func (c *signer) SetAppInfo(app *auth.AppInfo) {
136133
app.CurrentVersion, runtime.GOOS, runtime.GOARCH, base.Version))
137134
}
138135

139-
func (c *signer) check() {
140-
log.Infoln("开始签名服务器质量测试")
141-
availableQuantity := 0
142-
wg := sync.WaitGroup{}
143-
c.lock.RLock()
144-
for _, instance := range c.instances {
145-
wg.Add(1)
146-
go func(i *remote) {
147-
defer wg.Done()
148-
i.test()
149-
}(instance)
150-
}
151-
wg.Wait()
152-
for _, instance := range c.instances {
153-
if instance.latency.Load() < serverLatencyDown {
154-
availableQuantity++
155-
}
156-
}
157-
c.lock.RUnlock()
158-
c.sortByLatency()
159-
log.Infof("签名服务器质量测试完成,可用服务器数量: %d", availableQuantity)
160-
}
161-
162-
func (i *remote) sign(cmd string, seq uint32, buf []byte, header http.Header) (signResp *sign.Response, err error) {
163-
if !(sign.ContainSignPKG(cmd) || cmd == "wtlogin.trans_emp") {
136+
// func (c *signer) check() {
137+
// log.Infoln("开始签名服务器质量测试")
138+
// availableQuantity := 0
139+
// wg := sync.WaitGroup{}
140+
// c.lock.RLock()
141+
// for _, instance := range c.instances {
142+
// wg.Add(1)
143+
// go func(i *remote) {
144+
// defer wg.Done()
145+
// i.test()
146+
// }(instance)
147+
// }
148+
// wg.Wait()
149+
// for _, instance := range c.instances {
150+
// if instance.latency.Load() < serverLatencyDown {
151+
// availableQuantity++
152+
// }
153+
// }
154+
// c.lock.RUnlock()
155+
// c.sortByLatency()
156+
// log.Infof("签名服务器质量测试完成,可用服务器数量: %d", availableQuantity)
157+
//}
158+
159+
func (i *remote) sign(cmd string, seq uint32, buf []byte, uin uint32, guid, qua string, header http.Header) (signResp *sign.Response, err error) {
160+
if !sign.ContainSignPKG(cmd) {
164161
return nil, nil
165162
}
166163
signReq := sign.Request{
167-
Cmd: cmd,
168-
Seq: int(seq),
169-
Src: buf,
164+
Command: cmd,
165+
Seq: int(seq),
166+
Body: buf,
167+
Uin: uin,
168+
GUID: guid,
169+
Qua: qua,
170170
}
171171
u, err := url.Parse(i.server)
172172
if err != nil {
@@ -190,6 +190,9 @@ func (i *remote) sign(cmd string, seq uint32, buf []byte, header http.Header) (s
190190
req.Header.Add(k, v)
191191
}
192192
}
193+
if i.token != "" {
194+
req.Header.Set("Authorization", "Bearer "+i.token)
195+
}
193196
req.Header.Set("Content-Type", "application/json")
194197

195198
resp, err := http.DefaultClient.Do(req)
@@ -201,26 +204,29 @@ func (i *remote) sign(cmd string, seq uint32, buf []byte, header http.Header) (s
201204
if err != nil {
202205
return nil, err
203206
}
207+
if signResp.Code != 0 {
208+
return nil, errors.New(signResp.Message)
209+
}
204210

205211
return signResp, nil
206212
}
207213

208-
func (i *remote) test() {
209-
startTime := time.Now().UnixMilli()
210-
resp, err := i.sign("wtlogin.login", 1, []byte{11, 45, 14}, nil)
211-
if err != nil || len(resp.Value.Sign) == 0 {
212-
log.Warnf("测试签名服务器:%s时出现错误: %v", i.server, err)
213-
i.latency.Store(serverLatencyDown)
214-
return
215-
}
216-
// 有长连接的情况,取两次平均值
217-
resp, err = i.sign("wtlogin.login", 1, []byte{11, 45, 14}, nil)
218-
if err != nil || len(resp.Value.Sign) == 0 {
219-
log.Warnf("测试签名服务器:%s时出现错误: %v", i.server, err)
220-
i.latency.Store(serverLatencyDown)
221-
return
222-
}
223-
latency := (time.Now().UnixMilli() - startTime) / 2
224-
i.latency.Store(uint32(latency))
225-
log.Debugf("签名服务器:%s,延迟:%dms", i.server, latency)
226-
}
214+
// func (i *remote) test() {
215+
// startTime := time.Now().UnixMilli()
216+
// resp, err := i.sign("wtlogin.login", 1, []byte{11, 45, 14}, 0, "", "", nil)
217+
// if err != nil || len(resp.Value.SecSign) == 0 {
218+
// log.Warnf("测试签名服务器:%s时出现错误: %v", i.server, err)
219+
// i.latency.Store(serverLatencyDown)
220+
// return
221+
// }
222+
// // 有长连接的情况,取两次平均值
223+
// resp, err = i.sign("wtlogin.login", 1, []byte{11, 45, 14}, 0, "", "", nil)
224+
// if err != nil || len(resp.Value.SecSign) == 0 {
225+
// log.Warnf("测试签名服务器:%s时出现错误: %v", i.server, err)
226+
// i.latency.Store(serverLatencyDown)
227+
// return
228+
// }
229+
// latency := (time.Now().UnixMilli() - startTime) / 2
230+
// i.latency.Store(uint32(latency))
231+
// log.Debugf("签名服务器:%s,延迟:%dms", i.server, latency)
232+
//}

0 commit comments

Comments
 (0)