1
This commit is contained in:
parent
29680246f5
commit
94a82c4e1f
@ -2,12 +2,9 @@ package cs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"q5"
|
"q5"
|
||||||
|
proto "github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParsePb(msgId int, data []byte) interface{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type MsgHandler interface {
|
type MsgHandler interface {
|
||||||
CMPing(*q5.MsgHdr, *CMPing)
|
CMPing(*q5.MsgHdr, *CMPing)
|
||||||
CMLogin(*q5.MsgHdr, *CMLogin)
|
CMLogin(*q5.MsgHdr, *CMLogin)
|
||||||
@ -20,9 +17,12 @@ type MsgHandlerImpl struct {
|
|||||||
type NetMsgHandler struct {
|
type NetMsgHandler struct {
|
||||||
MsgId int
|
MsgId int
|
||||||
HandlerId int
|
HandlerId int
|
||||||
|
parseCb func([]byte) interface{}
|
||||||
cb func(*q5.MsgHdr, MsgHandler)
|
cb func(*q5.MsgHdr, MsgHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var handlers [2000]*NetMsgHandler
|
||||||
|
|
||||||
func (this *MsgHandlerImpl) CMPing(hdr *q5.MsgHdr, msg *CMPing) {
|
func (this *MsgHandlerImpl) CMPing(hdr *q5.MsgHdr, msg *CMPing) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,9 +33,30 @@ func (this *MsgHandlerImpl) CMReconnect(hdr *q5.MsgHdr, msg *CMReconnect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetNetMsgHandler(msgId int) *NetMsgHandler {
|
func GetNetMsgHandler(msgId int) *NetMsgHandler {
|
||||||
return nil
|
handler := handlers[msgId]
|
||||||
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func DispatchMsg(handler *NetMsgHandler, hdr *q5.MsgHdr, msgHandler MsgHandler) {
|
func DispatchMsg(handler *NetMsgHandler, hdr *q5.MsgHdr, msgHandler MsgHandler) {
|
||||||
handler.cb(hdr, msgHandler)
|
handler.cb(hdr, msgHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func ParsePb(msgId int, data []byte) interface{} {
|
||||||
|
handler := handlers[msgId]
|
||||||
|
return handler.parseCb(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
handlers[10] = &NetMsgHandler{
|
||||||
|
MsgId: int(CMMessageIdE__CMPing),
|
||||||
|
parseCb: func (data []byte) interface{} {
|
||||||
|
msg := &CMLogin{}
|
||||||
|
proto.Unmarshal(data, msg)
|
||||||
|
return msg
|
||||||
|
},
|
||||||
|
cb: func (hdr *q5.MsgHdr, handler MsgHandler) {
|
||||||
|
handler.CMPing(hdr, hdr.Msg.(*CMPing))
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user