聊天
This commit is contained in:
parent
095deb582b
commit
f924d4e880
@ -39,11 +39,11 @@ func NewChatMgr(pm *PlayerMgr, fm *FriendsMgr, gm *GuildMgr) *ChatMgr {
|
|||||||
|
|
||||||
func (cm *ChatMgr) init() {}
|
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) {
|
msgAutoId uint64, chatChannel int32, msgType int32, msgBody *string) {
|
||||||
|
|
||||||
msg.MsgUuid = &msgAutoId
|
msg.MsgUuid = &msgAutoId
|
||||||
msg.Sender = accountId
|
msg.Sender = sender.FillMFChatUser()
|
||||||
msg.ChatChannel = &chatChannel
|
msg.ChatChannel = &chatChannel
|
||||||
msg.MsgType = &msgType
|
msg.MsgType = &msgType
|
||||||
msg.MsgBody = msgBody
|
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) {
|
func (cm *ChatMgr) ProcWorldChat(p *Player, msg *cs.CMSendChatMsg) {
|
||||||
accountId := p.GetAccountId()
|
|
||||||
chatMsg := new(cs.MFChatMsg)
|
chatMsg := new(cs.MFChatMsg)
|
||||||
cm.worldMsgId++
|
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.CurrID = cm.worldMsgId
|
||||||
cm.worldMsgRec.AddChatMsg(chatMsg)
|
cm.worldMsgRec.AddChatMsg(chatMsg)
|
||||||
@ -114,7 +113,7 @@ func (cm *ChatMgr) ProcGuildChat(p *Player, msg *cs.CMSendChatMsg) {
|
|||||||
cm.guildMsgId++
|
cm.guildMsgId++
|
||||||
|
|
||||||
chatMsg := new(cs.MFChatMsg)
|
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 {
|
if msgRec, exists := cm.guildMsgRec[guildId]; exists {
|
||||||
msgRec.AddChatMsg(chatMsg)
|
msgRec.AddChatMsg(chatMsg)
|
||||||
@ -138,6 +137,7 @@ func (cm *ChatMgr) ProcPrivateChat(p *Player, msg *cs.CMSendChatMsg) {
|
|||||||
if p.accountId == targetAccountId {
|
if p.accountId == targetAccountId {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确定是否好友
|
// 确定是否好友
|
||||||
targetAccount := cm.fm.GetFriendByAccountId(p.accountId, targetAccountId)
|
targetAccount := cm.fm.GetFriendByAccountId(p.accountId, targetAccountId)
|
||||||
if targetAccount == nil {
|
if targetAccount == nil {
|
||||||
@ -145,7 +145,7 @@ func (cm *ChatMgr) ProcPrivateChat(p *Player, msg *cs.CMSendChatMsg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chatMsg := new(cs.MFChatMsg)
|
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.AddChatUser(p.accountId, msg.GetTargetAccountId(), chatMsg, p.IncrPrivateChatLastId())
|
||||||
cm.SyncPrivateChatMsg(p)
|
cm.SyncPrivateChatMsg(p)
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -56,14 +56,6 @@ func (g *Guild) GetMembersViceLeaderCount() int {
|
|||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMember 根据 AccountId 获取成员信息
|
|
||||||
func (g *Guild) GetMember(accountId string) *GuildMember {
|
|
||||||
if member, exists := g.Members[accountId]; exists {
|
|
||||||
return member
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsMember 是否是公会成员
|
// IsMember 是否是公会成员
|
||||||
func (g *Guild) IsMember(accountId string) bool {
|
func (g *Guild) IsMember(accountId string) bool {
|
||||||
_, exists := g.Members[accountId]
|
_, exists := g.Members[accountId]
|
||||||
@ -86,6 +78,22 @@ func (g *Guild) RemoveMember(accountId string) {
|
|||||||
delete(g.Members, accountId)
|
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) {
|
func (g *Guild) SetNotice(notice *string) {
|
||||||
g.Notice = *notice
|
g.Notice = *notice
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,12 @@ func (this *HandlerMgr) init() {
|
|||||||
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetAvatar), PLAYER_HANDLER_ID)
|
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetAvatar), PLAYER_HANDLER_ID)
|
||||||
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetJoinCond), 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__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() {
|
func (this *HandlerMgr) unInit() {
|
||||||
|
@ -3,6 +3,7 @@ package mt
|
|||||||
import (
|
import (
|
||||||
"f5"
|
"f5"
|
||||||
"mtb"
|
"mtb"
|
||||||
|
"q5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IMCluster struct {
|
type IMCluster struct {
|
||||||
@ -12,12 +13,17 @@ type IMCluster struct {
|
|||||||
type IMClusterTable struct {
|
type IMClusterTable struct {
|
||||||
f5.IdMetaTable[IMCluster]
|
f5.IdMetaTable[IMCluster]
|
||||||
selfConf *IMCluster
|
selfConf *IMCluster
|
||||||
|
serverInfo string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *IMCluster) Init1() {
|
func (this *IMCluster) Init1() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *IMClusterTable) GetIp() string {
|
||||||
|
return q5.GetLocalIP()
|
||||||
|
}
|
||||||
|
|
||||||
func (this *IMClusterTable) GetListenPort() int32 {
|
func (this *IMClusterTable) GetListenPort() int32 {
|
||||||
return this.selfConf.GetListenPort()
|
return this.selfConf.GetListenPort()
|
||||||
}
|
}
|
||||||
@ -31,4 +37,9 @@ func (this *IMClusterTable) PostInit1() {
|
|||||||
if this.selfConf == nil {
|
if this.selfConf == nil {
|
||||||
panic("imserver集群无法读取本服配置")
|
panic("imserver集群无法读取本服配置")
|
||||||
}
|
}
|
||||||
|
this.serverInfo = this.GetIp() + ":" + q5.ToString(this.GetListenPort())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IMClusterTable) GetServerInfo() string {
|
||||||
|
return this.serverInfo
|
||||||
}
|
}
|
||||||
|
@ -246,11 +246,11 @@ func (p *Player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) {
|
|||||||
|
|
||||||
// CMSendChatMsg 发送聊天消息
|
// CMSendChatMsg 发送聊天消息
|
||||||
func (p *Player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) {
|
func (p *Player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) {
|
||||||
chatChannel := *msg.ChatChannel
|
// p.chatChannel := *msg.ChatChannel
|
||||||
if !IsValidChatChannel(chatChannel) {
|
if !IsValidChatChannel(msg.GetChatChannel()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch chatChannel {
|
switch msg.GetChatChannel() {
|
||||||
case kCCWorld:
|
case kCCWorld:
|
||||||
chatMgr.ProcWorldChat(p, msg)
|
chatMgr.ProcWorldChat(p, msg)
|
||||||
case kCCPrivate:
|
case kCCPrivate:
|
||||||
@ -270,11 +270,11 @@ func (p *Player) SyncPrivateChatRedPoint() {
|
|||||||
|
|
||||||
// CMReadMsgAndOpenChatNotify 读取聊天消息列表并且开启聊天通知
|
// CMReadMsgAndOpenChatNotify 读取聊天消息列表并且开启聊天通知
|
||||||
func (p *Player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAndOpenChatNotify) {
|
func (p *Player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAndOpenChatNotify) {
|
||||||
chatChannel := *msg.CurrChannel
|
if !IsValidChatChannel(msg.GetCurrChannel()) {
|
||||||
if !IsValidChatChannel(chatChannel) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if chatChannel == kCCPrivate {
|
p.chatChannel = int(msg.GetCurrChannel())
|
||||||
|
if p.chatChannel == kCCPrivate {
|
||||||
p.SyncPrivateChatRedPoint()
|
p.SyncPrivateChatRedPoint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -779,6 +779,39 @@ func (p *Player) FillMFUser(profile *PlayerProfile) *cs.MFUser {
|
|||||||
return resUser
|
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 {
|
func (p *Player) IncrPrivateChatLastId() uint64 {
|
||||||
p.privateChatLastId++
|
p.privateChatLastId++
|
||||||
return p.privateChatLastId
|
return p.privateChatLastId
|
||||||
|
@ -137,9 +137,11 @@ func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.Htt
|
|||||||
cacheMgr.AddCacheProfile(1, playerProfile)
|
cacheMgr.AddCacheProfile(1, playerProfile)
|
||||||
friendMgr.LoadUser(accountId)
|
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 := &cs.SMLogin{}
|
||||||
rspMsg.ServerInfo = &serverInfo
|
rspMsg.ServerInfo = serverInfo
|
||||||
rspMsg.AccountId = &resObj.Info.AccountID
|
rspMsg.AccountId = &resObj.Info.AccountID
|
||||||
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||||
}
|
}
|
||||||
@ -148,7 +150,7 @@ func (this *PlayerMgr) reportServerState(masterIp string, masterPort int32) {
|
|||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
"node_id": q5.ToString(f5.GetApp().GetNodeId()),
|
"node_id": q5.ToString(f5.GetApp().GetNodeId()),
|
||||||
"instance_id": q5.ToString(f5.GetApp().GetInstanceId()),
|
"instance_id": q5.ToString(f5.GetApp().GetInstanceId()),
|
||||||
"ip": "192.168.100.164",
|
"ip": mt.Table.IMCluster.GetIp(),
|
||||||
"port": q5.ToString(mt.Table.IMCluster.GetListenPort()),
|
"port": q5.ToString(mt.Table.IMCluster.GetListenPort()),
|
||||||
"online_num": q5.ToString(0),
|
"online_num": q5.ToString(0),
|
||||||
"room_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() {
|
if hum.GetSessionId() != msg.GetSessionId() {
|
||||||
rspMsg.Errcode = proto.Int32(ERR_CODE_RECONNECT_PLAYER_SESSION_ID_NO_VALID)
|
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)
|
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -351,14 +351,27 @@ message MFChatMsg
|
|||||||
!!!不同的频道msg_uuid可能重复
|
!!!不同的频道msg_uuid可能重复
|
||||||
*/
|
*/
|
||||||
optional uint64 msg_uuid = 1;
|
optional uint64 msg_uuid = 1;
|
||||||
optional string sender = 2; //发送者
|
optional MFChatUser sender = 2; //发送者
|
||||||
optional string receiver = 3; //接收者
|
optional MFChatUser receiver = 3; //接收者
|
||||||
optional int32 chat_channel = 4; //聊天频道
|
optional int32 chat_channel = 4; //聊天频道
|
||||||
optional int32 msg_type = 5; //消息类型 0:文本消息(json) 1:自定义协议 (json) 2:纯文本(但是任会做屏蔽字替换)
|
optional int32 msg_type = 5; //消息类型 0:文本消息(json) 1:自定义协议 (json) 2:纯文本(但是任会做屏蔽字替换)
|
||||||
optional string msg_body = 6; //消息内容(json类型里的字段!开头的会做屏蔽替换)
|
optional string msg_body = 6; //消息内容(json类型里的字段!开头的会做屏蔽替换)
|
||||||
optional int64 send_time = 7; //消息发送时间
|
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
|
message CMGuildInfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user