diff --git a/server/imserver_new/common/types.go b/server/imserver_new/common/types.go index 4435391d..8d46c494 100644 --- a/server/imserver_new/common/types.go +++ b/server/imserver_new/common/types.go @@ -48,15 +48,38 @@ type PlayerMgr interface { GetOnlineStatus(string) int32 OnSocketClose(f5.WspCliConn) GetPlayers() map[string]Player + UnBindSocket(f5.WspCliConn) + BindSocket(f5.WspCliConn, Player) +} + +type Friendship interface { + IsFriendship() int32 + FriendAccountId() string +} + +type FriendBlackList interface { + GetAccountId() string + IsRemoved() int32 } type User interface { + GetFriendships() map[string]Friendship + GetFriendBlackList() map[string]FriendBlackList } type FriendMgr interface { GetFriendByAccountId(account1Id, account2Id string) User AddUser(string, User) + GetUser(string) User LoadUserFriendships(user User, where [][]string) + SearchUsers(accountId, username string, sinceId int64, cb func(errCode int32, errMsg string, lastId int64, listFriend []*PlayerProfile)) + SearchByAccountId(accountId string, cb func(errCode int32, errMsg string, playerProfile *PlayerProfile)) + AddFriendRequest(account1Id string, account2Id string, cb func(errCode int32, errMsg string)) + AcceptFriendRequest(account1Id string, account2Id string, cb func(errCode int32, errMsg string)) + RejectFriendRequest(account1Id string, account2Id string, cb func(errCode int32, errMsg string)) + DeleteFriendShip(account1Id, account2Id string, cb func(errCode int32, errMsg string)) + AddBlacklist(account1Id string, account2Id string, cb func(errCode int32, errMsg string)) + RemoveBlacklist(account1Id string, account2Id string, cb func(errCode int32, errMsg string)) } type Guild interface { @@ -77,6 +100,19 @@ type CacheMgr interface { GetProfileByAccountId(accountId string, cb func(err error, profile *PlayerProfile)) GetPlayerProfile(accountId string) *PlayerProfile LoadUserProfile(string) + AsyncGetUsers(accountIds []string, cb func(bool)) +} + +type ChatMgr interface { + ProcWorldChat(p Player, msg *cs.CMSendChatMsg) + ProcGuildChat(p Player, msg *cs.CMSendChatMsg) + ProcTeamChat(p Player, msg *cs.CMSendChatMsg) + ProcPrivateChat(p Player, msg *cs.CMSendChatMsg) + FillSMUpdateChatRedPointNotify(p Player, msg *cs.SMUpdateChatRedPointNotify) + FillSMUpdatePrivateChatRedPointNotify(p Player, msg *cs.SMUpdatePrivateChatRedPointNotify) + SyncWorldChatMsg(p Player) + SyncGuildChatMsg(p Player) + SyncPrivateChatMsg(p Player) } type PlayerProfile struct { diff --git a/server/imserver_new/friend/friends.go b/server/imserver_new/friend/friends.go index 3ceb7bcc..52bb9955 100644 --- a/server/imserver_new/friend/friends.go +++ b/server/imserver_new/friend/friends.go @@ -2,6 +2,7 @@ package friend import ( "main/constant" + "main/common" ) type User struct { @@ -32,6 +33,14 @@ func NewUser(accountId string) *User { return user } +func (u *User) GetFriendships() map[string]common.Friendship { + return nil +} + +func (u *User) GetFriendBlackList() map[string]common.FriendBlackList { + return nil +} + func (u *User) AddFriendRequest(account2Id string, IsFriendship int32, requestTime int64) { friendShip := &Friendship{ FriendAccountId: account2Id, diff --git a/server/imserver_new/global/global.go b/server/imserver_new/global/global.go index 98e31e3f..12f0b922 100644 --- a/server/imserver_new/global/global.go +++ b/server/imserver_new/global/global.go @@ -22,6 +22,7 @@ var wspListener common.WspListener var friendMgr common.FriendMgr var guildMgr common.GuildMgr var cacheMgr common.CacheMgr +var chatMgr common.ChatMgr func GetPlayerMgr() common.PlayerMgr { return playerMgr @@ -39,6 +40,10 @@ func GetCacheMgr() common.CacheMgr { return cacheMgr } +func GetChatMgr() common.ChatMgr { + return chatMgr +} + func GetWspListener() common.WspListener { return wspListener } diff --git a/server/imserver_new/player/player.go b/server/imserver_new/player/player.go index 4387bb5a..99f1e97e 100644 --- a/server/imserver_new/player/player.go +++ b/server/imserver_new/player/player.go @@ -7,6 +7,7 @@ import ( "q5" "sort" "main/constant" + "main/common" . "main/global" ) @@ -30,27 +31,79 @@ func (p *Player) GetSessionId() string { return p.sessionId } +func (this *Player) GetAvatarUrl() string { + return "" +} + +func (this *Player) GetName() string { + return "" +} + +func (this *Player) GetHeroId() string { + return "" +} + +func (this *Player) GetPing() int32 { + return 0 +} + +func (this *Player) GetHeadFrame() string { + return "" +} + +func (this *Player) GetPrivateTargetAccountId() string { + return "" +} + +func (this *Player) IncrPrivateChatLastId() int64 { + return 0 +} + +func (this *Player) IsOnline() bool { + return true +} + +func (this *Player) SetGuildChannelLastId(int64) { + +} + +func (this *Player) SetWorldChannelLastId(int64) { + +} + +func (this *Player) GetChatChannel() int32 { + return 0 +} + +func (this *Player)GetWorldChannelLastId() int64 { + return 0 +} + +func (this* Player) GetGuildChannelLastId() int64 { + return 0 +} + func (p *Player) SendMsg(rspMsg proto.Message) { GetWspListener().SendProxyMsg(p.socket.Conn, p.socket.SocketHandle, rspMsg) } func (p *Player) ReBind(socket f5.WspCliConn) { if p.socket.IsValid() { - delete(playerMgr.socketHash, p.socket) + GetPlayerMgr().UnBindSocket(p.socket) } p.socket = socket - playerMgr.socketHash[p.socket] = p + GetPlayerMgr().BindSocket(socket, p) } // CMSearchUser 搜索用户 func (p *Player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) { sinceId := msg.GetSinceId() searchUsername := msg.GetUsername() - friendMgr.SearchUsers( + GetFriendMgr().SearchUsers( p.accountId, searchUsername, sinceId, - func(errCode int32, errMsg string, lastId int64, listFriend []*PlayerProfile) { + func(errCode int32, errMsg string, lastId int64, listFriend []*common.PlayerProfile) { f5.GetSysLog().Info("CMSearchUser username:[%s], count:%d, \n", searchUsername, len(listFriend)) rspMsg := new(cs.SMSearchUser) if errCode != 0 { @@ -69,8 +122,8 @@ func (p *Player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) { // CMSearchUserByAccountId 搜索指定用户 func (p *Player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByAccountId) { - friendMgr.SearchByAccountId(msg.GetAccountId(), - func(errCode int32, errMsg string, playerProfile *PlayerProfile) { + GetFriendMgr().SearchByAccountId(msg.GetAccountId(), + func(errCode int32, errMsg string, playerProfile *common.PlayerProfile) { rspMsg := new(cs.SMSearchUserByAccountId) if errCode != 0 { rspMsg.Errcode = &errCode @@ -87,14 +140,14 @@ func (p *Player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByA // CMListPendingFriendRequest 等待验证的好友请求 func (p *Player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendingFriendRequest) { accountId := p.accountId - user := friendMgr.GetUser(accountId) + user := GetFriendMgr().GetUser(accountId) rspMsg := &cs.SMListPendingFriendRequest{} - for targetAccountId, friendRequest := range user.Friendships { - if friendRequest.IsFriendship != constant.FriendshipStatusPending { + for targetAccountId, friendRequest := range user.GetFriendships() { + if friendRequest.IsFriendship() != constant.FriendshipStatusPending { continue } - profile := cacheMgr.GetPlayerProfile(targetAccountId) + profile := GetCacheMgr().GetPlayerProfile(targetAccountId) if profile == nil { continue } @@ -109,24 +162,24 @@ func (p *Player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendin // CMListFriend 我的好友列表 func (p *Player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) { accountId := p.accountId - user := friendMgr.GetUser(accountId) + user := GetFriendMgr().GetUser(accountId) var friendIds []string - for _, friendship := range user.Friendships { - if friendship.FriendAccountId == accountId || friendship.IsFriendship != constant.FriendshipStatusOK { + for _, friendship := range user.GetFriendships() { + if friendship.FriendAccountId() == accountId || friendship.IsFriendship() != constant.FriendshipStatusOK { continue } - friendIds = append(friendIds, friendship.FriendAccountId) + friendIds = append(friendIds, friendship.FriendAccountId()) } rspMsg := &cs.SMListFriend{} rspMsg.Users = make([]*cs.MFUser, len(friendIds)) - cacheMgr.AsyncGetUsers(friendIds, func(ok bool) { + GetCacheMgr().AsyncGetUsers(friendIds, func(ok bool) { if !ok { return } for _, fid := range friendIds { - userProfile := cacheMgr.GetPlayerProfile(fid) + userProfile := GetCacheMgr().GetPlayerProfile(fid) rspUser := p.FillMFUser(userProfile) rspMsg.Users = append(rspMsg.Users, rspUser) } @@ -138,12 +191,12 @@ func (p *Player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) { func (p *Player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) { rspMsg := &cs.SMBlacklist{} accountId := p.accountId - player := friendMgr.GetUser(accountId) - for _, blackList := range player.FriendBlackList { - if blackList.IsRemoved != 0 { + player := GetFriendMgr().GetUser(accountId) + for _, blackList := range player.GetFriendBlackList() { + if blackList.IsRemoved() != 0 { continue } - blockedPlayerProfile := cacheMgr.GetPlayerProfile(blackList.AccountId) + blockedPlayerProfile := GetCacheMgr().GetPlayerProfile(blackList.GetAccountId()) if blockedPlayerProfile == nil { continue } @@ -157,7 +210,7 @@ func (p *Player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) { func (p *Player) CMAddFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAddFriendRequest) { user1Id := p.accountId user2Id := msg.GetTargetAccountId() - friendMgr.AddFriendRequest(user1Id, user2Id, + GetFriendMgr().AddFriendRequest(user1Id, user2Id, func(errCode int32, errMsg string) { rspMsg := new(cs.SMAddFriendRequest) if errCode != 0 { @@ -173,7 +226,7 @@ func (p *Player) CMAddFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAddFriendRequest) func (p *Player) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAcceptFriendRequest) { user1Id := p.accountId user2Id := msg.GetTargetAccountId() - friendMgr.AcceptFriendRequest(user1Id, user2Id, + GetFriendMgr().AcceptFriendRequest(user1Id, user2Id, func(errCode int32, errMsg string) { rspMsg := new(cs.SMAcceptFriendRequest) if errCode != 0 { @@ -189,7 +242,7 @@ func (p *Player) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAcceptFriendReq func (p *Player) CMRejectFriendRequest(hdr *f5.MsgHdr, msg *cs.CMRejectFriendRequest) { user1Id := p.accountId user2Id := msg.GetTargetAccountId() - friendMgr.RejectFriendRequest(user1Id, user2Id, + GetFriendMgr().RejectFriendRequest(user1Id, user2Id, func(errCode int32, errMsg string) { rspMsg := new(cs.SMRejectFriendRequest) if errCode != 0 { @@ -205,7 +258,7 @@ func (p *Player) CMRejectFriendRequest(hdr *f5.MsgHdr, msg *cs.CMRejectFriendReq func (p *Player) CMDeleteFriendShip(hdr *f5.MsgHdr, msg *cs.CMDeleteFriendShip) { user1Id := p.accountId user2Id := msg.GetTargetAccountId() - friendMgr.DeleteFriendShip(user1Id, user2Id, + GetFriendMgr().DeleteFriendShip(user1Id, user2Id, func(errCode int32, errMsg string) { rspMsg := new(cs.SMDeleteFriendShip) rspMsg.Errcode = &errCode @@ -218,7 +271,7 @@ func (p *Player) CMDeleteFriendShip(hdr *f5.MsgHdr, msg *cs.CMDeleteFriendShip) func (p *Player) CMAddBlacklist(hdr *f5.MsgHdr, msg *cs.CMAddBlacklist) { user1Id := p.accountId user2Id := msg.GetTargetAccountId() - friendMgr.AddBlacklist(user1Id, user2Id, + GetFriendMgr().AddBlacklist(user1Id, user2Id, func(errCode int32, errMsg string) { rspMsg := new(cs.SMAddBlacklist) if errCode != 0 { @@ -234,7 +287,7 @@ func (p *Player) CMAddBlacklist(hdr *f5.MsgHdr, msg *cs.CMAddBlacklist) { func (p *Player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) { user1Id := p.accountId user2Id := msg.GetTargetAccountId() - friendMgr.RemoveBlacklist(user1Id, user2Id, + GetFriendMgr().RemoveBlacklist(user1Id, user2Id, func(errCode int32, errMsg string) { rspMsg := new(cs.SMRemoveBlacklist) if errCode != 0 { @@ -249,7 +302,7 @@ func (p *Player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) { // CMInviteFriendMsg 邀请好友加入队伍 func (p *Player) CMInviteFriendMsg(hdr *f5.MsgHdr, msg *cs.CMInviteFriendMsg) { rspMsg := new(cs.SMInviteFriendMsg) - p2 := playerMgr.GetPlayerByAccountId(msg.GetInviteAccountId()) + p2 := GetPlayerMgr().GetPlayerByAccountId(msg.GetInviteAccountId()) if p2 == nil { rspMsg.Errcode = proto.Int32(constant.ERR_CODE_FRIEND_NO_EXISTS) rspMsg.Errmsg = proto.String("friend no exists") @@ -268,13 +321,13 @@ func (p *Player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) { switch msg.GetChatChannel() { case constant.CCWorld: - chatMgr.ProcWorldChat(p, msg) + GetChatMgr().ProcWorldChat(p, msg) case constant.CCPrivate: - chatMgr.ProcPrivateChat(p, msg) + GetChatMgr().ProcPrivateChat(p, msg) case constant.CCGuild: - chatMgr.ProcGuildChat(p, msg) + GetChatMgr().ProcGuildChat(p, msg) case constant.CCTeam: - chatMgr.ProcTeamChat(p, msg) + GetChatMgr().ProcTeamChat(p, msg) default: return } @@ -282,7 +335,7 @@ func (p *Player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) { func (p *Player) SyncPrivateChatRedPoint() { msg := &cs.SMUpdatePrivateChatRedPointNotify{} - chatMgr.FillSMUpdatePrivateChatRedPointNotify(p, msg) + GetChatMgr().FillSMUpdatePrivateChatRedPointNotify(p, msg) } // CMReadMsgAndOpenChatNotify 读取聊天消息列表并且开启聊天通知 @@ -305,10 +358,10 @@ func (p *Player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAnd switch chatChannel { case constant.CCWorld: p.worldChannelLastId = chatChannelLastId - chatMgr.SyncWorldChatMsg(p) + GetChatMgr().SyncWorldChatMsg(p) case constant.CCGuild: p.guildChannelLastId = chatChannelLastId - chatMgr.SyncGuildChatMsg(p) + GetChatMgr().SyncGuildChatMsg(p) default: break } @@ -318,12 +371,12 @@ func (p *Player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAnd // CMSetCurrPrivateChatTarget 设置当前私聊目标 func (p *Player) CMSetCurrPrivateChatTarget(hdr *f5.MsgHdr, msg *cs.CMSetCurrPrivateChatTarget) { p.privateTargetAccountId = msg.GetTargetAccountId() - chatMgr.SyncPrivateChatMsg(p) + GetChatMgr().SyncPrivateChatMsg(p) } func (p *Player) MarkNewMsg() { rspMsg := &cs.SMUpdateChatRedPointNotify{} - chatMgr.FillSMUpdateChatRedPointNotify(p, rspMsg) + GetChatMgr().FillSMUpdateChatRedPointNotify(p, rspMsg) p.SendMsg(rspMsg) } @@ -338,7 +391,7 @@ func (p *Player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) { accountId = msg.GetAccountId() } rspMsg := new(cs.SMGuildInfo) - guild := guildMgr.GetGuildByAccountId(accountId) + guild := GetGuildMgr().GetGuildByAccountId(accountId) if guild != nil { rspMsg.Guild = p.FillMFGuild(guild) } @@ -348,7 +401,7 @@ func (p *Player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) { // CMRecommendGuildList 推荐公会列表 func (p *Player) CMRecommendGuildList(hdr *f5.MsgHdr, msg *cs.CMRecommendGuildList) { rspMsg := new(cs.SMRecommendGuildList) - rspMsg.RecommendGuilds = p.FillMFGuilds(guildMgr.RandomGuilds()) + rspMsg.RecommendGuilds = p.FillMFGuilds(GetGuildMgr().RandomGuilds()) p.SendMsg(rspMsg) }