协议解锁
This commit is contained in:
parent
27d02a32cc
commit
eb9f2bb1ec
@ -37,7 +37,7 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent {
|
||||
writeChan: make(chan []byte, 2),
|
||||
closeSignal: make(chan bool),
|
||||
state: 1,
|
||||
protoMsg: map[string]int64{},
|
||||
protoMsg: make(map[string]int64, 0),
|
||||
}
|
||||
agent.wg.Add(2)
|
||||
go agent.readLoop()
|
||||
@ -97,11 +97,39 @@ locp:
|
||||
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)
|
||||
|
||||
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()})
|
||||
@ -114,14 +142,7 @@ locp:
|
||||
break locp
|
||||
}
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
this.gateway.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId)
|
||||
@ -352,34 +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 // 加锁
|
||||
if v, ok := this.protoMsg[key]; ok {
|
||||
if v != 0 && configure.Now().Unix()-v < 2 {
|
||||
// 返回错误码
|
||||
key := this.uId + msg.MainType + msg.SubType
|
||||
this.hlock.Lock()
|
||||
this.protoMsg[key] = configure.Now().Unix()
|
||||
if v, ok := this.protoMsg[key]; ok && v != 0 { // 发送消息 协议解锁
|
||||
v = 0
|
||||
}
|
||||
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()
|
||||
|
||||
}
|
||||
|
||||
if reply.Code != pb.ErrorCode_Success {
|
||||
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{
|
||||
ReqMainType: msg.MainType,
|
||||
|
Loading…
Reference in New Issue
Block a user