mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
修改聊天和登录信息的数据库结构
This commit is contained in:
@@ -47,9 +47,7 @@ func NewController(dao *dao.Dao, discovery *rpc.DiscoveryClient) (r *Controller)
|
||||
|
||||
func (c *Controller) authorize() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
// TODO auth token或其他验证方式
|
||||
ok := true
|
||||
if ok {
|
||||
if context.Query("key") == "flswld" {
|
||||
context.Next()
|
||||
return
|
||||
}
|
||||
@@ -80,10 +78,10 @@ func (c *Controller) registerRouter() {
|
||||
{
|
||||
// 调度
|
||||
// dispatchosglobal.yuanshen.com
|
||||
engine.GET("/query_security_file", c.query_security_file)
|
||||
engine.GET("/query_region_list", c.query_region_list)
|
||||
engine.GET("/query_security_file", c.querySecurityFile)
|
||||
engine.GET("/query_region_list", c.queryRegionList)
|
||||
// osusadispatch.yuanshen.com
|
||||
engine.GET("/query_cur_region", c.query_cur_region)
|
||||
engine.GET("/query_cur_region", c.queryCurRegion)
|
||||
}
|
||||
{
|
||||
// 登录
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (c *Controller) query_security_file(context *gin.Context) {
|
||||
func (c *Controller) querySecurityFile(context *gin.Context) {
|
||||
// 很早以前2.6.0版本的时候抓包为了完美还原写的 不清楚有没有副作用暂时不要了
|
||||
return
|
||||
file, err := os.ReadFile("static/security_file")
|
||||
@@ -30,7 +30,7 @@ func (c *Controller) query_security_file(context *gin.Context) {
|
||||
_, _ = context.Writer.WriteString(string(file))
|
||||
}
|
||||
|
||||
func (c *Controller) query_region_list(context *gin.Context) {
|
||||
func (c *Controller) queryRegionList(context *gin.Context) {
|
||||
context.Header("Content-type", "text/html; charset=UTF-8")
|
||||
regionListBase64 := region.GetRegionListBase64(c.ec2b)
|
||||
_, _ = context.Writer.WriteString(regionListBase64)
|
||||
@@ -66,7 +66,7 @@ func (c *Controller) getClientVersionByName(versionName string) (int, string) {
|
||||
return version, strconv.Itoa(version)
|
||||
}
|
||||
|
||||
func (c *Controller) query_cur_region(context *gin.Context) {
|
||||
func (c *Controller) queryCurRegion(context *gin.Context) {
|
||||
rspError := func() {
|
||||
rspContentError := "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="
|
||||
rspSignError := "TW9yZSBsb3ZlIGZvciBVQSBQYXRjaCBwbGF5ZXJz"
|
||||
|
||||
@@ -42,29 +42,29 @@ func (c *Controller) gateTokenVerify(context *gin.Context) {
|
||||
verifyFail(0)
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("accountID", accountId)
|
||||
account, err := c.dao.QueryAccountByField("AccountID", accountId)
|
||||
if err != nil || account == nil {
|
||||
verifyFail(0)
|
||||
return
|
||||
}
|
||||
if tokenVerifyReq.AccountToken != account.ComboToken {
|
||||
verifyFail(uint32(account.PlayerID))
|
||||
verifyFail(account.PlayerID)
|
||||
return
|
||||
}
|
||||
if account.ComboTokenUsed {
|
||||
verifyFail(uint32(account.PlayerID))
|
||||
verifyFail(account.PlayerID)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "comboTokenUsed", true)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboTokenUsed", true)
|
||||
if err != nil {
|
||||
verifyFail(uint32(account.PlayerID))
|
||||
verifyFail(account.PlayerID)
|
||||
return
|
||||
}
|
||||
context.JSON(http.StatusOK, &TokenVerifyRsp{
|
||||
Valid: true,
|
||||
Forbid: account.Forbid,
|
||||
ForbidEndTime: uint32(account.ForbidEndTime),
|
||||
PlayerID: uint32(account.PlayerID),
|
||||
ForbidEndTime: account.ForbidEndTime,
|
||||
PlayerID: account.PlayerID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func (c *Controller) gateTokenReset(context *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("playerID", req.PlayerId, "comboTokenUsed", false)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("PlayerID", req.PlayerId, "ComboTokenUsed", false)
|
||||
if err != nil {
|
||||
context.JSON(http.StatusOK, &TokenResetRsp{
|
||||
Result: false,
|
||||
|
||||
@@ -92,8 +92,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
// TODO SDK账号登陆
|
||||
account, err := c.dao.QueryAccountByField("username", username)
|
||||
account, err := c.dao.QueryAccountByField("Username", username)
|
||||
if err != nil {
|
||||
logger.Error("query account from db error: %v", err)
|
||||
return
|
||||
@@ -141,14 +140,14 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
}
|
||||
// 生成新的token
|
||||
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "token", account.Token)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "Token", account.Token)
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-4"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "tokenCreateTime", time.Now().UnixMilli())
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "TokenCreateTime", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-5"
|
||||
@@ -174,7 +173,7 @@ func (c *Controller) apiVerify(context *gin.Context) {
|
||||
logger.Error("parse uid error: %v", err)
|
||||
return
|
||||
}
|
||||
account, err := c.dao.QueryAccountByField("accountID", uid)
|
||||
account, err := c.dao.QueryAccountByField("AccountID", uid)
|
||||
if err != nil {
|
||||
logger.Error("query account from db error: %v", err)
|
||||
return
|
||||
@@ -223,7 +222,7 @@ func (c *Controller) v2Login(context *gin.Context) {
|
||||
return
|
||||
}
|
||||
responseData := api.NewComboTokenRsp()
|
||||
account, err := c.dao.QueryAccountByField("accountID", uid)
|
||||
account, err := c.dao.QueryAccountByField("AccountID", uid)
|
||||
if account == nil || account.Token != loginData.Token {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "token错误"
|
||||
@@ -232,14 +231,14 @@ func (c *Controller) v2Login(context *gin.Context) {
|
||||
}
|
||||
// 生成新的comboToken
|
||||
account.ComboToken = random.GetRandomByteHexStr(20)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "comboToken", account.ComboToken)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboToken", account.ComboToken)
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-1"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "comboTokenUsed", false)
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("AccountID", account.AccountID, "ComboTokenUsed", false)
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-2"
|
||||
|
||||
@@ -8,26 +8,26 @@ const RedisPlayerKeyPrefix = "HK4E"
|
||||
|
||||
const (
|
||||
AccountIdRedisKey = "AccountId"
|
||||
AccountIdBegin uint64 = 10000
|
||||
AccountIdBegin uint32 = 10000
|
||||
YuanShenUidRedisKey = "YuanShenUid"
|
||||
YuanShenUidBegin uint64 = 100000000
|
||||
YuanShenUidBegin uint32 = 100000000
|
||||
)
|
||||
|
||||
func (d *Dao) GetNextAccountId() (uint64, error) {
|
||||
func (d *Dao) GetNextAccountId() (uint32, error) {
|
||||
return d.redisInc(RedisPlayerKeyPrefix + ":" + AccountIdRedisKey)
|
||||
}
|
||||
|
||||
func (d *Dao) GetNextYuanShenUid() (uint64, error) {
|
||||
func (d *Dao) GetNextYuanShenUid() (uint32, error) {
|
||||
return d.redisInc(RedisPlayerKeyPrefix + ":" + YuanShenUidRedisKey)
|
||||
}
|
||||
|
||||
func (d *Dao) redisInc(keyName string) (uint64, error) {
|
||||
func (d *Dao) redisInc(keyName string) (uint32, error) {
|
||||
exist, err := d.redis.Exists(context.TODO(), keyName).Result()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if exist == 0 {
|
||||
var value uint64 = 0
|
||||
var value uint32 = 0
|
||||
if keyName == RedisPlayerKeyPrefix+":"+AccountIdRedisKey {
|
||||
value = AccountIdBegin
|
||||
} else if keyName == RedisPlayerKeyPrefix+":"+YuanShenUidRedisKey {
|
||||
@@ -42,5 +42,5 @@ func (d *Dao) redisInc(keyName string) (uint64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(id), nil
|
||||
return uint32(id), nil
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
type Account struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
AccountID uint64 `bson:"accountID"`
|
||||
Username string `bson:"username"`
|
||||
Password string `bson:"password"`
|
||||
PlayerID uint64 `bson:"playerID"`
|
||||
Token string `bson:"token"`
|
||||
TokenCreateTime uint64 `bson:"tokenCreateTime"` // 毫秒时间戳
|
||||
ComboToken string `bson:"comboToken"`
|
||||
ComboTokenUsed bool `bson:"comboTokenUsed"`
|
||||
Forbid bool `bson:"forbid"`
|
||||
ForbidEndTime uint64 `bson:"forbidEndTime"` // 秒时间戳
|
||||
AccountID uint32 `bson:"AccountID"`
|
||||
PlayerID uint32 `bson:"PlayerID"`
|
||||
Username string `bson:"Username"`
|
||||
Password string `bson:"Password"`
|
||||
Token string `bson:"Token"`
|
||||
TokenCreateTime uint64 `bson:"TokenCreateTime"` // 毫秒时间戳
|
||||
ComboToken string `bson:"ComboToken"`
|
||||
ComboTokenUsed bool `bson:"ComboTokenUsed"`
|
||||
Forbid bool `bson:"Forbid"`
|
||||
ForbidEndTime uint32 `bson:"ForbidEndTime"` // 秒时间戳
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ import (
|
||||
|
||||
type ClientLog struct {
|
||||
ID primitive.ObjectID `json:"-" bson:"_id,omitempty"`
|
||||
Auid string `json:"auid" bson:"auid"`
|
||||
ClientIp string `json:"clientIp" bson:"clientIp"`
|
||||
CpuInfo string `json:"cpuInfo" bson:"cpuInfo"`
|
||||
DeviceModel string `json:"deviceModel" bson:"deviceModel"`
|
||||
DeviceName string `json:"deviceName" bson:"deviceName"`
|
||||
GpuInfo string `json:"gpuInfo" bson:"gpuInfo"`
|
||||
Guid string `json:"guid" bson:"guid"`
|
||||
LogStr string `json:"logStr" bson:"logStr"`
|
||||
LogType string `json:"logType" bson:"logType"`
|
||||
OperatingSystem string `json:"operatingSystem" bson:"operatingSystem"`
|
||||
StackTrace string `json:"stackTrace" bson:"stackTrace"`
|
||||
Time string `json:"time" bson:"time"`
|
||||
Uid uint64 `json:"uid" bson:"uid"`
|
||||
UserName string `json:"userName" bson:"userName"`
|
||||
Version string `json:"version" bson:"version"`
|
||||
Auid string `json:"auid" bson:"Auid"`
|
||||
ClientIp string `json:"clientIp" bson:"ClientIp"`
|
||||
CpuInfo string `json:"cpuInfo" bson:"CpuInfo"`
|
||||
DeviceModel string `json:"deviceModel" bson:"DeviceModel"`
|
||||
DeviceName string `json:"deviceName" bson:"DeviceName"`
|
||||
GpuInfo string `json:"gpuInfo" bson:"GpuInfo"`
|
||||
Guid string `json:"guid" bson:"Guid"`
|
||||
LogStr string `json:"logStr" bson:"LogStr"`
|
||||
LogType string `json:"logType" bson:"LogType"`
|
||||
OperatingSystem string `json:"operatingSystem" bson:"OperatingSystem"`
|
||||
StackTrace string `json:"stackTrace" bson:"StackTrace"`
|
||||
Time string `json:"time" bson:"Time"`
|
||||
Uid uint64 `json:"uid" bson:"Uid"`
|
||||
UserName string `json:"userName" bson:"UserName"`
|
||||
Version string `json:"version" bson:"Version"`
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type Service struct {
|
||||
// UserPasswordChange 用户密码改变
|
||||
func (s *Service) UserPasswordChange(uid uint32) bool {
|
||||
// http登录态失效
|
||||
_, err := s.dao.UpdateAccountFieldByFieldName("playerID", uid, "tokenCreateTime", 0)
|
||||
_, err := s.dao.UpdateAccountFieldByFieldName("PlayerID", uid, "TokenCreateTime", 0)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -22,11 +22,11 @@ func (s *Service) UserPasswordChange(uid uint32) bool {
|
||||
// ForbidUser 封号
|
||||
func (s *Service) ForbidUser(uid uint32, forbidEndTime uint64) bool {
|
||||
// 写入账号封禁信息
|
||||
_, err := s.dao.UpdateAccountFieldByFieldName("playerID", uid, "forbid", true)
|
||||
_, err := s.dao.UpdateAccountFieldByFieldName("PlayerID", uid, "Forbid", true)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
_, err = s.dao.UpdateAccountFieldByFieldName("playerID", uid, "forbidEndTime", forbidEndTime)
|
||||
_, err = s.dao.UpdateAccountFieldByFieldName("PlayerID", uid, "ForbidEndTime", forbidEndTime)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func (s *Service) ForbidUser(uid uint32, forbidEndTime uint64) bool {
|
||||
// UnForbidUser 解封
|
||||
func (s *Service) UnForbidUser(uid uint32) bool {
|
||||
// 解除账号封禁
|
||||
_, err := s.dao.UpdateAccountFieldByFieldName("playerID", uid, "forbid", false)
|
||||
_, err := s.dao.UpdateAccountFieldByFieldName("PlayerID", uid, "Forbid", false)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user