mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-08 23:42:27 +08:00
系统架构层面流量控制功能完善
This commit is contained in:
@@ -22,24 +22,42 @@ type TokenVerifyRsp struct {
|
||||
}
|
||||
|
||||
func (c *Controller) gateTokenVerify(context *gin.Context) {
|
||||
tokenVerifyReq := new(TokenVerifyReq)
|
||||
err := context.ShouldBindJSON(tokenVerifyReq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
logger.Debug("gate token verify, req: %v", tokenVerifyReq)
|
||||
accountId, err := strconv.ParseUint(tokenVerifyReq.AccountId, 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("accountID", accountId)
|
||||
if err != nil || account == nil {
|
||||
VerifyFail := func() {
|
||||
context.JSON(http.StatusOK, &TokenVerifyRsp{
|
||||
Valid: false,
|
||||
Forbid: false,
|
||||
ForbidEndTime: 0,
|
||||
PlayerID: 0,
|
||||
})
|
||||
}
|
||||
tokenVerifyReq := new(TokenVerifyReq)
|
||||
err := context.ShouldBindJSON(tokenVerifyReq)
|
||||
if err != nil {
|
||||
VerifyFail()
|
||||
return
|
||||
}
|
||||
logger.Info("gate token verify, req: %v", tokenVerifyReq)
|
||||
accountId, err := strconv.ParseUint(tokenVerifyReq.AccountId, 10, 64)
|
||||
if err != nil {
|
||||
VerifyFail()
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("accountID", accountId)
|
||||
if err != nil || account == nil {
|
||||
VerifyFail()
|
||||
return
|
||||
}
|
||||
if tokenVerifyReq.AccountToken != account.ComboToken {
|
||||
VerifyFail()
|
||||
return
|
||||
}
|
||||
if account.ComboTokenUsed {
|
||||
VerifyFail()
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "comboTokenUsed", true)
|
||||
if err != nil {
|
||||
VerifyFail()
|
||||
return
|
||||
}
|
||||
context.JSON(http.StatusOK, &TokenVerifyRsp{
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package controller
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"hk4e/dispatch/model"
|
||||
"hk4e/pkg/logger"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// POST https://log-upload-os.mihoyo.com/sdk/dataUpload HTTP/1.1
|
||||
func (c *Controller) sdkDataUpload(context *gin.Context) {
|
||||
@@ -22,6 +27,17 @@ func (c *Controller) perfDataUpload(context *gin.Context) {
|
||||
|
||||
// POST http://overseauspider.yuanshen.com:8888/log HTTP/1.1
|
||||
func (c *Controller) log8888(context *gin.Context) {
|
||||
clientLog := new(model.ClientLog)
|
||||
err := context.ShouldBindJSON(clientLog)
|
||||
if err != nil {
|
||||
logger.Error("parse client log error: %v", err)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.InsertClientLog(clientLog)
|
||||
if err != nil {
|
||||
logger.Error("insert client log error: %v", err)
|
||||
return
|
||||
}
|
||||
context.Header("Content-type", "application/json")
|
||||
_, _ = context.Writer.WriteString("{\"code\":0}")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hk4e/dispatch/api"
|
||||
"hk4e/dispatch/model"
|
||||
@@ -98,7 +99,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
return
|
||||
}
|
||||
if account == nil {
|
||||
// 注册一个原神account
|
||||
// 自动注册
|
||||
accountId, err := c.dao.GetNextAccountId()
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
@@ -138,7 +139,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
// 生产新的token
|
||||
// 生成新的token
|
||||
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "token", account.Token)
|
||||
if err != nil {
|
||||
@@ -147,6 +148,13 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "tokenCreateTime", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-5"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.Account.Uid = strconv.FormatInt(int64(account.AccountID), 10)
|
||||
responseData.Data.Account.Token = account.Token
|
||||
@@ -178,6 +186,12 @@ func (c *Controller) apiVerify(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
if uint64(time.Now().UnixMilli())-account.TokenCreateTime > uint64(time.Hour.Milliseconds()*24*7) {
|
||||
responseData.Retcode = -111
|
||||
responseData.Message = "登录已失效"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.Account.Uid = requestData.Uid
|
||||
responseData.Data.Account.Token = requestData.Token
|
||||
@@ -225,6 +239,13 @@ func (c *Controller) v2Login(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "comboTokenUsed", false)
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-2"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.OpenID = loginData.Uid
|
||||
responseData.Data.ComboID = "0"
|
||||
|
||||
Reference in New Issue
Block a user