将游戏服务器uid与sdk分离
This commit is contained in:
1 parent
6d7e4867f5
commit
ddb55671b5
31 files changed
+457
-296
No files matched your search
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
dao *dao.Dao
|
||||
db *dao.Dao
|
||||
discovery *rpc.DiscoveryClient
|
||||
signRsaKey []byte
|
||||
encRsaKeyMap map[string][]byte
|
||||
@@ -28,9 +28,9 @@ type Controller struct {
|
||||
messageQueue *mq.MessageQueue
|
||||
}
|
||||
|
||||
func NewController(dao *dao.Dao, discovery *rpc.DiscoveryClient, messageQueue *mq.MessageQueue) (r *Controller) {
|
||||
func NewController(db *dao.Dao, discovery *rpc.DiscoveryClient, messageQueue *mq.MessageQueue) (r *Controller) {
|
||||
r = new(Controller)
|
||||
r.dao = dao
|
||||
r.db = db
|
||||
r.discovery = discovery
|
||||
r.signRsaKey, r.encRsaKeyMap, r.pwdRsaKey = region.LoadRegionRsaKey()
|
||||
rsp, err := r.discovery.GetRegionEc2B(context.TODO(), &api.NullMsg{})
|
||||
@@ -168,7 +168,6 @@ func (c *Controller) registerRouter() {
|
||||
}
|
||||
engine.Use(c.authorize())
|
||||
engine.POST("/gate/token/verify", c.gateTokenVerify)
|
||||
engine.POST("/gate/player/info", c.gatePlayerInfo)
|
||||
port := config.GetConfig().HttpPort
|
||||
addr := ":" + strconv.Itoa(int(port))
|
||||
err := engine.Run(addr)
|
||||
|
||||
@@ -77,7 +77,7 @@ func GetRegionList(ec2b *random.Ec2b) *proto.QueryRegionListHttpRsp {
|
||||
RegionConfig: "pm|fk|add",
|
||||
DownloadMode: 0,
|
||||
DebugMenu: true,
|
||||
DebugLogSwitch: []int32{0, 1, 2},
|
||||
DebugLogSwitch: []int32{0},
|
||||
DebugLog: true,
|
||||
})
|
||||
endec.Xor(clientCustomConfig, dispatchXorKey)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/dispatch/model"
|
||||
"hk4e/pkg/logger"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -65,7 +64,7 @@ func (c *Controller) gateTokenVerify(ctx *gin.Context) {
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("AccountID", uint64(accountId))
|
||||
account, err := c.db.QueryAccountByField("account_id", uint64(accountId))
|
||||
if err != nil || account == nil {
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
@@ -100,86 +99,3 @@ func (c *Controller) gateTokenVerify(ctx *gin.Context) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type PlayerInfoReq struct {
|
||||
AccountId string `json:"accountId"`
|
||||
}
|
||||
|
||||
type PlayerInfoRsp struct {
|
||||
RetCode int32 `json:"retcode"`
|
||||
Message string `json:"message"`
|
||||
Data struct{} `json:"data"`
|
||||
Forbid bool `json:"forbid"`
|
||||
ForbidEndTime uint32 `json:"forbidEndTime"`
|
||||
PlayerID uint32 `json:"playerID"`
|
||||
}
|
||||
|
||||
func (c *Controller) gatePlayerInfo(ctx *gin.Context) {
|
||||
playerInfoReq := new(PlayerInfoReq)
|
||||
err := ctx.ShouldBindJSON(playerInfoReq)
|
||||
if err != nil {
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
logger.Info("gate player info, req: %v", playerInfoReq)
|
||||
accountId, err := strconv.Atoi(playerInfoReq.AccountId)
|
||||
if err != nil {
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("AccountID", uint64(accountId))
|
||||
if err != nil {
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
if account == nil {
|
||||
// 外部sdk登录
|
||||
redisAccountId, err := c.dao.GetAccountId()
|
||||
if err != nil {
|
||||
logger.Error("get account id error: %v", err)
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
if uint32(accountId) > redisAccountId {
|
||||
// 临时修正自增id
|
||||
err := c.dao.SetAccountId(uint32(accountId))
|
||||
if err != nil {
|
||||
logger.Error("set account id error: %v", err)
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
}
|
||||
// 补账号记录
|
||||
playerID, err := c.dao.GetNextYuanShenUid()
|
||||
if err != nil {
|
||||
logger.Error("get next player id error: %v", err)
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
regAccount := &model.Account{
|
||||
AccountID: uint32(accountId),
|
||||
Username: "",
|
||||
Password: "",
|
||||
PlayerID: playerID,
|
||||
Token: "",
|
||||
ComboToken: "",
|
||||
Forbid: false,
|
||||
ForbidEndTime: 0,
|
||||
}
|
||||
_, err = c.dao.InsertAccount(regAccount)
|
||||
if err != nil {
|
||||
logger.Error("insert account error: %v", err)
|
||||
c.gateReqErrorRsp(ctx)
|
||||
return
|
||||
}
|
||||
account = regAccount
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &PlayerInfoRsp{
|
||||
RetCode: 0,
|
||||
Message: "OK",
|
||||
Data: struct{}{},
|
||||
Forbid: account.Forbid,
|
||||
ForbidEndTime: account.ForbidEndTime,
|
||||
PlayerID: account.PlayerID,
|
||||
})
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (c *Controller) log8888(ctx *gin.Context) {
|
||||
logger.Error("parse client log error: %v", err)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.InsertClientLog(clientLog)
|
||||
_, err = c.db.InsertClientLog(clientLog)
|
||||
if err != nil {
|
||||
logger.Error("insert client log error: %v", err)
|
||||
return
|
||||
|
||||
@@ -92,14 +92,14 @@ func (c *Controller) apiLogin(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("Username", username)
|
||||
account, err := c.db.QueryAccountByField("username", username)
|
||||
if err != nil {
|
||||
logger.Error("query account from db error: %v", err)
|
||||
return
|
||||
}
|
||||
if account == nil {
|
||||
// 自动注册
|
||||
accountId, err := c.dao.GetNextAccountId()
|
||||
accountId, err := c.db.GetNextAccountId()
|
||||
if err != nil {
|
||||
logger.Error("get next account id error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
@@ -107,29 +107,18 @@ func (c *Controller) apiLogin(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
playerID, err := c.dao.GetNextYuanShenUid()
|
||||
if err != nil {
|
||||
logger.Error("get next player id error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-2"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
regAccount := &model.Account{
|
||||
AccountID: accountId,
|
||||
Username: username,
|
||||
Password: endec.Md5Str(password),
|
||||
PlayerID: playerID,
|
||||
Token: "",
|
||||
ComboToken: "",
|
||||
Forbid: false,
|
||||
ForbidEndTime: 0,
|
||||
AccountId: accountId,
|
||||
Username: username,
|
||||
Password: endec.Md5Str(password),
|
||||
Token: "",
|
||||
ComboToken: "",
|
||||
}
|
||||
_, err = c.dao.InsertAccount(regAccount)
|
||||
_, err = c.db.InsertAccount(regAccount)
|
||||
if err != nil {
|
||||
logger.Error("insert account error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-3"
|
||||
responseData.Message = "服务器内部错误:-2"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
@@ -143,24 +132,24 @@ func (c *Controller) apiLogin(ctx *gin.Context) {
|
||||
}
|
||||
// 生成新的token
|
||||
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "Token", account.Token)
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "token", account.Token)
|
||||
if err != nil {
|
||||
logger.Error("update account token error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-3"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "token_create_time", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
logger.Error("update account token time error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-4"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "TokenCreateTime", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
logger.Error("update account token time error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-5"
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.Account.Uid = strconv.FormatInt(int64(account.AccountID), 10)
|
||||
responseData.Data.Account.Uid = strconv.FormatInt(int64(account.AccountId), 10)
|
||||
responseData.Data.Account.Token = account.Token
|
||||
responseData.Data.Account.Email = account.Username
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
@@ -178,7 +167,7 @@ func (c *Controller) apiVerify(ctx *gin.Context) {
|
||||
logger.Error("parse uid error: %v", err)
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("AccountID", uid)
|
||||
account, err := c.db.QueryAccountByField("account_id", uid)
|
||||
if err != nil {
|
||||
logger.Error("query account from db error: %v", err)
|
||||
return
|
||||
@@ -227,7 +216,7 @@ func (c *Controller) v2Login(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
responseData := api.NewComboTokenRsp()
|
||||
account, err := c.dao.QueryAccountByField("AccountID", uid)
|
||||
account, err := c.db.QueryAccountByField("account_id", uid)
|
||||
if account == nil || account.Token != loginData.Token {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "token错误"
|
||||
@@ -236,7 +225,7 @@ func (c *Controller) v2Login(ctx *gin.Context) {
|
||||
}
|
||||
// 生成新的comboToken
|
||||
account.ComboToken = random.GetRandomByteHexStr(20)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboToken", account.ComboToken)
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "combo_token", account.ComboToken)
|
||||
if err != nil {
|
||||
logger.Error("update combo token error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
@@ -244,7 +233,7 @@ func (c *Controller) v2Login(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboTokenCreateTime", time.Now().UnixMilli())
|
||||
_, err = c.db.UpdateAccountFieldByFieldName("account_id", account.AccountId, "combo_token_create_time", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
logger.Error("update combo token time error: %v", err)
|
||||
responseData.Retcode = -201
|
||||
|
||||
Reference in new issue
Block a user