更新protobuf消息协议内容
This commit is contained in:
parent
3b78707f0d
commit
30dc225da6
@ -43,6 +43,10 @@ type MsgHandler interface {
|
||||
CMPing(*f5.MsgHdr, *CMPing)
|
||||
CMLogin(*f5.MsgHdr, *CMLogin)
|
||||
CMReconnect(*f5.MsgHdr, *CMReconnect)
|
||||
CMSearchFriend(*f5.MsgHdr, *CMSearchFriend)
|
||||
CMAddFriendRequest(*f5.MsgHdr, *CMAddFriendRequest)
|
||||
CMAcceptFriendRequest(*f5.MsgHdr, *CMAcceptFriendRequest)
|
||||
CMListFriend(*f5.MsgHdr, *CMListFriend)
|
||||
}
|
||||
|
||||
func (this *MsgHandlerImpl) CMPing(hdr *f5.MsgHdr, msg *CMPing) {
|
||||
@ -54,6 +58,18 @@ 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) 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)
|
||||
}
|
||||
@ -82,6 +98,38 @@ 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 *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)] = &NetMsgHandler{
|
||||
@ -120,4 +168,52 @@ func init() {
|
||||
},
|
||||
}
|
||||
|
||||
handlers[int(CMMessageIdE__CMSearchFriend)] = &NetMsgHandler{
|
||||
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__CMAddFriendRequest)] = &NetMsgHandler{
|
||||
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)] = &NetMsgHandler{
|
||||
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)] = &NetMsgHandler{
|
||||
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))
|
||||
},
|
||||
}
|
||||
|
||||
}
|
@ -24,10 +24,13 @@ const (
|
||||
type CMMessageIdE int32
|
||||
|
||||
const (
|
||||
CMMessageIdE__CMPing CMMessageIdE = 101
|
||||
CMMessageIdE__CMLogin CMMessageIdE = 103
|
||||
CMMessageIdE__CMReconnect CMMessageIdE = 104
|
||||
CMMessageIdE__CMSearchFriend CMMessageIdE = 105
|
||||
CMMessageIdE__CMPing CMMessageIdE = 101
|
||||
CMMessageIdE__CMLogin CMMessageIdE = 103
|
||||
CMMessageIdE__CMReconnect CMMessageIdE = 104
|
||||
CMMessageIdE__CMSearchFriend CMMessageIdE = 105
|
||||
CMMessageIdE__CMAddFriendRequest CMMessageIdE = 106
|
||||
CMMessageIdE__CMAcceptFriendRequest CMMessageIdE = 107
|
||||
CMMessageIdE__CMListFriend CMMessageIdE = 108
|
||||
)
|
||||
|
||||
// Enum value maps for CMMessageIdE.
|
||||
@ -37,12 +40,18 @@ var (
|
||||
103: "_CMLogin",
|
||||
104: "_CMReconnect",
|
||||
105: "_CMSearchFriend",
|
||||
106: "_CMAddFriendRequest",
|
||||
107: "_CMAcceptFriendRequest",
|
||||
108: "_CMListFriend",
|
||||
}
|
||||
CMMessageIdE_value = map[string]int32{
|
||||
"_CMPing": 101,
|
||||
"_CMLogin": 103,
|
||||
"_CMReconnect": 104,
|
||||
"_CMSearchFriend": 105,
|
||||
"_CMPing": 101,
|
||||
"_CMLogin": 103,
|
||||
"_CMReconnect": 104,
|
||||
"_CMSearchFriend": 105,
|
||||
"_CMAddFriendRequest": 106,
|
||||
"_CMAcceptFriendRequest": 107,
|
||||
"_CMListFriend": 108,
|
||||
}
|
||||
)
|
||||
|
||||
@ -86,10 +95,14 @@ func (CMMessageIdE) EnumDescriptor() ([]byte, []int) {
|
||||
type SMMessageIdE int32
|
||||
|
||||
const (
|
||||
SMMessageIdE__SMPing SMMessageIdE = 101
|
||||
SMMessageIdE__SMRpcError SMMessageIdE = 102
|
||||
SMMessageIdE__SMReconnect SMMessageIdE = 104
|
||||
SMMessageIdE__SMLogin SMMessageIdE = 103
|
||||
SMMessageIdE__SMPing SMMessageIdE = 101
|
||||
SMMessageIdE__SMRpcError SMMessageIdE = 102
|
||||
SMMessageIdE__SMReconnect SMMessageIdE = 104
|
||||
SMMessageIdE__SMSearchFriend SMMessageIdE = 105
|
||||
SMMessageIdE__SMAddFriendRequest SMMessageIdE = 106
|
||||
SMMessageIdE__SMAcceptFriendRequest SMMessageIdE = 107
|
||||
SMMessageIdE__SMListFriend SMMessageIdE = 108
|
||||
SMMessageIdE__SMLogin SMMessageIdE = 103
|
||||
)
|
||||
|
||||
// Enum value maps for SMMessageIdE.
|
||||
@ -98,13 +111,21 @@ var (
|
||||
101: "_SMPing",
|
||||
102: "_SMRpcError",
|
||||
104: "_SMReconnect",
|
||||
105: "_SMSearchFriend",
|
||||
106: "_SMAddFriendRequest",
|
||||
107: "_SMAcceptFriendRequest",
|
||||
108: "_SMListFriend",
|
||||
103: "_SMLogin",
|
||||
}
|
||||
SMMessageIdE_value = map[string]int32{
|
||||
"_SMPing": 101,
|
||||
"_SMRpcError": 102,
|
||||
"_SMReconnect": 104,
|
||||
"_SMLogin": 103,
|
||||
"_SMPing": 101,
|
||||
"_SMRpcError": 102,
|
||||
"_SMReconnect": 104,
|
||||
"_SMSearchFriend": 105,
|
||||
"_SMAddFriendRequest": 106,
|
||||
"_SMAcceptFriendRequest": 107,
|
||||
"_SMListFriend": 108,
|
||||
"_SMLogin": 103,
|
||||
}
|
||||
)
|
||||
|
||||
@ -149,17 +170,28 @@ var File_cs_msgid_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_cs_msgid_proto_rawDesc = []byte{
|
||||
0x0a, 0x0e, 0x63, 0x73, 0x5f, 0x6d, 0x73, 0x67, 0x69, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x12, 0x02, 0x63, 0x73, 0x2a, 0x51, 0x0a, 0x0d, 0x43, 0x4d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x49, 0x64, 0x5f, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x5f, 0x43, 0x4d, 0x50, 0x69, 0x6e, 0x67,
|
||||
0x10, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x5f, 0x43, 0x4d, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x10, 0x67,
|
||||
0x12, 0x10, 0x0a, 0x0c, 0x5f, 0x43, 0x4d, 0x52, 0x65, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74,
|
||||
0x10, 0x68, 0x12, 0x13, 0x0a, 0x0f, 0x5f, 0x43, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x46,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x10, 0x69, 0x2a, 0x4d, 0x0a, 0x0d, 0x53, 0x4d, 0x4d, 0x65, 0x73,
|
||||
0x73, 0x61, 0x67, 0x65, 0x49, 0x64, 0x5f, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x5f, 0x53, 0x4d, 0x50,
|
||||
0x69, 0x6e, 0x67, 0x10, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x5f, 0x53, 0x4d, 0x52, 0x70, 0x63, 0x45,
|
||||
0x72, 0x72, 0x6f, 0x72, 0x10, 0x66, 0x12, 0x10, 0x0a, 0x0c, 0x5f, 0x53, 0x4d, 0x52, 0x65, 0x63,
|
||||
0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x10, 0x68, 0x12, 0x0c, 0x0a, 0x08, 0x5f, 0x53, 0x4d, 0x4c,
|
||||
0x6f, 0x67, 0x69, 0x6e, 0x10, 0x67, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x63, 0x73,
|
||||
0x12, 0x02, 0x63, 0x73, 0x2a, 0x99, 0x01, 0x0a, 0x0d, 0x43, 0x4d, 0x4d, 0x65, 0x73, 0x73, 0x61,
|
||||
0x67, 0x65, 0x49, 0x64, 0x5f, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x5f, 0x43, 0x4d, 0x50, 0x69, 0x6e,
|
||||
0x67, 0x10, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x5f, 0x43, 0x4d, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x10,
|
||||
0x67, 0x12, 0x10, 0x0a, 0x0c, 0x5f, 0x43, 0x4d, 0x52, 0x65, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63,
|
||||
0x74, 0x10, 0x68, 0x12, 0x13, 0x0a, 0x0f, 0x5f, 0x43, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68,
|
||||
0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x10, 0x69, 0x12, 0x17, 0x0a, 0x13, 0x5f, 0x43, 0x4d, 0x41,
|
||||
0x64, 0x64, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x10,
|
||||
0x6a, 0x12, 0x1a, 0x0a, 0x16, 0x5f, 0x43, 0x4d, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x46, 0x72,
|
||||
0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x10, 0x6b, 0x12, 0x11, 0x0a,
|
||||
0x0d, 0x5f, 0x43, 0x4d, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x10, 0x6c,
|
||||
0x2a, 0xaa, 0x01, 0x0a, 0x0d, 0x53, 0x4d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x64,
|
||||
0x5f, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x5f, 0x53, 0x4d, 0x50, 0x69, 0x6e, 0x67, 0x10, 0x65, 0x12,
|
||||
0x0f, 0x0a, 0x0b, 0x5f, 0x53, 0x4d, 0x52, 0x70, 0x63, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x66,
|
||||
0x12, 0x10, 0x0a, 0x0c, 0x5f, 0x53, 0x4d, 0x52, 0x65, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74,
|
||||
0x10, 0x68, 0x12, 0x13, 0x0a, 0x0f, 0x5f, 0x53, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x46,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x10, 0x69, 0x12, 0x17, 0x0a, 0x13, 0x5f, 0x53, 0x4d, 0x41, 0x64,
|
||||
0x64, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x10, 0x6a,
|
||||
0x12, 0x1a, 0x0a, 0x16, 0x5f, 0x53, 0x4d, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x46, 0x72, 0x69,
|
||||
0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x10, 0x6b, 0x12, 0x11, 0x0a, 0x0d,
|
||||
0x5f, 0x53, 0x4d, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x10, 0x6c, 0x12,
|
||||
0x0c, 0x0a, 0x08, 0x5f, 0x53, 0x4d, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x10, 0x67, 0x42, 0x06, 0x5a,
|
||||
0x04, 0x2e, 0x3b, 0x63, 0x73,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -2,7 +2,13 @@ module cs
|
||||
|
||||
go 1.20
|
||||
|
||||
require f5 v1.0.0
|
||||
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.4.2
|
||||
google.golang.org/protobuf v1.23.0
|
||||
)
|
||||
|
||||
replace q5 => ../../../third_party/q5
|
||||
replace f5 => ../../../third_party/f5
|
@ -4,6 +4,7 @@ import (
|
||||
"cs"
|
||||
"errors"
|
||||
"f5"
|
||||
"fmt"
|
||||
"mt"
|
||||
"q5"
|
||||
"strings"
|
||||
@ -88,6 +89,29 @@ func (fm *FriendsMgr) searchFriends(searchKeyword string) []*User {
|
||||
return listFriend
|
||||
}
|
||||
|
||||
func (fm *FriendsMgr) addFriendRequestAccountIds(accountId string) ([]string, error) {
|
||||
// 检查用户是否存在
|
||||
if _, ok := fm.users[accountId]; !ok {
|
||||
return nil, fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
// 获取用户的等待验证的好友请求
|
||||
pendingRequests, ok := fm.pendingReqs[accountId]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 构建等待验证的好友请求列表
|
||||
var requestAccountIds []string
|
||||
for request, isTrue := range pendingRequests {
|
||||
if isTrue {
|
||||
requestAccountIds = append(requestAccountIds, request)
|
||||
}
|
||||
}
|
||||
|
||||
return requestAccountIds, nil
|
||||
}
|
||||
|
||||
// addFriendRequest 发送好友请求
|
||||
func (fm *FriendsMgr) addFriendRequest(user1Id string, user2Id string) error {
|
||||
// Check if users exist
|
||||
@ -131,6 +155,22 @@ func (fm *FriendsMgr) acceptFriendRequest(user1Id string, user2Id string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// rejectFriendRequest 拒绝好友请求
|
||||
func (fm *FriendsMgr) rejectFriendRequest(user1Id string, user2Id string) error {
|
||||
if !fm.pendingReqs[user1Id][user2Id] {
|
||||
return errors.New("no pending friend request from user1 to user2")
|
||||
}
|
||||
err := fm.acceptFriendRequestToDB(user1Id, user2Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//fm.pendingReqs[user1Id], user2Id
|
||||
//fm.pendingReqs[user2Id], user1Id
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CMListFriend 我的好友列表
|
||||
func (fm *FriendsMgr) listFriend(accountId string) []*User {
|
||||
// By default, Users member data count:10
|
||||
@ -219,7 +259,7 @@ func (fm *FriendsMgr) loadFriendshipsFromDB(conn *q5.Mysql) {
|
||||
}
|
||||
|
||||
func (fm *FriendsMgr) loadPendingRequestsFromDB(conn *q5.Mysql) {
|
||||
rows, err := conn.Query("select sender_account_id, receiver_account_id from t_pending_friend_requests;")
|
||||
rows, err := conn.Query("select sender_account_id, receiver_account_id, flag from t_pending_friend_requests where flag ;")
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("mysql error", err)
|
||||
return
|
||||
@ -228,7 +268,8 @@ func (fm *FriendsMgr) loadPendingRequestsFromDB(conn *q5.Mysql) {
|
||||
|
||||
for rows.Next() {
|
||||
var senderAccountId, receiverAccountId string
|
||||
if err := rows.Scan(&senderAccountId, &receiverAccountId); err != nil {
|
||||
var pendingRequestStatus string
|
||||
if err := rows.Scan(&senderAccountId, &receiverAccountId, &pendingRequestStatus); err != nil {
|
||||
continue
|
||||
}
|
||||
if pendingReqs[senderAccountId] == nil {
|
||||
|
@ -13,8 +13,8 @@ type Player struct {
|
||||
}
|
||||
|
||||
func (p *Player) CMSearchFriends(hdr *f5.MsgHdr, msg *cs.CMSearchFriend) {
|
||||
//rspMsg := new(cs.SMSearchFriend)
|
||||
rspMsg := &cs.SMSearchFriend{}
|
||||
rspMsg := new(cs.SMSearchFriend)
|
||||
//rspMsg := &cs.SMSearchFriend{}
|
||||
listUsers := friendMgr.searchFriends(msg.GetSearchKeyword())
|
||||
for _, u := range listUsers {
|
||||
friend := &cs.MFFriend{
|
||||
|
@ -10,6 +10,9 @@ enum CMMessageId_e
|
||||
_CMLogin = 103;
|
||||
_CMReconnect = 104;
|
||||
_CMSearchFriend = 105;
|
||||
_CMAddFriendRequest = 106;
|
||||
_CMAcceptFriendRequest = 107;
|
||||
_CMListFriend = 108;
|
||||
}
|
||||
|
||||
enum SMMessageId_e
|
||||
@ -17,6 +20,9 @@ enum SMMessageId_e
|
||||
_SMPing = 101;
|
||||
_SMRpcError = 102;
|
||||
_SMReconnect = 104;
|
||||
|
||||
_SMSearchFriend = 105;
|
||||
_SMAddFriendRequest = 106;
|
||||
_SMAcceptFriendRequest = 107;
|
||||
_SMListFriend = 108;
|
||||
_SMLogin = 103;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user