上传用户信息传递

This commit is contained in:
liwei1dao 2023-12-19 16:04:54 +08:00
parent c26783c877
commit 55b49e288f
7 changed files with 50 additions and 18 deletions

View File

@ -1157,3 +1157,8 @@ const (
GMResAddType int32 = 0
GMResDelType int32 = 1
)
//session Session 临时数据key
const (
Session_User = "user"
)

View File

@ -84,6 +84,8 @@ type IUserSession interface {
Close() (err error)
Reset()
Clone() (session IUserSession) //克隆
SetMate(name string, value interface{})
GetMate(name string) (ok bool, value interface{})
ToString() string
}

View File

@ -18,6 +18,7 @@ import (
func NewUserSessionByPools(service IService) IUserSession {
return &UserSession{
msgqueue: make([]*pb.UserMessage, 0),
mate: make(map[string]interface{}),
service: service,
}
}
@ -30,6 +31,7 @@ type UserSession struct {
UserId string
service IService
msgqueue []*pb.UserMessage
mate map[string]interface{}
}
// 重置
@ -40,6 +42,7 @@ func (this *UserSession) SetSession(ip, sessionId, stag, sid, uid string) {
this.GatewayServiceId = sid
this.UserId = uid
this.msgqueue = this.msgqueue[:0]
}
// 重置
@ -49,6 +52,7 @@ func (this *UserSession) Reset() {
this.GatewayServiceId = ""
this.UserId = ""
this.msgqueue = this.msgqueue[:0]
this.mate = make(map[string]interface{})
}
// 获取用户的会话id
@ -111,6 +115,17 @@ func (this *UserSession) UnBind() (err error) {
return
}
//写入元数据
func (this *UserSession) SetMate(name string, value interface{}) {
this.mate[name] = value
}
//写入元数据
func (this *UserSession) GetMate(name string) (ok bool, value interface{}) {
value, ok = this.mate[name]
return
}
// 向用户发送消息
func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) {
// log.Debugf("SendMsg to UserId:[%s] Data: %v", this.UserId, msg)
@ -174,6 +189,9 @@ func (this *UserSession) SyncPush() (err error) {
func (this *UserSession) Clone() (session IUserSession) {
session = this.service.GetUserSession()
session.SetSession(this.IP, this.SessionId, this.ServiceTag, this.GatewayServiceId, this.UserId)
for k, v := range this.mate {
session.SetMate(k, v)
}
return
}

View File

@ -65,9 +65,12 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto
break
case "finish":
resp := message.(*pb.WTaskFinishResp)
for i, v := range this.info.Accepts {
if v == resp.Tid {
this.info.Accepts = append(this.info.Accepts[0:i], this.info.Accepts[i+1:]...)
if this.info != nil && this.info.Accepts != nil {
for i, v := range this.info.Accepts {
if v == resp.Tid {
this.info.Accepts = append(this.info.Accepts[0:i], this.info.Accepts[i+1:]...)
break
}
}
}
break
@ -79,7 +82,7 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto
break
case "acceptchange":
resp := message.(*pb.WTaskAcceptChangePush)
log.Debug("[机器人 WTask-AcceptChange]", log.Field{Key: "Account", Value: robot.Account()}, log.Field{Key: "Resp", Value: resp.String()})
// log.Debug("[机器人 WTask-AcceptChange]", log.Field{Key: "Account", Value: robot.Account()}, log.Field{Key: "Resp", Value: resp.String()})
this.progress = resp.Accepts
if this.info != nil {
this.info.Accepts = make([]int32, 0)

View File

@ -313,7 +313,7 @@ func (this *Robot) run() {
this.Close()
return
}
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(2000)))
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(1000)))
}
for this.cycle {
@ -345,7 +345,7 @@ func (this *Robot) run() {
this.cycle = true
}
}
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(2000)))
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(1000)))
}
}
this.Close()

View File

@ -86,12 +86,13 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e
"ps": 0, //设置初始体力 调整未0 由策划初始表发放
}
globalConf := this.module.globalConf
if req.Gender == 0 {
if req.Gender == 1 {
update["avatar"] = globalConf.BoyHeadPortrait
} else if req.Gender == 1 {
} else if req.Gender == 2 {
update["avatar"] = globalConf.GirlHeadPortrait
}
user.Gender = req.Gender
session.SetMate(comm.Session_User, user)
if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
@ -109,11 +110,10 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e
for _, v := range val.GetDataList() {
res = append(res, v.Var...)
}
if errdata, award = this.module.DispenseAtno(session, res, true); errdata != nil {
if errdata, _ := this.module.DispenseAtno(session, res, true); errdata != nil {
this.module.Error("发放资源失败!", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "err", Value: errdata.String()})
}
}
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype72, 1))
session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateResp{
NickName: req.NickName,
@ -124,6 +124,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e
//异步逻辑
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.mail.SendMailByCid(session, comm.Welcomemail, nil)
if len(tasks) > 0 {
this.module.ModuleBuried.TriggerBuried(session, tasks...)

View File

@ -1157,15 +1157,18 @@ func (this *User) AddPer(session comm.IUserSession, pers map[string]int32, bPush
adds []string = make([]string, 0)
iskeep bool
)
if user, err = this.GetUser(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserSessionNobeing,
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
Message: err.Error(),
if ok, userMate := session.GetMate(comm.Session_User); ok {
user = userMate.(*pb.DBUser)
} else {
if user, err = this.GetUser(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserSessionNobeing,
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
Message: err.Error(),
}
return
}
return
}
for k, _ := range pers {
iskeep = false
for _, v1 := range user.Skins {