feat(log): 添加QQWry IP数据库支持并实现IP地址解析功能

This commit is contained in:
1
2025-11-03 16:19:24 +00:00
parent e86e138d94
commit abaa51af38
7 changed files with 43 additions and 3 deletions

1
common/utils/qqwry Submodule

Submodule common/utils/qqwry added at 1dd385f77d

17
common/utils/tcpping.go Normal file
View File

@@ -0,0 +1,17 @@
package utils
import (
"net"
"time"
)
func TcpPing(address string) (n int64, err error) {
s := time.Now()
tcpConn, err := net.Dial("tcp", address)
n = time.Now().Sub(s).Nanoseconds()
if err != nil {
return
}
tcpConn.Close()
return
}

View File

@@ -15,6 +15,7 @@ use (
./common/utils/goja
./common/utils/limit
./common/utils/log
./common/utils/qqwry
./common/utils/sturc
./common/utils/xml
./logic

View File

@@ -1,7 +1,6 @@
package node
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
)
@@ -24,6 +23,6 @@ func (e *EffectNode) OnOwnerSwitchIn(ctx input.Ctx) bool {
// 自身下场,清除掉技能效果
func (e *EffectNode) OnOwnerSwitchOut(ctx input.Ctx) bool {
e.Input.AttackValue = info.NewAttackValue(e.Input.UserID)
// e.Input.AttackValue = info.NewAttackValue(e.Input.UserID)
return true
}

View File

@@ -2,12 +2,14 @@ package service
import (
"blazing/cool"
"fmt"
"blazing/modules/base/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/xiaoqidun/qqwry"
)
type BaseSysLogService struct {
@@ -44,7 +46,19 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
baseSysLog.UserID = admin.UserId
baseSysLog.Action = r.Method + ":" + r.URL.Path
baseSysLog.IP = r.GetClientIp()
baseSysLog.IPAddr = r.GetClientIp()
// 从内存或缓存查询IP
location, err := qqwry.QueryIP("119.29.29.29")
if err != nil {
fmt.Printf("错误:%v\n", err)
return
}
baseSysLog.IPAddr = fmt.Sprintf("国家:%s省份%s城市%s区县%s运营商%s\n",
location.Country,
location.Province,
location.City,
location.District,
location.ISP,
)
baseSysLog.Params = r.GetBodyString()
m := cool.DBM(s.Model)
m.Insert(g.Map{
@@ -68,3 +82,11 @@ func (s *BaseSysLogService) Clear(isAll bool) (err error) {
}
return
}
func init() {
// 从文件加载IP数据库
if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
panic(err)
}
}

Binary file not shown.

BIN
public/qqwry.ipdb Normal file

Binary file not shown.