Files
hk4e/dispatch/controller/gate_controller.go
flswld 0395dc0bc2 1.MongoDB、Redis兼容集群模式
2.离线数据接口化访问
2023-02-26 23:03:13 +08:00

66 lines
1.5 KiB
Go

package controller
import (
"net/http"
"strconv"
"time"
"hk4e/pkg/logger"
"github.com/gin-gonic/gin"
)
type TokenVerifyReq struct {
AccountId string `json:"accountId"`
AccountToken string `json:"accountToken"`
}
type TokenVerifyRsp struct {
Valid bool `json:"valid"`
Forbid bool `json:"forbid"`
ForbidEndTime uint32 `json:"forbidEndTime"`
PlayerID uint32 `json:"playerID"`
}
func (c *Controller) gateTokenVerify(context *gin.Context) {
verifyFail := func(playerID uint32) {
context.JSON(http.StatusOK, &TokenVerifyRsp{
Valid: false,
Forbid: false,
ForbidEndTime: 0,
PlayerID: playerID,
})
}
tokenVerifyReq := new(TokenVerifyReq)
err := context.ShouldBindJSON(tokenVerifyReq)
if err != nil {
verifyFail(0)
return
}
logger.Info("gate token verify, req: %v", tokenVerifyReq)
accountId, err := strconv.ParseUint(tokenVerifyReq.AccountId, 10, 64)
if err != nil {
verifyFail(0)
return
}
account, err := c.dao.QueryAccountByField("AccountID", accountId)
if err != nil || account == nil {
verifyFail(0)
return
}
if tokenVerifyReq.AccountToken != account.ComboToken {
verifyFail(account.PlayerID)
return
}
if time.Now().UnixMilli()-int64(account.ComboTokenCreateTime) > time.Minute.Milliseconds()*5 {
verifyFail(account.PlayerID)
return
}
context.JSON(http.StatusOK, &TokenVerifyRsp{
Valid: true,
Forbid: account.Forbid,
ForbidEndTime: account.ForbidEndTime,
PlayerID: account.PlayerID,
})
}