解决冲突

This commit is contained in:
sk 2024-12-12 17:45:41 +08:00
commit ff04ab8e0f
2 changed files with 45 additions and 12 deletions

View File

@ -4,7 +4,9 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/golang-jwt/jwt/v4"
"io"
"mongo.games.com/game/webapi"
"strconv"
"time"
@ -72,7 +74,21 @@ func (this *CSLoginHandler) Process(s *netlib.Session, packetid int, data interf
s.Send(int(login_proto.GatePacketID_PACKET_SS_DICONNECT), ssDis)
}
if csl.GetUsername() == "" || csl.GetPassword() == "" {
if csl.GetLoginType() == common.LoginTypePlatformToken {
claims, err := webapi.ParseJwtWithClaims([]byte(common.Config.AppId), csl.Token)
if err != nil {
return nil
}
logger.Logger.Tracef("(this *CSLoginHandler) Process ParseJwtWithClaims: claims:%v", claims.(jwt.MapClaims))
username := (claims.(jwt.MapClaims))["Username"].(string)
{
csl.Username = username
}
}
if (csl.GetUsername() == "" || csl.GetPassword() == "") && csl.GetLoginType() != common.LoginTypePlatformToken {
sendSCLogin(login_proto.OpResultCode_OPRC_Error)
sendSCDisconnect(common.KickReason_Freeze)
return nil
@ -123,7 +139,7 @@ func (this *CSLoginHandler) Process(s *netlib.Session, packetid int, data interf
h := md5.New()
io.WriteString(h, raw)
hashsum := hex.EncodeToString(h.Sum(nil))
if hashsum != csl.GetSign() {
if hashsum != csl.GetSign() && csl.GetLoginType() != common.LoginTypePlatformToken {
logger.Logger.Tracef("ClientSessionAttribute_State hashsum not fit!!! get:%v expect:%v rawstr:%v", csl.GetSign(), hashsum, raw)
sendSCLogin(login_proto.OpResultCode_OPRC_Error)
sendSCDisconnect(common.KickReason_CheckCodeErr)
@ -250,7 +266,6 @@ func (this *CSLoginHandler) Process(s *netlib.Session, packetid int, data interf
// 用缓存信息做登录有account
// 根据StartLogin代码这里ls.acc一定不为nil
// 验证token
ls = LoginStateMgrSington.GetLoginStateByName(UserKey(csl.GetUsername(), csl.GetPlatform(), tagkey))
if ls != nil {
acc := ls.acc
@ -325,6 +340,18 @@ func (this *CSLoginHandler) Process(s *netlib.Session, packetid int, data interf
}
}
}
case common.LoginTypePlatformToken:
// 验证token
pwdIsErr = true
//expire := (claims.(jwt.MapClaims))["Exp"].(int64)
////timeStamp := (claims.(jwt.MapClaims))["Timestamp"]
//
//if username == username && expire <= time.Now().Add(time.Hour*24).Unix() {
// pwdIsErr = true
//} else {
// pwdIsErr = false
//}
}
//密码错误

View File

@ -4,7 +4,9 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/golang-jwt/jwt/v4"
"io"
"mongo.games.com/game/webapi"
"strconv"
"strings"
"time"
@ -39,20 +41,24 @@ type TaskLogin struct {
func (t *TaskLogin) Call(o *basic.Object) interface{} {
var playerData *model.PlayerData
// token验证
//claims, err := webapi.ParseJwtWithClaims([]byte(common.Config.AppId), t.Token)
//if err != nil {
// return nil
//}
//
//logger.Logger.Tracef("TaskLogin ParseJwtWithClaims: claims:%v", claims.(jwt.MapClaims))
if t.GetLoginType() == common.LoginTypePlatformToken {
//token验证
claims, err := webapi.ParseJwtWithClaims([]byte(common.Config.AppId), t.Token)
if err != nil {
return nil
}
logger.Logger.Tracef("TaskLogin ParseJwtWithClaims: claims:%v", claims.(jwt.MapClaims))
username := (claims.(jwt.MapClaims))["Username"].(string)
t.Username = username
}
//username := (claims.(jwt.MapClaims))["Username"]
//expire := (claims.(jwt.MapClaims))["Exp"]
//timeStamp := (claims.(jwt.MapClaims))["Timestamp"]
acc, retCode := model.AccountIsExist(t.GetUsername(), t.GetUsername(), t.GetPassword(), t.GetPlatform(),
t.GetTimeStamp(), t.GetLoginType(), t.tagkey, false, t.codeValid)
t.GetTimeStamp(), common.LoginTypePlatformToken, t.tagkey, false, t.codeValid)
switch retCode {
case common.LoginOk: