151 lines
3.6 KiB
Go
151 lines
3.6 KiB
Go
package user
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) SwitchDefPerCheck(session comm.IUserSession, req *pb.UserSwitchDefPerReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
//登录
|
|
func (this *apiComp) SwitchDefPer(session comm.IUserSession, req *pb.UserSwitchDefPerReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
change map[string]interface{} = make(map[string]interface{})
|
|
user *pb.DBUser
|
|
conf *cfg.GamePlayerInfor_overviewData
|
|
err error
|
|
keep bool
|
|
)
|
|
|
|
if errdata = this.SwitchDefPerCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
user = this.module.GetUser(session.GetUserId())
|
|
|
|
if req.CurSkin != "" {
|
|
if conf, err = this.module.configure.GetPlayerOverview(req.CurSkin, user.Gender); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.Type != 1 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range user.Skins {
|
|
if v == req.CurSkin {
|
|
keep = true
|
|
}
|
|
}
|
|
if !keep {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
user.CurSkin = req.CurSkin
|
|
user.Avatar = conf.Playerhead
|
|
change["avatar"] = conf.Playerhead
|
|
change["curSkin"] = req.CurSkin
|
|
}
|
|
|
|
if req.CurAction != "" {
|
|
if conf, err = this.module.configure.GetPlayerOverview(req.CurAction, user.Gender); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.Type != 2 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range user.Skins {
|
|
if v == req.CurAction {
|
|
keep = true
|
|
}
|
|
}
|
|
if !keep {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
user.CurAction = req.CurAction
|
|
change["curAction"] = req.CurAction
|
|
}
|
|
|
|
if req.CurBg != "" {
|
|
if conf, err = this.module.configure.GetPlayerOverview(req.CurBg, user.Gender); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.Type != 3 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range user.Skins {
|
|
if v == req.CurBg {
|
|
keep = true
|
|
}
|
|
}
|
|
if !keep {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
user.CurBg = req.CurBg
|
|
change["curBg"] = req.CurBg
|
|
}
|
|
if err = this.module.modelUser.Change(session.GetUserId(), change); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "skinlist", &pb.UserSkinlistPush{
|
|
Skins: user.Skins,
|
|
CurSkin: user.CurSkin,
|
|
CurAction: user.CurAction,
|
|
CurBg: user.CurBg,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "switchdefper", &pb.UserSwitchDefPerResp{
|
|
Issucc: true,
|
|
CurSkin: user.CurSkin,
|
|
CurAction: user.CurAction,
|
|
CurBg: user.CurBg,
|
|
})
|
|
return
|
|
}
|