Compare commits

..

12 Commits

9 changed files with 107 additions and 20 deletions

View File

@@ -42,6 +42,9 @@ var (
getFileName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name") getFileName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name")
Filename := getFileName.String() Filename := getFileName.String()
getPath, err := g.Cfg("hack").Get(ctx, "gfcli.build.path")
Path := getPath.String()
//获取版本号 //获取版本号
getVersion, err := g.Cfg("hack").Get(ctx, "gfcli.build.version") getVersion, err := g.Cfg("hack").Get(ctx, "gfcli.build.version")
Version := getVersion.String() Version := getVersion.String()
@@ -89,7 +92,7 @@ var (
if v.Arch != "" && v.System != "" { if v.Arch != "" && v.System != "" {
systemName = v.System + "_" + v.Arch systemName = v.System + "_" + v.Arch
} }
var filename = path.Join(Version, systemName, Filename) var filename = path.Join(Path, Version, systemName, Filename)
g.Log().Debugf(ctx, "当前上传文件:"+filename) g.Log().Debugf(ctx, "当前上传文件:"+filename)
url[v.S3], err = UploadS3(v.S3, filename) url[v.S3], err = UploadS3(v.S3, filename)
@@ -109,9 +112,24 @@ var (
FileUrl: url[v.S3], FileUrl: url[v.S3],
}) })
if err != nil { if err != nil {
Proxy := g.Cfg().MustGet(ctx, "update_proxy", "http://192.168.50.170:10808").String() // 读取HTTP代理环境变量小写/大写通常都兼容,部分系统可能用大写)
g.Log().Debugf(ctx, "切换代理进行上传:err=%v", err) httpProxy := os.Getenv("http_proxy")
get, err = client.Proxy(Proxy).Post(ctx, address+"/callback/update", &UpdateReq{ if httpProxy == "" {
httpProxy = os.Getenv("HTTP_PROXY")
}
if httpProxy == "" {
// 读取HTTPS代理环境变量
httpProxy = os.Getenv("https_proxy")
if httpProxy == "" {
httpProxy = os.Getenv("HTTPS_PROXY")
}
}
// 如果没有读取到本地的代理,使用配置上传
if httpProxy == "" {
httpProxy = g.Cfg().MustGet(ctx, "update_proxy", "http://192.168.50.173:10808").String()
}
g.Log().Debugf(ctx, "切换代理进行上传:ip=%v,err=%v", httpProxy, err)
get, err = client.Proxy(httpProxy).Post(ctx, address+"/callback/update", &UpdateReq{
FileUrl: url[v.S3], FileUrl: url[v.S3],
}) })
} }

6
go.mod
View File

@@ -12,8 +12,8 @@ require (
github.com/go-pay/gopay v1.5.114 github.com/go-pay/gopay v1.5.114
github.com/go-pay/util v0.0.4 github.com/go-pay/util v0.0.4
github.com/goccy/go-json v0.10.5 github.com/goccy/go-json v0.10.5
github.com/gogf/gf/contrib/config/apollo/v2 v2.9.3 github.com/gogf/gf/contrib/config/apollo/v2 v2.9.4
github.com/gogf/gf/v2 v2.9.3 github.com/gogf/gf/v2 v2.9.4
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20250916043522-9a14e3273609 github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20250916043522-9a14e3273609
github.com/minio/minio-go/v7 v7.0.95 github.com/minio/minio-go/v7 v7.0.95
@@ -72,7 +72,7 @@ require (
github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect
github.com/olekukonko/errors v1.1.0 // indirect github.com/olekukonko/errors v1.1.0 // indirect
github.com/olekukonko/ll v0.1.1 // indirect github.com/olekukonko/ll v0.1.1 // indirect
github.com/olekukonko/tablewriter v1.0.9 // indirect github.com/olekukonko/tablewriter v1.1.0 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/philhofer/fwd v1.2.0 // indirect github.com/philhofer/fwd v1.2.0 // indirect

12
go.sum
View File

@@ -151,10 +151,10 @@ github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlnd
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogf/gf/contrib/config/apollo/v2 v2.9.3 h1:/IcE+DmlQDWeDjnkKWr1Rql7VCLUxEqz7gXoQKZHd8o= github.com/gogf/gf/contrib/config/apollo/v2 v2.9.4 h1:l2vkPpqteotzpq0h5Qg6S/GK84WpPUZlRwPVfZSDbYs=
github.com/gogf/gf/contrib/config/apollo/v2 v2.9.3/go.mod h1:mek4CnNsvdum4jYhf0PzaIYzoSBuSvVXyuCZG4I9qvw= github.com/gogf/gf/contrib/config/apollo/v2 v2.9.4/go.mod h1:mTfSf2Zm8+C49+rM7pK6AC8cwDSDxxwO8sLMNOl0yCI=
github.com/gogf/gf/v2 v2.9.3 h1:qjN4s55FfUzxZ1AE8vUHNDX3V0eIOUGXhF2DjRTVZQ4= github.com/gogf/gf/v2 v2.9.4 h1:6vleEWypot9WBPncP2GjbpgAUeG6Mzb1YESb9nPMkjY=
github.com/gogf/gf/v2 v2.9.3/go.mod h1:w6rcfD13SmO7FKI80k9LSLiSMGqpMYp50Nfkrrc2sEE= github.com/gogf/gf/v2 v2.9.4/go.mod h1:Ukl+5HUH9S7puBmNLR4L1zUqeRwi0nrW4OigOknEztU=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
@@ -321,8 +321,8 @@ github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y= github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
github.com/olekukonko/ll v0.1.1 h1:9Dfeed5/Mgaxb9lHRAftLK9pVfYETvHn+If6lywVhJc= github.com/olekukonko/ll v0.1.1 h1:9Dfeed5/Mgaxb9lHRAftLK9pVfYETvHn+If6lywVhJc=
github.com/olekukonko/ll v0.1.1/go.mod h1:2dJo+hYZcJMLMbKwHEWvxCUbAOLc/CXWS9noET22Mdo= github.com/olekukonko/ll v0.1.1/go.mod h1:2dJo+hYZcJMLMbKwHEWvxCUbAOLc/CXWS9noET22Mdo=
github.com/olekukonko/tablewriter v1.0.9 h1:XGwRsYLC2bY7bNd93Dk51bcPZksWZmLYuaTHR0FqfL8= github.com/olekukonko/tablewriter v1.1.0 h1:N0LHrshF4T39KvI96fn6GT8HEjXRXYNDrDjKFDB7RIY=
github.com/olekukonko/tablewriter v1.0.9/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo= github.com/olekukonko/tablewriter v1.1.0/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=

View File

@@ -15,6 +15,7 @@ import (
service2 "github.com/ayflying/utility_go/service" service2 "github.com/ayflying/utility_go/service"
"github.com/ayflying/utility_go/tools" "github.com/ayflying/utility_go/tools"
"github.com/gogf/gf/v2/container/gset" "github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gctx"
@@ -68,8 +69,8 @@ func (s *sGameAct) Info(uid int64, actId int) (data *g.Var, err error) {
Uid: uid, Uid: uid,
ActId: actId, ActId: actId,
}).Fields("action").OrderDesc("updated_at").Value() }).Fields("action").OrderDesc("updated_at").Value()
getDb.Scan(&data) // getDb.Scan(&data)
data = gvar.New(getDb)
if data == nil || data.IsEmpty() { if data == nil || data.IsEmpty() {
return return
} }

View File

@@ -2,6 +2,7 @@ package systemLog
import ( import (
"context" "context"
v1 "github.com/ayflying/utility_go/api/admin/v1" v1 "github.com/ayflying/utility_go/api/admin/v1"
"github.com/ayflying/utility_go/service" "github.com/ayflying/utility_go/service"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"

View File

@@ -72,6 +72,13 @@ var safePropertyRE = regexp.MustCompile(`[/"'\\\/]`)
// 设置某些字段只允许包含字母、数字和下划线 // 设置某些字段只允许包含字母、数字和下划线
var onlyWordRE = regexp.MustCompile(`\W`) var onlyWordRE = regexp.MustCompile(`\W`)
var nonWordCharRes = regexp.MustCompile(`[^\w]`)
func hasNonWordChar(s string) bool {
// 匹配非 \w 字符的正则表达式
return nonWordCharRes.MatchString(s)
}
var onlyWordPropertyNames = map[string]struct{}{ var onlyWordPropertyNames = map[string]struct{}{
"nickname": {}, "nickname": {},
} }
@@ -83,7 +90,12 @@ func SetOnlyWordProperty(propertyNames ...string) {
} }
func safeProperty(property map[string]any) { func safeProperty(property map[string]any) {
delkeys := []string{}
for k, v := range property { for k, v := range property {
if hasNonWordChar(k) {
delkeys = append(delkeys, k)
continue
}
if _, ok := onlyWordPropertyNames[k]; ok { if _, ok := onlyWordPropertyNames[k]; ok {
if _, ok := v.(string); ok { if _, ok := v.(string); ok {
property[k] = onlyWordRE.ReplaceAllString(gconv.String(v), "*") property[k] = onlyWordRE.ReplaceAllString(gconv.String(v), "*")
@@ -93,6 +105,9 @@ func safeProperty(property map[string]any) {
} }
} }
for _, delkey := range delkeys {
delete(property, delkey)
}
} }
func getLocationMapValue(key string) *time.Location { func getLocationMapValue(key string) *time.Location {
@@ -390,7 +405,7 @@ func (sdk *SDK) flush() {
// 发送消息 // 发送消息
func (sdk *SDK) send(logs []GameLog) { func (sdk *SDK) send(logs []GameLog) {
waitSecond := time.Duration(sdk.sdkConfig.FlushInterval/4) * time.Second waitSecond := time.Duration(sdk.sdkConfig.FlushInterval/4)*time.Second + time.Second*time.Duration(gconv.Int(len(logs)/5000))
timeoutCtx, cancel := context.WithTimeout(context.Background(), waitSecond) timeoutCtx, cancel := context.WithTimeout(context.Background(), waitSecond)
defer cancel() defer cancel()
data := make([][]any, 0, len(logs)) data := make([][]any, 0, len(logs))

View File

@@ -14,8 +14,9 @@ import (
func TestGamelog(t *testing.T) { func TestGamelog(t *testing.T) {
glsdk, err := gamelog.INIT(&gamelog.SDKConfig{ glsdk, err := gamelog.INIT(&gamelog.SDKConfig{
// 必填 // 必填
Pid: "test5", // 项目ID Pid: "test5", // 项目ID
BaseUrl: "http://47.76.178.47:10101", // 香港测试服上报地址 // BaseUrl: "http://47.76.178.47:10101", // 香港测试服上报地址
BaseUrl: "http://101.37.28.111:10101", // 香港测试服上报地址
// BaseUrl: "http://127.0.0.1:10101", // 本次测试上报地址 // BaseUrl: "http://127.0.0.1:10101", // 本次测试上报地址
ReportSk: "sngame2025", // xor混淆key ReportSk: "sngame2025", // xor混淆key
FlushInterval: 5, // 上报间隔 FlushInterval: 5, // 上报间隔
@@ -23,7 +24,7 @@ func TestGamelog(t *testing.T) {
// 可填 // 可填
RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据 RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据
ChanSize: 500, // 默认1000, 信道size ChanSize: 500, // 默认1000, 信道size
SendSaveType: 1, // 发送存储类型, 默认不设置为0代表文件存储, 1代表走kafka可实同步日志 SendSaveType: 2, // 发送存储类型, 默认不设置为0代表文件存储, 2代表走kafka可实同步日志
}) })
// 随机测试事件和属性 // 随机测试事件和属性

View File

@@ -2,9 +2,10 @@ package rank
import ( import (
"fmt" "fmt"
v1 "github.com/ayflying/utility_go/api/pkg/v1"
"time" "time"
v1 "github.com/ayflying/utility_go/api/pkg/v1"
"github.com/gogf/gf/v2/database/gredis" "github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gctx"
@@ -98,6 +99,51 @@ func (r *F64CountRank) IncrScore(id int64, score int64) (curScore float64, err e
return return
} }
// SetScore 对指定ID的分数进行赋值,这样同分情况下先完成的在前面。
// 该方法首先更新成员的更新时间戳,然后更新成员的分数。
//
// 参数:
//
// id - 要操作的成员ID。
// score - 要更新的分数。
//
// 返回值:
//
// err - 操作过程中可能发生的错误。
//
// @Description:
// @receiver r
// @param id
// @param score
// @return err
func (r *F64CountRank) SetScore(id int64, score int) (err error) {
// 记录当前时间戳,用于更新成员的最新活动时间。
now := time.Now().UnixMilli()
// 将成员的更新时间戳加入到Redis的有序集合中确保成员的排序依据是最新的活动时间。
_, err = g.Redis().ZAdd(ctx, r.updateTs, &gredis.ZAddOption{}, gredis.ZAddMember{
Score: float64(now),
Member: id,
})
if err != nil {
return
}
//如果分数小于0则删除
if score <= 0 {
err = r.DelScore(id)
if err != nil {
return
}
}
// 增加成员的分数,并返回增加后的当前分数。
_, err = g.Redis().ZAdd(ctx, r.name, &gredis.ZAddOption{}, gredis.ZAddMember{
Score: float64(score) + (3*1e13 - float64(now)) / 1e14,
Member: id,
})
return
}
// todo暂时未使用 // todo暂时未使用
func (r *F64CountRank) GetCount() { func (r *F64CountRank) GetCount() {
count, _ := g.Redis().ZCard(ctx, r.name) count, _ := g.Redis().ZCard(ctx, r.name)

View File

@@ -152,3 +152,8 @@ func (m *timeMod) CheckIsBeRwd(createdTime, lastRwdTime time.Time, _now ...time.
// 如果是,则说明还没领过,可以领取 // 如果是,则说明还没领过,可以领取
return lastRwdTime.Before(refreshToday) return lastRwdTime.Before(refreshToday)
} }
// 获取指定时间的本月最后一刻
func (m *timeMod) EndOfMonth(t time.Time) time.Time {
return time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location()).Add(-time.Second)
}