Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
6a39b36e47
@ -44,6 +44,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.EnchantChallen
|
||||
code = pb.ErrorCode_ItemsNoEnough
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := enchant.Boss[req.BossType]
|
||||
if !ok { // 类型校验
|
||||
enchant.Boss[req.BossType] = 0
|
||||
|
@ -30,10 +30,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.EnchantGetListRe
|
||||
list.Boss = make(map[int32]int64)
|
||||
list.BossTime = make(map[int32]int32)
|
||||
|
||||
_cfg := this.module.configure.GetEnchantBossTypeConfigData()
|
||||
for k := range _cfg {
|
||||
list.BossTime[k] = 0
|
||||
}
|
||||
this.module.modelEnchant.Add(session.GetUserId(), list)
|
||||
}
|
||||
if session.GetUserId() != "" { // 恢复时间
|
||||
|
@ -68,25 +68,6 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error)
|
||||
return configure.GetConfigure(name)
|
||||
}
|
||||
|
||||
// get boss Type
|
||||
func (this *configureComp) GetEnchantBossTypeConfigData() (mapType map[int32]struct{}) {
|
||||
|
||||
mapType = make(map[int32]struct{}, 0)
|
||||
if v, err := this.GetConfigure(game_enchantboss); err == nil {
|
||||
if configure, ok := v.(*cfg.GameEnchantBoss); ok {
|
||||
this.hlock.Lock()
|
||||
defer this.hlock.Unlock()
|
||||
for _, value := range configure.GetDataList() {
|
||||
if _, ok := mapType[value.Bossid]; !ok {
|
||||
mapType[value.Bossid] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) GetBuyChallengeCount(index int32) (data *cfg.GameEnchantShopData) {
|
||||
if v, err := this.GetConfigure(game_enchantshop); err == nil {
|
||||
if configure, ok := v.(*cfg.GameEnchantShop); ok {
|
||||
|
@ -37,6 +37,7 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent {
|
||||
writeChan: make(chan []byte, 2),
|
||||
closeSignal: make(chan bool),
|
||||
state: 1,
|
||||
protoMsg: make(map[string]int64, 0),
|
||||
}
|
||||
agent.wg.Add(2)
|
||||
go agent.readLoop()
|
||||
@ -55,6 +56,8 @@ type Agent struct {
|
||||
closeSignal chan bool
|
||||
state int32 //状态 0 关闭 1 运行 2 关闭中
|
||||
wg sync.WaitGroup
|
||||
hlock sync.RWMutex
|
||||
protoMsg map[string]int64
|
||||
}
|
||||
|
||||
func (this *Agent) readLoop() {
|
||||
@ -93,12 +96,40 @@ locp:
|
||||
var code pb.ErrorCode
|
||||
code, err = this.secAuth(msg)
|
||||
if err == nil {
|
||||
// this.gateway.Debugf("----------2 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||
this.gateway.Debugf("----------2 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||
|
||||
if err := this.messageDistribution(msg); err != nil {
|
||||
this.gateway.Errorf("messageDistribution err:%v", err)
|
||||
go this.Close()
|
||||
break locp
|
||||
}
|
||||
if this.uId != "" {
|
||||
key := this.uId + msg.MainType + msg.SubType // 加锁
|
||||
if v, ok := this.protoMsg[key]; ok {
|
||||
if v != 0 && configure.Now().Unix()-v < 2 {
|
||||
// 返回错误码
|
||||
this.hlock.Lock()
|
||||
this.protoMsg[key] = configure.Now().Unix()
|
||||
this.hlock.Unlock()
|
||||
|
||||
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{
|
||||
ReqMainType: msg.MainType,
|
||||
ReqSubType: msg.SubType,
|
||||
Arg: msg.Data,
|
||||
Code: pb.ErrorCode_InsufficientPermissions})
|
||||
err = this.WriteMsg(&pb.UserMessage{
|
||||
MainType: comm.MainTypeNotify,
|
||||
SubType: comm.SubTypeErrorNotify,
|
||||
Data: data,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
this.hlock.Lock()
|
||||
this.protoMsg[key] = configure.Now().Unix()
|
||||
this.hlock.Unlock()
|
||||
|
||||
}
|
||||
} else {
|
||||
this.gateway.Errorf("agent:%s uId:%s 密钥无效 err:%v", this.sessionId, this.uId, err)
|
||||
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: code, Message: err.Error()})
|
||||
@ -111,6 +142,7 @@ locp:
|
||||
break locp
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
this.gateway.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId)
|
||||
@ -129,11 +161,12 @@ locp:
|
||||
break locp
|
||||
case msg, ok := <-this.writeChan:
|
||||
if ok {
|
||||
// data, err = proto.Marshal(msg)
|
||||
//data, err = proto.Marshal(msg)
|
||||
if err = this.wsConn.WriteMessage(websocket.BinaryMessage, msg); err != nil {
|
||||
this.gateway.Errorf("agent:%s uId:%d WriteMessage err:%v", this.sessionId, this.uId, err)
|
||||
go this.Close()
|
||||
}
|
||||
|
||||
} else {
|
||||
go this.Close()
|
||||
}
|
||||
@ -340,6 +373,15 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
|
||||
log.Field{Key: "req", Value: fmt.Sprintf("%s:%s %v", req.MainType, req.SubType, req.Message.String())},
|
||||
log.Field{Key: "reply", Value: reply.String()},
|
||||
)
|
||||
|
||||
if this.uId != "" {
|
||||
key := this.uId + msg.MainType + msg.SubType
|
||||
this.hlock.Lock()
|
||||
if v, ok := this.protoMsg[key]; ok && v != 0 { // 发送消息 协议解锁
|
||||
v = 0
|
||||
}
|
||||
this.hlock.Unlock()
|
||||
}
|
||||
if reply.Code != pb.ErrorCode_Success {
|
||||
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{
|
||||
ReqMainType: msg.MainType,
|
||||
|
@ -81,22 +81,6 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
|
||||
return
|
||||
}
|
||||
|
||||
//初始化用户扩展
|
||||
initUpdate := map[string]interface{}{
|
||||
"modifynameCount": 1, //修改名称1次
|
||||
"sociatyTicket": globalConf.GuildBossInitialNum, //公会BOSS挑战券
|
||||
"expitem": make(map[string]int32, 0), // 初始化
|
||||
"mline": make(map[string]int32, 0),
|
||||
}
|
||||
if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), initUpdate); err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
this.module.Error("创建初始修改名称次数",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "params", Value: initUpdate},
|
||||
log.Field{Key: "err", Value: err.Error()},
|
||||
)
|
||||
return
|
||||
}
|
||||
var (
|
||||
res []*cfg.Gameatn
|
||||
)
|
||||
|
@ -43,7 +43,25 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err = this.Get(uid, result); err != nil && mongo.ErrNoDocuments != err {
|
||||
if err = this.Get(uid, result); err != nil && mongo.ErrNoDocuments == err {
|
||||
globalConf := this.module.configure.GetGlobalConf()
|
||||
initUpdate := map[string]interface{}{
|
||||
"uid": uid,
|
||||
"modifynameCount": 1, //修改名称1次
|
||||
"sociatyTicket": globalConf.GuildBossInitialNum, //公会BOSS挑战券
|
||||
"expitem": make(map[string]int32, 0), // 初始化
|
||||
"mline": make(map[string]int32, 0),
|
||||
}
|
||||
result.SociatyTicket = globalConf.GuildBossInitialNum
|
||||
if err = this.module.modelExpand.ChangeUserExpand(uid, initUpdate); err != nil {
|
||||
|
||||
this.module.Error("创建初始修改名称次数",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "params", Value: initUpdate},
|
||||
log.Field{Key: "err", Value: err.Error()},
|
||||
)
|
||||
return
|
||||
}
|
||||
this.module.Error("Get", log.Field{Key: "uid", Value: uid})
|
||||
return result, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user