feat(log): 添加QQWry IP数据库支持并实现IP地址解析功能
This commit is contained in:
1
common/utils/qqwry
Submodule
1
common/utils/qqwry
Submodule
Submodule common/utils/qqwry added at 1dd385f77d
17
common/utils/tcpping.go
Normal file
17
common/utils/tcpping.go
Normal 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
|
||||
}
|
||||
1
go.work
1
go.work
@@ -15,6 +15,7 @@ use (
|
||||
./common/utils/goja
|
||||
./common/utils/limit
|
||||
./common/utils/log
|
||||
./common/utils/qqwry
|
||||
./common/utils/sturc
|
||||
./common/utils/xml
|
||||
./logic
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BIN
public/login
BIN
public/login
Binary file not shown.
BIN
public/qqwry.ipdb
Normal file
BIN
public/qqwry.ipdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user