This commit is contained in:
殷勇 2023-09-21 17:09:52 +08:00
parent 095deb582b
commit f924d4e880
8 changed files with 746 additions and 515 deletions

View File

@ -39,11 +39,11 @@ func NewChatMgr(pm *PlayerMgr, fm *FriendsMgr, gm *GuildMgr) *ChatMgr {
func (cm *ChatMgr) init() {}
func (cm *ChatMgr) FillMFChatMsg(msg *cs.MFChatMsg, accountId *string,
func (cm *ChatMgr) FillMFChatMsg(msg *cs.MFChatMsg, sender *Player,
msgAutoId uint64, chatChannel int32, msgType int32, msgBody *string) {
msg.MsgUuid = &msgAutoId
msg.Sender = accountId
msg.Sender = sender.FillMFChatUser()
msg.ChatChannel = &chatChannel
msg.MsgType = &msgType
msg.MsgBody = msgBody
@ -91,10 +91,9 @@ func (cm *ChatMgr) FillSMUpdatePrivateChatRedPointNotify(p *Player, msg *cs.SMUp
}
func (cm *ChatMgr) ProcWorldChat(p *Player, msg *cs.CMSendChatMsg) {
accountId := p.GetAccountId()
chatMsg := new(cs.MFChatMsg)
cm.worldMsgId++
cm.FillMFChatMsg(chatMsg, &accountId, cm.worldMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
cm.FillMFChatMsg(chatMsg, p, cm.worldMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
cm.worldMsgRec.CurrID = cm.worldMsgId
cm.worldMsgRec.AddChatMsg(chatMsg)
@ -114,7 +113,7 @@ func (cm *ChatMgr) ProcGuildChat(p *Player, msg *cs.CMSendChatMsg) {
cm.guildMsgId++
chatMsg := new(cs.MFChatMsg)
cm.FillMFChatMsg(chatMsg, &p.accountId, cm.guildMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
cm.FillMFChatMsg(chatMsg, p, cm.guildMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
if msgRec, exists := cm.guildMsgRec[guildId]; exists {
msgRec.AddChatMsg(chatMsg)
@ -138,6 +137,7 @@ func (cm *ChatMgr) ProcPrivateChat(p *Player, msg *cs.CMSendChatMsg) {
if p.accountId == targetAccountId {
return
}
// 确定是否好友
targetAccount := cm.fm.GetFriendByAccountId(p.accountId, targetAccountId)
if targetAccount == nil {
@ -145,7 +145,7 @@ func (cm *ChatMgr) ProcPrivateChat(p *Player, msg *cs.CMSendChatMsg) {
}
chatMsg := new(cs.MFChatMsg)
cm.FillMFChatMsg(chatMsg, &p.accountId, 0, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
cm.FillMFChatMsg(chatMsg, p, 0, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
cm.AddChatUser(p.accountId, msg.GetTargetAccountId(), chatMsg, p.IncrPrivateChatLastId())
cm.SyncPrivateChatMsg(p)

File diff suppressed because it is too large Load Diff

View File

@ -56,14 +56,6 @@ func (g *Guild) GetMembersViceLeaderCount() int {
return count
}
// GetMember 根据 AccountId 获取成员信息
func (g *Guild) GetMember(accountId string) *GuildMember {
if member, exists := g.Members[accountId]; exists {
return member
}
return nil
}
// IsMember 是否是公会成员
func (g *Guild) IsMember(accountId string) bool {
_, exists := g.Members[accountId]
@ -86,6 +78,22 @@ func (g *Guild) RemoveMember(accountId string) {
delete(g.Members, accountId)
}
// GetMember 获取成员
func (g *Guild) GetMember(accountId string) *GuildMember {
if member, exists := g.Members[accountId]; exists {
return member
}
return nil
}
// GetMemberLevel 获取成员职位
func (g *Guild) GetMemberLevel(accountId string) int32 {
if member, exists := g.Members[accountId]; exists {
return member.Level
}
return 0
}
func (g *Guild) SetNotice(notice *string) {
g.Notice = *notice
}

View File

@ -45,6 +45,12 @@ func (this *HandlerMgr) init() {
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetAvatar), PLAYER_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetJoinCond), PLAYER_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetMemberLevel), PLAYER_HANDLER_ID)
// 聊天
cs.RegHandlerId(int(cs.CMMessageIdE__CMSendChatMsg), PLAYER_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMReadMsgAndOpenChatNotify), PLAYER_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetCurrPrivateChatTarget), PLAYER_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMCloseChatNotify), PLAYER_HANDLER_ID)
}
func (this *HandlerMgr) unInit() {

View File

@ -3,6 +3,7 @@ package mt
import (
"f5"
"mtb"
"q5"
)
type IMCluster struct {
@ -11,13 +12,18 @@ type IMCluster struct {
type IMClusterTable struct {
f5.IdMetaTable[IMCluster]
selfConf *IMCluster
selfConf *IMCluster
serverInfo string
}
func (this *IMCluster) Init1() {
}
func (this *IMClusterTable) GetIp() string {
return q5.GetLocalIP()
}
func (this *IMClusterTable) GetListenPort() int32 {
return this.selfConf.GetListenPort()
}
@ -31,4 +37,9 @@ func (this *IMClusterTable) PostInit1() {
if this.selfConf == nil {
panic("imserver集群无法读取本服配置")
}
this.serverInfo = this.GetIp() + ":" + q5.ToString(this.GetListenPort())
}
func (this *IMClusterTable) GetServerInfo() string {
return this.serverInfo
}

View File

@ -246,11 +246,11 @@ func (p *Player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) {
// CMSendChatMsg 发送聊天消息
func (p *Player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) {
chatChannel := *msg.ChatChannel
if !IsValidChatChannel(chatChannel) {
// p.chatChannel := *msg.ChatChannel
if !IsValidChatChannel(msg.GetChatChannel()) {
return
}
switch chatChannel {
switch msg.GetChatChannel() {
case kCCWorld:
chatMgr.ProcWorldChat(p, msg)
case kCCPrivate:
@ -270,11 +270,11 @@ func (p *Player) SyncPrivateChatRedPoint() {
// CMReadMsgAndOpenChatNotify 读取聊天消息列表并且开启聊天通知
func (p *Player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAndOpenChatNotify) {
chatChannel := *msg.CurrChannel
if !IsValidChatChannel(chatChannel) {
if !IsValidChatChannel(msg.GetCurrChannel()) {
return
}
if chatChannel == kCCPrivate {
p.chatChannel = int(msg.GetCurrChannel())
if p.chatChannel == kCCPrivate {
p.SyncPrivateChatRedPoint()
}
}
@ -779,6 +779,39 @@ func (p *Player) FillMFUser(profile *PlayerProfile) *cs.MFUser {
return resUser
}
// FillMFChatUser 填充聊天信息
func (p *Player) FillMFChatUser() *cs.MFChatUser {
accountId := p.accountId
profile := cacheMgr.GetPlayerProfile(accountId)
if profile == nil {
return nil
}
var guildId int64 = 0
var guildName = ""
var guildLevel int32 = 0
guild := guildMgr.GetGuildByAccountId(profile.AccountId)
if guild != nil {
guildId = guild.GuildId
guildName = guild.Name
guildLevel = guild.GetMemberLevel(accountId)
}
onlineStatus := playerMgr.GetOnlineStatus(profile.AccountId)
res := &cs.MFChatUser{
AccountId: &profile.AccountId,
Username: &profile.Username,
Avatar: &profile.Avatar,
AvatarHead: &profile.AvatarHead,
GuildId: &guildId,
GuildName: &guildName,
GuildLevel: &guildLevel,
OnlineStatus: &onlineStatus,
LastLoginTime: &profile.LastLoginTime,
}
return res
}
func (p *Player) IncrPrivateChatLastId() uint64 {
p.privateChatLastId++
return p.privateChatLastId

View File

@ -137,9 +137,11 @@ func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.Htt
cacheMgr.AddCacheProfile(1, playerProfile)
friendMgr.LoadUser(accountId)
serverInfo := "192.168.100.39:2000"
serverInfo := proto.String(mt.Table.IMCluster.GetServerInfo())
f5.GetSysLog().Info("ServerInfo:%s", serverInfo)
rspMsg := &cs.SMLogin{}
rspMsg.ServerInfo = &serverInfo
rspMsg.ServerInfo = serverInfo
rspMsg.AccountId = &resObj.Info.AccountID
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
}
@ -148,7 +150,7 @@ func (this *PlayerMgr) reportServerState(masterIp string, masterPort int32) {
params := map[string]string{
"node_id": q5.ToString(f5.GetApp().GetNodeId()),
"instance_id": q5.ToString(f5.GetApp().GetInstanceId()),
"ip": "192.168.100.164",
"ip": mt.Table.IMCluster.GetIp(),
"port": q5.ToString(mt.Table.IMCluster.GetListenPort()),
"online_num": q5.ToString(0),
"room_num": q5.ToString(0),
@ -211,7 +213,7 @@ func (this *PlayerMgr) CMReconnect(hdr *f5.MsgHdr, msg *cs.CMReconnect) {
}
if hum.GetSessionId() != msg.GetSessionId() {
rspMsg.Errcode = proto.Int32(ERR_CODE_RECONNECT_PLAYER_SESSION_ID_NO_VALID)
rspMsg.Errmsg = proto.String("session id no valid")
rspMsg.Errmsg = proto.String("session_id no valid")
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
return
}

View File

@ -351,14 +351,27 @@ message MFChatMsg
!!!msg_uuid可能重复
*/
optional uint64 msg_uuid = 1;
optional string sender = 2; //
optional string receiver = 3; //
optional MFChatUser sender = 2; //
optional MFChatUser receiver = 3; //
optional int32 chat_channel = 4; //
optional int32 msg_type = 5; // 0(json) 1 (json) 2:()
optional string msg_body = 6; //(json类型里的字段!)
optional int64 send_time = 7; //
}
//
message MFChatUser{
optional string account_id = 1;
optional string username = 2;
optional int32 avatar = 3;
optional int32 avatar_head = 4;
optional int64 guild_id = 5;
optional string guild_name = 6;
optional int32 guild_level = 7;
optional int32 online_status = 8;
optional int32 last_login_time = 9;
}
// --- ---
//
message CMGuildInfo
@ -675,4 +688,4 @@ message MFGuildMember {
optional int32 last_login_time = 9;
optional int32 level = 10;
optional int32 star = 11;
}
}