上传用户信息传递

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 GMResAddType int32 = 0
GMResDelType int32 = 1 GMResDelType int32 = 1
) )
//session Session 临时数据key
const (
Session_User = "user"
)

View File

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

View File

@ -18,6 +18,7 @@ import (
func NewUserSessionByPools(service IService) IUserSession { func NewUserSessionByPools(service IService) IUserSession {
return &UserSession{ return &UserSession{
msgqueue: make([]*pb.UserMessage, 0), msgqueue: make([]*pb.UserMessage, 0),
mate: make(map[string]interface{}),
service: service, service: service,
} }
} }
@ -30,6 +31,7 @@ type UserSession struct {
UserId string UserId string
service IService service IService
msgqueue []*pb.UserMessage 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.GatewayServiceId = sid
this.UserId = uid this.UserId = uid
this.msgqueue = this.msgqueue[:0] this.msgqueue = this.msgqueue[:0]
} }
// 重置 // 重置
@ -49,6 +52,7 @@ func (this *UserSession) Reset() {
this.GatewayServiceId = "" this.GatewayServiceId = ""
this.UserId = "" this.UserId = ""
this.msgqueue = this.msgqueue[:0] this.msgqueue = this.msgqueue[:0]
this.mate = make(map[string]interface{})
} }
// 获取用户的会话id // 获取用户的会话id
@ -111,6 +115,17 @@ func (this *UserSession) UnBind() (err error) {
return 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) { func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) {
// log.Debugf("SendMsg to UserId:[%s] Data: %v", this.UserId, msg) // 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) { func (this *UserSession) Clone() (session IUserSession) {
session = this.service.GetUserSession() session = this.service.GetUserSession()
session.SetSession(this.IP, this.SessionId, this.ServiceTag, this.GatewayServiceId, this.UserId) session.SetSession(this.IP, this.SessionId, this.ServiceTag, this.GatewayServiceId, this.UserId)
for k, v := range this.mate {
session.SetMate(k, v)
}
return return
} }

View File

@ -65,9 +65,12 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto
break break
case "finish": case "finish":
resp := message.(*pb.WTaskFinishResp) resp := message.(*pb.WTaskFinishResp)
for i, v := range this.info.Accepts { if this.info != nil && this.info.Accepts != nil {
if v == resp.Tid { for i, v := range this.info.Accepts {
this.info.Accepts = append(this.info.Accepts[0:i], this.info.Accepts[i+1:]...) if v == resp.Tid {
this.info.Accepts = append(this.info.Accepts[0:i], this.info.Accepts[i+1:]...)
break
}
} }
} }
break break
@ -79,7 +82,7 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto
break break
case "acceptchange": case "acceptchange":
resp := message.(*pb.WTaskAcceptChangePush) 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 this.progress = resp.Accepts
if this.info != nil { if this.info != nil {
this.info.Accepts = make([]int32, 0) this.info.Accepts = make([]int32, 0)

View File

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

View File

@ -86,12 +86,13 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e
"ps": 0, //设置初始体力 调整未0 由策划初始表发放 "ps": 0, //设置初始体力 调整未0 由策划初始表发放
} }
globalConf := this.module.globalConf globalConf := this.module.globalConf
if req.Gender == 0 { if req.Gender == 1 {
update["avatar"] = globalConf.BoyHeadPortrait update["avatar"] = globalConf.BoyHeadPortrait
} else if req.Gender == 1 { } else if req.Gender == 2 {
update["avatar"] = globalConf.GirlHeadPortrait 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 { if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_DBError,
@ -109,11 +110,10 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (e
for _, v := range val.GetDataList() { for _, v := range val.GetDataList() {
res = append(res, v.Var...) 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()}) 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)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype72, 1))
session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateResp{ session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateResp{
NickName: req.NickName, 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) { go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.mail.SendMailByCid(session, comm.Welcomemail, nil) this.mail.SendMailByCid(session, comm.Welcomemail, nil)
if len(tasks) > 0 { if len(tasks) > 0 {
this.module.ModuleBuried.TriggerBuried(session, tasks...) 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) adds []string = make([]string, 0)
iskeep bool iskeep bool
) )
if user, err = this.GetUser(session.GetUserId()); err != nil { if ok, userMate := session.GetMate(comm.Session_User); ok {
errdata = &pb.ErrorData{ user = userMate.(*pb.DBUser)
Code: pb.ErrorCode_UserSessionNobeing, } else {
Title: pb.ErrorCode_UserSessionNobeing.ToString(), if user, err = this.GetUser(session.GetUserId()); err != nil {
Message: err.Error(), errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserSessionNobeing,
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
Message: err.Error(),
}
return
} }
return
} }
for k, _ := range pers { for k, _ := range pers {
iskeep = false iskeep = false
for _, v1 := range user.Skins { for _, v1 := range user.Skins {