238 lines
7.7 KiB
Go
238 lines
7.7 KiB
Go
package cs
|
|
|
|
import (
|
|
"f5"
|
|
proto "github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
type CsNetMsgHandler f5.NetMsgHandler[MsgHandler];
|
|
|
|
type MsgHandlerImpl struct {
|
|
}
|
|
|
|
var handlers [2000]*CsNetMsgHandler
|
|
|
|
func GetNetMsgHandler(msgId uint16) *CsNetMsgHandler {
|
|
handler := handlers[msgId]
|
|
return handler
|
|
}
|
|
|
|
func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
|
|
handler.Cb(hdr, msgHandler)
|
|
}
|
|
|
|
func RegHandlerId(msgId int, handlerId int) {
|
|
handler := handlers[msgId]
|
|
handler.HandlerId = handlerId
|
|
}
|
|
|
|
func ParsePb(msgId uint16, data []byte) interface{} {
|
|
handler := handlers[msgId]
|
|
if handler == nil {
|
|
return nil
|
|
}
|
|
return handler.ParseCb(data)
|
|
}
|
|
|
|
type MsgHandler interface {
|
|
CMPing(*f5.MsgHdr, *CMPing)
|
|
CMLogin(*f5.MsgHdr, *CMLogin)
|
|
CMReconnect(*f5.MsgHdr, *CMReconnect)
|
|
CMSearchFriend(*f5.MsgHdr, *CMSearchFriend)
|
|
CMListPendingFriendRequest(*f5.MsgHdr, *CMListPendingFriendRequest)
|
|
CMAddFriendRequest(*f5.MsgHdr, *CMAddFriendRequest)
|
|
CMAcceptFriendRequest(*f5.MsgHdr, *CMAcceptFriendRequest)
|
|
CMListFriend(*f5.MsgHdr, *CMListFriend)
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMPing(hdr *f5.MsgHdr, msg *CMPing) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMLogin(hdr *f5.MsgHdr, msg *CMLogin) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMReconnect(hdr *f5.MsgHdr, msg *CMReconnect) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMSearchFriend(hdr *f5.MsgHdr, msg *CMSearchFriend) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *CMListPendingFriendRequest) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMAddFriendRequest(hdr *f5.MsgHdr, msg *CMAddFriendRequest) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *CMAcceptFriendRequest) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMListFriend(hdr *f5.MsgHdr, msg *CMListFriend) {
|
|
}
|
|
|
|
func (this *CMPing) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMPing)
|
|
}
|
|
|
|
func (this *SMPing) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMPing)
|
|
}
|
|
|
|
func (this *SMRpcError) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMRpcError)
|
|
}
|
|
|
|
func (this *CMLogin) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMLogin)
|
|
}
|
|
|
|
func (this *SMLogin) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMLogin)
|
|
}
|
|
|
|
func (this *CMReconnect) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMReconnect)
|
|
}
|
|
|
|
func (this *SMReconnect) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMReconnect)
|
|
}
|
|
|
|
func (this *CMSearchFriend) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMSearchFriend)
|
|
}
|
|
|
|
func (this *SMSearchFriend) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMSearchFriend)
|
|
}
|
|
|
|
func (this *CMListPendingFriendRequest) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMListPendingFriendRequest)
|
|
}
|
|
|
|
func (this *SMListPendingFriendRequest) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMListPendingFriendRequest)
|
|
}
|
|
|
|
func (this *CMAddFriendRequest) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMAddFriendRequest)
|
|
}
|
|
|
|
func (this *SMAddFriendRequest) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMAddFriendRequest)
|
|
}
|
|
|
|
func (this *CMAcceptFriendRequest) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMAcceptFriendRequest)
|
|
}
|
|
|
|
func (this *SMAcceptFriendRequest) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMAcceptFriendRequest)
|
|
}
|
|
|
|
func (this *CMListFriend) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMListFriend)
|
|
}
|
|
|
|
func (this *SMListFriend) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMListFriend)
|
|
}
|
|
|
|
func init() {
|
|
|
|
handlers[int(CMMessageIdE__CMPing)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMPing),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMPing{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMPing(hdr, hdr.Msg.(*CMPing))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMLogin)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMLogin),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMLogin{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMLogin(hdr, hdr.Msg.(*CMLogin))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMReconnect)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMReconnect),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMReconnect{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMReconnect(hdr, hdr.Msg.(*CMReconnect))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMSearchFriend)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMSearchFriend),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMSearchFriend{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMSearchFriend(hdr, hdr.Msg.(*CMSearchFriend))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMListPendingFriendRequest)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMListPendingFriendRequest),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMListPendingFriendRequest{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMListPendingFriendRequest(hdr, hdr.Msg.(*CMListPendingFriendRequest))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMAddFriendRequest)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMAddFriendRequest),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMAddFriendRequest{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMAddFriendRequest(hdr, hdr.Msg.(*CMAddFriendRequest))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMAcceptFriendRequest)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMAcceptFriendRequest),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMAcceptFriendRequest{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMAcceptFriendRequest(hdr, hdr.Msg.(*CMAcceptFriendRequest))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMListFriend)] = &CsNetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMListFriend),
|
|
ParseCb: func (data []byte) interface{} {
|
|
msg := &CMListFriend{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMListFriend(hdr, hdr.Msg.(*CMListFriend))
|
|
},
|
|
}
|
|
|
|
} |