diff --git a/cmd/gm/application.toml b/cmd/gm/application.toml index 901bc94a..69cbef72 100644 --- a/cmd/gm/application.toml +++ b/cmd/gm/application.toml @@ -1,5 +1,8 @@ http_port = 9001 +[hk4e] +gm_auth_key = "flswld" # gm认证密钥 + [logger] level = "DEBUG" mode = "CONSOLE" diff --git a/common/config/config.go b/common/config/config.go index 7efc4775..ea7bb891 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -54,6 +54,7 @@ type Hk4e struct { DispatchUrl string `toml:"dispatch_url"` // 二级dispatch地址 将域名改为dispatch的外网地址 ForwardRegionUrl string `toml:"forward_region_url"` // 转发的一级dispatch地址 ForwardDispatchUrl string `toml:"forward_dispatch_url"` // 转发的二级dispatch地址 + GmAuthKey string `toml:"gm_auth_key"` // gm认证密钥 } // Hk4eRobot 原神机器人 diff --git a/dispatch/controller/controller.go b/dispatch/controller/controller.go index acdbd4bd..aff166e5 100644 --- a/dispatch/controller/controller.go +++ b/dispatch/controller/controller.go @@ -2,7 +2,6 @@ package controller import ( "context" - "net" "net/http" "strconv" "sync" @@ -69,30 +68,6 @@ func NewController(db *dao.Dao, discovery *rpc.DiscoveryClient, messageQueue *mq return r } -func (c *Controller) authorize() gin.HandlerFunc { - return func(context *gin.Context) { - addr := context.ClientIP() - if addr == "" { - addr = context.Request.RemoteAddr - } - ip := net.ParseIP(addr) - ipv4 := ip.To4() - if ip.IsLoopback() || - ipv4[0] == 10 || - ipv4[0] == 169 && ipv4[1] == 254 || - ipv4[0] == 172 && ipv4[1] >= 16 && ipv4[1] <= 31 || - ipv4[0] == 192 && ipv4[1] == 168 { - context.Next() - return - } - context.Abort() - context.JSON(http.StatusOK, gin.H{ - "code": "10001", - "msg": "没有访问权限", - }) - } -} - func (c *Controller) registerRouter() { if config.GetConfig().Logger.Level == "DEBUG" { gin.SetMode(gin.DebugMode) @@ -186,7 +161,6 @@ func (c *Controller) registerRouter() { engine.StaticFS("/static", http.Dir("./static/geetest/static")) engine.StaticFS("/pictures", http.Dir("./static/geetest/pictures")) } - engine.Use(c.authorize()) engine.POST("/gate/token/verify", c.gateTokenVerify) port := config.GetConfig().HttpPort addr := ":" + strconv.Itoa(int(port)) diff --git a/gm/controller/controller.go b/gm/controller/controller.go index 39e53cf8..a88ef425 100644 --- a/gm/controller/controller.go +++ b/gm/controller/controller.go @@ -71,7 +71,7 @@ func (c *Controller) syncGlobalGsOnlineMap() { func (c *Controller) authorize() gin.HandlerFunc { return func(context *gin.Context) { - if context.GetHeader("Auth") == "flswld" { + if context.GetHeader("GmAuthKey") == config.GetConfig().Hk4e.GmAuthKey { // 验证通过 context.Next() return