添加注释

This commit is contained in:
sk 2024-11-27 16:31:47 +08:00
parent a8d78d5480
commit 794880b644
10 changed files with 100 additions and 81 deletions

View File

@ -65,15 +65,15 @@ func CSChatMsgHandler(s *netlib.Session, packetid int, data interface{}, sid int
} else { //私聊 } else { //私聊
FriendUnreadMgrSington.DelFriendUnread(p.Platform, p.SnId, msg.GetMsg2Snid()) FriendUnreadMgrSington.DelFriendUnread(p.Platform, p.SnId, msg.GetMsg2Snid())
pack.Content = content pack.Content = content
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, msg.GetMsg2Snid()) { if !FriendMgrSingleton.IsFriend(p.Platform, p.SnId, msg.GetMsg2Snid()) {
pack.OpRetCode = chat.OpResultCode_OPRC_Chat_NotFriend pack.OpRetCode = chat.OpResultCode_OPRC_Chat_NotFriend
logger.Logger.Warn("CSChatMsgHandler not friend") logger.Logger.Warn("CSChatMsgHandler not friend")
} else { } else {
if FriendMgrSington.IsShield(p.Platform, msg.GetMsg2Snid(), p.SnId) { //对方有没有屏蔽发送者 if FriendMgrSingleton.IsShield(p.Platform, msg.GetMsg2Snid(), p.SnId) { //对方有没有屏蔽发送者
pack.OpRetCode = chat.OpResultCode_OPRC_Chat_IsShield pack.OpRetCode = chat.OpResultCode_OPRC_Chat_IsShield
logger.Logger.Warn("CSChatMsgHandler IsShield") logger.Logger.Warn("CSChatMsgHandler IsShield")
} }
if FriendMgrSington.IsShield(p.Platform, p.SnId, msg.GetMsg2Snid()) { //有没有屏蔽对方 if FriendMgrSingleton.IsShield(p.Platform, p.SnId, msg.GetMsg2Snid()) { //有没有屏蔽对方
pack.OpRetCode = chat.OpResultCode_OPRC_Chat_Shield pack.OpRetCode = chat.OpResultCode_OPRC_Chat_Shield
logger.Logger.Warn("CSChatMsgHandler Shield") logger.Logger.Warn("CSChatMsgHandler Shield")
} }
@ -117,11 +117,11 @@ func CSGetChatLogHandler(s *netlib.Session, packetid int, data interface{}, sid
logger.Logger.Warn("CSGetChatLogHandler platform == nil") logger.Logger.Warn("CSGetChatLogHandler platform == nil")
return nil return nil
} }
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, msg.GetSnid()) { if !FriendMgrSingleton.IsFriend(p.Platform, p.SnId, msg.GetSnid()) {
logger.Logger.Warn("CSGetChatLogHandler not friend") logger.Logger.Warn("CSGetChatLogHandler not friend")
return nil return nil
} }
friendInfo := FriendMgrSington.GetFriendList(p.Platform, p.SnId) friendInfo := FriendMgrSingleton.GetFriendList(p.Platform, p.SnId)
var bf *model.BindFriend var bf *model.BindFriend
if friendInfo != nil && len(friendInfo) != 0 { if friendInfo != nil && len(friendInfo) != 0 {
for _, friend := range friendInfo { for _, friend := range friendInfo {
@ -275,7 +275,7 @@ func CSReadChatMsgHandler(s *netlib.Session, packetid int, data interface{}, sid
logger.Logger.Warn("CSReadChatMsgHandler platform == nil") logger.Logger.Warn("CSReadChatMsgHandler platform == nil")
return nil return nil
} }
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, msg.GetSnid()) { if !FriendMgrSingleton.IsFriend(p.Platform, p.SnId, msg.GetSnid()) {
logger.Logger.Warn("CSReadChatMsgHandler not friend") logger.Logger.Warn("CSReadChatMsgHandler not friend")
return nil return nil
} }
@ -307,21 +307,21 @@ func CSShieldMsgHandler(s *netlib.Session, packetid int, data interface{}, sid i
OpRetCode: chat.OpResultCode_OPRC_Sucess, OpRetCode: chat.OpResultCode_OPRC_Sucess,
} }
if msg.GetShield() { if msg.GetShield() {
if FriendMgrSington.IsShield(p.Platform, p.SnId, msg.GetShieldSnid()) { if FriendMgrSingleton.IsShield(p.Platform, p.SnId, msg.GetShieldSnid()) {
logger.Logger.Warn("重复屏蔽") logger.Logger.Warn("重复屏蔽")
pack.OpRetCode = chat.OpResultCode_OPRC_Chat_ReShield pack.OpRetCode = chat.OpResultCode_OPRC_Chat_ReShield
} }
} else { } else {
if !FriendMgrSington.IsShield(p.Platform, p.SnId, msg.GetShieldSnid()) { if !FriendMgrSingleton.IsShield(p.Platform, p.SnId, msg.GetShieldSnid()) {
logger.Logger.Warn("重复解除") logger.Logger.Warn("重复解除")
pack.OpRetCode = chat.OpResultCode_OPRC_Chat_ReUnShield pack.OpRetCode = chat.OpResultCode_OPRC_Chat_ReUnShield
} }
} }
if pack.OpRetCode == chat.OpResultCode_OPRC_Sucess { if pack.OpRetCode == chat.OpResultCode_OPRC_Sucess {
if msg.GetShield() { if msg.GetShield() {
FriendMgrSington.AddShield(p.Platform, p.SnId, msg.GetShieldSnid()) FriendMgrSingleton.AddShield(p.Platform, p.SnId, msg.GetShieldSnid())
} else { } else {
FriendMgrSington.DelShield(p.Platform, p.SnId, msg.GetShieldSnid()) FriendMgrSingleton.DelShield(p.Platform, p.SnId, msg.GetShieldSnid())
} }
} }
proto.SetDefaults(pack) proto.SetDefaults(pack)

View File

@ -46,8 +46,8 @@ func (this *CSFriendListHandler) Process(s *netlib.Session, packetid int, data i
OpRetCode: friend.OpResultCode_OPRC_Sucess, OpRetCode: friend.OpResultCode_OPRC_Sucess,
} }
switch msg.GetListType() { switch msg.GetListType() {
case ListType_Friend: case ListTypeFriend:
dfl := FriendMgrSington.GetFriendList(p.Platform, p.GetSnId()) dfl := FriendMgrSingleton.GetFriendList(p.Platform, p.GetSnId())
if dfl != nil { if dfl != nil {
for _, bf := range dfl { for _, bf := range dfl {
if bf.SnId == p.SnId { if bf.SnId == p.SnId {
@ -62,7 +62,7 @@ func (this *CSFriendListHandler) Process(s *netlib.Session, packetid int, data i
CreateTs: proto.Int64(bf.CreateTime), CreateTs: proto.Int64(bf.CreateTime),
LogoutTs: proto.Int64(bf.LogoutTime), LogoutTs: proto.Int64(bf.LogoutTime),
LastChatTs: proto.Int64(bf.CreateTime), LastChatTs: proto.Int64(bf.CreateTime),
IsShield: proto.Bool(FriendMgrSington.IsShield(p.Platform, p.SnId, bf.SnId)), IsShield: proto.Bool(FriendMgrSingleton.IsShield(p.Platform, p.SnId, bf.SnId)),
RoleId: bf.RoleId, RoleId: bf.RoleId,
} }
fi.Online = false fi.Online = false
@ -80,7 +80,7 @@ func (this *CSFriendListHandler) Process(s *netlib.Session, packetid int, data i
proto.SetDefaults(pack) proto.SetDefaults(pack)
p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendList), pack) p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendList), pack)
logger.Logger.Trace("SCFriendListHandler:", pack) logger.Logger.Trace("SCFriendListHandler:", pack)
case ListType_Apply: case ListTypeApply:
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
ret, err := model.QueryFriendApplyBySnid(p.Platform, p.SnId) ret, err := model.QueryFriendApplyBySnid(p.Platform, p.SnId)
if err != nil { if err != nil {
@ -113,7 +113,7 @@ func (this *CSFriendListHandler) Process(s *netlib.Session, packetid int, data i
p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendList), pack) p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendList), pack)
logger.Logger.Trace("SCFriendListHandler: ", pack) logger.Logger.Trace("SCFriendListHandler: ", pack)
})).Start() })).Start()
case ListType_Recommend: case ListTypeRecommend:
friends := PlayerMgrSington.RecommendFriendRule(p.Platform, p.SnId) friends := PlayerMgrSington.RecommendFriendRule(p.Platform, p.SnId)
for _, f := range friends { for _, f := range friends {
if f.Snid == p.SnId { if f.Snid == p.SnId {
@ -165,7 +165,7 @@ func (this *CSFriendOpHandler) Process(s *netlib.Session, packetid int, data int
if destP.Roles != nil { if destP.Roles != nil {
roleId = int(destP.Roles.ModId) roleId = int(destP.Roles.ModId)
} }
FriendMgrSington.FriendOp(msg.OpCode, p, &model.BindFriend{ FriendMgrSingleton.FriendOp(msg.OpCode, p, &model.BindFriend{
SnId: destP.SnId, SnId: destP.SnId,
Platform: destP.Platform, Platform: destP.Platform,
Name: destP.Name, Name: destP.Name,
@ -194,7 +194,7 @@ func (this *CSFriendOpHandler) Process(s *netlib.Session, packetid int, data int
if destPlayer.Roles != nil { if destPlayer.Roles != nil {
roleId = int(destPlayer.Roles.ModId) roleId = int(destPlayer.Roles.ModId)
} }
FriendMgrSington.FriendOp(msg.OpCode, p, &model.BindFriend{ FriendMgrSingleton.FriendOp(msg.OpCode, p, &model.BindFriend{
SnId: destPlayer.SnId, SnId: destPlayer.SnId,
Platform: destPlayer.Platform, Platform: destPlayer.Platform,
Name: destPlayer.Name, Name: destPlayer.Name,
@ -325,7 +325,7 @@ func (this *CSInviteFriendHandler) Process(s *netlib.Session, packetid int, data
return nil return nil
} }
//不是好友 //不是好友
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, friendSnid) { if !FriendMgrSingleton.IsFriend(p.Platform, p.SnId, friendSnid) {
logger.Logger.Warn("CSInviteFriendHandler not friend") logger.Logger.Warn("CSInviteFriendHandler not friend")
opRetCode = friend.OpResultCode_OPRC_InviteFriend_NotFriend opRetCode = friend.OpResultCode_OPRC_InviteFriend_NotFriend
send(p) send(p)
@ -340,7 +340,7 @@ func (this *CSInviteFriendHandler) Process(s *netlib.Session, packetid int, data
return nil return nil
} }
//CD //CD
if !FriendMgrSington.CanInvite(p.Platform, p.SnId, friendSnid) { if !FriendMgrSingleton.CanInvite(p.Platform, p.SnId, friendSnid) {
logger.Logger.Warn("CSInviteFriendHandler in cd time") logger.Logger.Warn("CSInviteFriendHandler in cd time")
opRetCode = friend.OpResultCode_OPRC_Error opRetCode = friend.OpResultCode_OPRC_Error
send(p) send(p)
@ -437,7 +437,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da
return nil return nil
} }
//不是好友 //不是好友
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, srcSnid) { if !FriendMgrSingleton.IsFriend(p.Platform, p.SnId, srcSnid) {
logger.Logger.Warn("CSInviteFriendHandler not friend") logger.Logger.Warn("CSInviteFriendHandler not friend")
opRetCode = friend.OpResultCode_OPRC_InviteFriend_NotFriend opRetCode = friend.OpResultCode_OPRC_InviteFriend_NotFriend
send(p) send(p)
@ -445,7 +445,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da
} }
switch int(opcode) { switch int(opcode) {
case Invite_Agree: case InviteAgree:
logger.Logger.Trace("同意邀请") logger.Logger.Trace("同意邀请")
if p.scene != nil { if p.scene != nil {
logger.Logger.Warn("CSInviteFriendHandler scene is not nil") logger.Logger.Warn("CSInviteFriendHandler scene is not nil")
@ -574,7 +574,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da
} }
} }
} }
case Invite_Refuse: case InviteRefuse:
logger.Logger.Trace("拒绝邀请") logger.Logger.Trace("拒绝邀请")
send(fp) //通知邀请者 send(fp) //通知邀请者
} }
@ -612,7 +612,7 @@ func (this *CSFuzzyQueryPlayerHandler) Process(s *netlib.Session, packetid int,
// 优先搜索在线玩家 // 优先搜索在线玩家
for _, player := range PlayerMgrSington.snidMap { for _, player := range PlayerMgrSington.snidMap {
if player != nil && player.IsOnLine() /*&& !player.IsRobot() && !FriendMgrSington.IsFriend(p.SnId, player.SnId)*/ { //在线 if player != nil && player.IsOnLine() /*&& !player.IsRobot() && !FriendMgrSingleton.IsFriend(p.SnId, player.SnId)*/ { //在线
if !player.IsRob && player.Platform != p.Platform { //不同平台的真人不能匹配 if !player.IsRob && player.Platform != p.Platform { //不同平台的真人不能匹配
continue continue
} }

View File

@ -325,7 +325,7 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid
// 私人房需要是好友 // 私人房需要是好友
if scene.sceneMode == common.SceneModePrivate { if scene.sceneMode == common.SceneModePrivate {
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, scene.creator) { if !FriendMgrSingleton.IsFriend(p.Platform, p.SnId, scene.creator) {
continue continue
} }
} }

View File

@ -167,7 +167,7 @@ func (this *CSRisingStarHandler) Process(s *netlib.Session, packetid int, data i
}) })
//人物模型状态处理 //人物模型状态处理
p.Roles.ModUnlock[msg.RisingModId]++ p.Roles.ModUnlock[msg.RisingModId]++
FriendMgrSington.UpdateInfo(p.Platform, p.SnId) FriendMgrSingleton.UpdateInfo(p.Platform, p.SnId)
p.dirty = true p.dirty = true
//人物 //人物
SendInfoRole(pets.OpResultCode_OPRC_Sucess, ModelMgrSingleton.GetRoleInfo(p, msg.RisingModId)) SendInfoRole(pets.OpResultCode_OPRC_Sucess, ModelMgrSingleton.GetRoleInfo(p, msg.RisingModId))
@ -213,7 +213,7 @@ func (this *CSRisingStarHandler) Process(s *netlib.Session, packetid int, data i
Remark: remark, Remark: remark,
}) })
p.Pets.ModUnlock[msg.RisingModId]++ p.Pets.ModUnlock[msg.RisingModId]++
FriendMgrSington.UpdateInfo(p.Platform, p.SnId) FriendMgrSingleton.UpdateInfo(p.Platform, p.SnId)
p.dirty = true p.dirty = true
//宠物 //宠物
SendInfoPet(pets.OpResultCode_OPRC_Sucess, ModelMgrSingleton.GetPetInfo(p, msg.RisingModId)) SendInfoPet(pets.OpResultCode_OPRC_Sucess, ModelMgrSingleton.GetPetInfo(p, msg.RisingModId))
@ -346,7 +346,7 @@ func (this *CSRolePetUnlockHandler) Process(s *netlib.Session, packetid int, dat
if p.Roles.Mod[msg.UseModId].Ts == 0 { if p.Roles.Mod[msg.UseModId].Ts == 0 {
p.Roles.Mod[msg.UseModId].Ts = time.Now().Unix() p.Roles.Mod[msg.UseModId].Ts = time.Now().Unix()
} }
FriendMgrSington.UpdateInfo(p.Platform, p.SnId) FriendMgrSingleton.UpdateInfo(p.Platform, p.SnId)
p.dirty = true p.dirty = true
logger.Logger.Trace("解锁人物", msg.UseModId) logger.Logger.Trace("解锁人物", msg.UseModId)
SendMsg(pets.OpResultCode_OPRC_Sucess, ModelMgrSingleton.GetRoleInfo(p, msg.UseModId), nil) SendMsg(pets.OpResultCode_OPRC_Sucess, ModelMgrSingleton.GetRoleInfo(p, msg.UseModId), nil)
@ -381,7 +381,7 @@ func (this *CSRolePetUnlockHandler) Process(s *netlib.Session, packetid int, dat
if p.Pets.Mod[msg.UseModId].Ts == 0 { if p.Pets.Mod[msg.UseModId].Ts == 0 {
p.Pets.Mod[msg.UseModId].Ts = time.Now().Unix() p.Pets.Mod[msg.UseModId].Ts = time.Now().Unix()
} }
FriendMgrSington.UpdateInfo(p.Platform, p.SnId) FriendMgrSingleton.UpdateInfo(p.Platform, p.SnId)
p.dirty = true p.dirty = true
logger.Logger.Trace("解锁宠物", msg.UseModId) logger.Logger.Trace("解锁宠物", msg.UseModId)
SendMsg(pets.OpResultCode_OPRC_Sucess, nil, ModelMgrSingleton.GetPetInfo(p, msg.UseModId)) SendMsg(pets.OpResultCode_OPRC_Sucess, nil, ModelMgrSingleton.GetPetInfo(p, msg.UseModId))

View File

@ -2172,9 +2172,9 @@ func CSQueryPlayer(s *netlib.Session, packetid int, data interface{}, sid int64)
GameID: f.GameID, GameID: f.GameID,
} }
//IsFriend //IsFriend
pack.IsFriend = FriendMgrSington.IsFriend(p.Platform, p.SnId, f.SnId) pack.IsFriend = FriendMgrSingleton.IsFriend(p.Platform, p.SnId, f.SnId)
//IsShield //IsShield
pack.IsShield = FriendMgrSington.IsShield(p.Platform, p.SnId, f.SnId) pack.IsShield = FriendMgrSingleton.IsShield(p.Platform, p.SnId, f.SnId)
//Role //Role
roleInfo := f.Roles roleInfo := f.Roles
if roleInfo != nil { if roleInfo != nil {
@ -2227,7 +2227,7 @@ func CSQueryPlayer(s *netlib.Session, packetid int, data interface{}, sid int64)
p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_QUERYPLAYER), pack) p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_QUERYPLAYER), pack)
logger.Logger.Trace("SCQueryPlayerHandler ok: ", ok, " pack: ", pack) logger.Logger.Trace("SCQueryPlayerHandler ok: ", ok, " pack: ", pack)
} else { // 真人去friend取信息 } else { // 真人去friend取信息
friend := FriendMgrSington.GetPlayer(p.Platform, destSnId) friend := FriendMgrSingleton.GetPlayer(p.Platform, destSnId)
if friend != nil { if friend != nil {
send(friend) send(friend)
} else { } else {

View File

@ -148,7 +148,7 @@ func init() {
// 更新好友信息 // 更新好友信息
if param.ItemId == common.ItemIDVCard { if param.ItemId == common.ItemIDVCard {
FriendMgrSington.UpdateInfo(p.Platform, p.SnId) FriendMgrSingleton.UpdateInfo(p.Platform, p.SnId)
} }
}) })
} }

View File

@ -18,37 +18,40 @@ import (
"mongo.games.com/game/worldsrv/internal" "mongo.games.com/game/worldsrv/internal"
) )
// 列表类型
const ( const (
ListType_Friend int32 = iota // 0.好友列表 ListTypeFriend int32 = iota // 0.好友列表
ListType_Apply // 1.申请列表 ListTypeApply // 1.申请列表
ListType_Recommend // 2.推荐列表 ListTypeRecommend // 2.推荐列表
) )
// 好友操作
const ( const (
OpType_Apply int32 = iota // 0.申请 OpTypeApply int32 = iota // 0.申请,申请添加好友
OpType_Agree // 1.同意 OpTypeAgree // 1.同意,同意添加好友
OpType_Refuse // 2.拒绝 OpTypeRefuse // 2.拒绝,拒绝添加好友
OpType_Delete // 3.删除 OpTypeDelete // 3.删除,删除好友
) )
// 是否同意邀请进入游戏
const ( const (
Invite_Agree int = iota // 0.同意 InviteAgree int = iota // 0.同意
Invite_Refuse // 1.拒绝 InviteRefuse // 1.拒绝
) )
const FriendMaxNum = 200 const FriendMaxNum = 200 // 好友最大数量
const ShieldMaxNum = 10000 const ShieldMaxNum = 10000 // 最大屏蔽人数
const FriendApplyMaxNum = 1000 //好友申请上限 const FriendApplyMaxNum = 1000 // 好友申请上限
const FriendWrite = "FriendWrite" const FriendWrite = "FriendWrite" // 好友数据修改线程名称
var FriendMgrSington = &FriendMgr{ var FriendMgrSingleton = &FriendMgr{
FriendList: make(map[string]map[int32]*model.Friend), FriendList: make(map[string]map[int32]*model.Friend),
TsInviteCd: make(map[string]map[string]int64), TsInviteCd: make(map[string]map[string]int64),
} }
type FriendMgr struct { type FriendMgr struct {
FriendList map[string]map[int32]*model.Friend // 平台id:snid:好友信息 FriendList map[string]map[int32]*model.Friend // 平台id:snid:好友信息
TsInviteCd map[string]map[string]int64 // 平台id:snid:邀请cd时间 TsInviteCd map[string]map[string]int64 // 平台id:邀请人id_被邀请人id:邀请cd时间
} }
func (this *FriendMgr) ModuleName() string { func (this *FriendMgr) ModuleName() string {
@ -84,6 +87,8 @@ func (this *FriendMgr) Del(platform string, snid int32) {
} }
// CanInvite 是否可以邀请,邀请冷却 // CanInvite 是否可以邀请,邀请冷却
// snid 发起人
// fsnid 被邀请人
func (this *FriendMgr) CanInvite(platform string, snid, fsnid int32) bool { func (this *FriendMgr) CanInvite(platform string, snid, fsnid int32) bool {
if this.TsInviteCd[platform] == nil { if this.TsInviteCd[platform] == nil {
this.TsInviteCd[platform] = make(map[string]int64) this.TsInviteCd[platform] = make(map[string]int64)
@ -275,6 +280,10 @@ func (this *FriendMgr) ApplyList(platform string, snid int32) {
if ret != nil && ret.ApplySnids != nil { if ret != nil && ret.ApplySnids != nil {
pack := &friend.SCFriendApplyData{} pack := &friend.SCFriendApplyData{}
for _, as := range ret.ApplySnids { for _, as := range ret.ApplySnids {
p := PlayerMgrSington.GetPlayerBySnId(as.SnId)
if p != nil {
as.Name = p.Name
}
fa := &friend.FriendApply{ fa := &friend.FriendApply{
Snid: proto.Int32(as.SnId), Snid: proto.Int32(as.SnId),
Name: proto.String(as.Name), Name: proto.String(as.Name),
@ -302,6 +311,7 @@ func (this *FriendMgr) ApplyList(platform string, snid int32) {
} }
// AddShield 屏蔽好友消息 // AddShield 屏蔽好友消息
// snid屏蔽ssnid的消息
func (this *FriendMgr) AddShield(platform string, snid, ssnid int32) { func (this *FriendMgr) AddShield(platform string, snid, ssnid int32) {
if this.FriendList[platform] == nil { if this.FriendList[platform] == nil {
return return
@ -382,16 +392,16 @@ func (this *FriendMgr) UpdateLogoutTime(platform string, snid int32) {
func (this *FriendMgr) FriendOp(opcode int32, p *Player, destP *model.BindFriend) { func (this *FriendMgr) FriendOp(opcode int32, p *Player, destP *model.BindFriend) {
switch opcode { switch opcode {
case OpType_Apply: case OpTypeApply:
logger.Logger.Trace("@Apply friend", p.SnId, " -> ", destP.SnId) logger.Logger.Trace("@Apply friend", p.SnId, " -> ", destP.SnId)
this.FriendApply(p, destP) this.FriendApply(p, destP)
case OpType_Agree: case OpTypeAgree:
logger.Logger.Trace("@AgreeApply friend", p.SnId, " -> ", destP.SnId) logger.Logger.Trace("@AgreeApply friend", p.SnId, " -> ", destP.SnId)
this.FriendAgree(p, destP) this.FriendAgree(p, destP)
case OpType_Refuse: case OpTypeRefuse:
logger.Logger.Trace("@Refuse friend", p.SnId, " -> ", destP.SnId) logger.Logger.Trace("@Refuse friend", p.SnId, " -> ", destP.SnId)
this.FriendRefuse(p, destP) this.FriendRefuse(p, destP)
case OpType_Delete: case OpTypeDelete:
logger.Logger.Trace("@Delete friend", p.SnId, " -> ", destP.SnId) logger.Logger.Trace("@Delete friend", p.SnId, " -> ", destP.SnId)
this.FriendDelete(p, destP) this.FriendDelete(p, destP)
} }
@ -399,11 +409,13 @@ func (this *FriendMgr) FriendOp(opcode int32, p *Player, destP *model.BindFriend
// FriendApply 好友申请 // FriendApply 好友申请
// 记录在数据库 // 记录在数据库
// p 发起方
// destP 接收方
func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) { func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
var applyList []int32 var applyList []int32
SendToClick := func(retCode friend.OpResultCode, self ...bool) { SendToClick := func(retCode friend.OpResultCode, self ...bool) {
pack := &friend.SCFriendOp{ pack := &friend.SCFriendOp{
OpCode: proto.Int32(OpType_Apply), OpCode: proto.Int32(OpTypeApply),
SnId: proto.Int32(destP.SnId), SnId: proto.Int32(destP.SnId),
OpRetCode: retCode, OpRetCode: retCode,
} }
@ -435,7 +447,7 @@ func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
} }
logger.Logger.Tracef(">>FriendApply %d -> %d, %v", p.SnId, destP.SnId, pack) logger.Logger.Tracef(">>FriendApply %d -> %d, %v", p.SnId, destP.SnId, pack)
} }
if FriendMgrSington.IsFriend(p.Platform, p.SnId, destP.SnId) { if FriendMgrSingleton.IsFriend(p.Platform, p.SnId, destP.SnId) {
SendToClick(friend.OpResultCode_OPRC_Friend_AlreadyAdd) SendToClick(friend.OpResultCode_OPRC_Friend_AlreadyAdd)
return return
} }
@ -496,11 +508,13 @@ func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
} }
// FriendAgree 同意好友申请 // FriendAgree 同意好友申请
// p 同意者
// destP 申请者
func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) { func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
var applyList []int32 var applyList []int32
SendToClick := func(retCode friend.OpResultCode, self ...bool) { SendToClick := func(retCode friend.OpResultCode, self ...bool) {
pack := &friend.SCFriendOp{ pack := &friend.SCFriendOp{
OpCode: proto.Int32(OpType_Agree), OpCode: proto.Int32(OpTypeAgree),
SnId: proto.Int32(destP.SnId), SnId: proto.Int32(destP.SnId),
OpRetCode: retCode, OpRetCode: retCode,
} }
@ -546,12 +560,12 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
} }
logger.Logger.Tracef(">>FriendAgree %d -> %d, %v", p.SnId, destP.SnId, pack) logger.Logger.Tracef(">>FriendAgree %d -> %d, %v", p.SnId, destP.SnId, pack)
} }
me := FriendMgrSington.GetPlayer(p.Platform, p.SnId) me := FriendMgrSingleton.GetPlayer(p.Platform, p.SnId)
if me == nil { if me == nil {
SendToClick(friend.OpResultCode_OPRC_Error) SendToClick(friend.OpResultCode_OPRC_Error)
return return
} }
if FriendMgrSington.IsFriend(p.Platform, p.SnId, destP.SnId) { //已经是好友了 if FriendMgrSingleton.IsFriend(p.Platform, p.SnId, destP.SnId) { //已经是好友了
SendToClick(friend.OpResultCode_OPRC_Friend_AlreadyAdd) SendToClick(friend.OpResultCode_OPRC_Friend_AlreadyAdd)
return return
} }
@ -561,7 +575,7 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
return return
} }
destPFriend := FriendMgrSington.GetPlayer(destP.Platform, destP.SnId) destPFriend := FriendMgrSingleton.GetPlayer(destP.Platform, destP.SnId)
if destPFriend != nil { if destPFriend != nil {
if len(destPFriend.BindFriend) >= FriendMaxNum { if len(destPFriend.BindFriend) >= FriendMaxNum {
SendToClick(friend.OpResultCode_OPRC_Friend_DestFriendMax) SendToClick(friend.OpResultCode_OPRC_Friend_DestFriendMax)
@ -569,7 +583,7 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
} }
} }
var friendDB *model.Friend var friendDB *model.Friend // 申请者好友列表
var err error var err error
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
if destPFriend == nil { if destPFriend == nil {
@ -598,15 +612,17 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
if err != nil { if err != nil {
return friend.OpResultCode_OPRC_Error return friend.OpResultCode_OPRC_Error
} }
// 维护申请放和被申请方的申请列表
//查看是否在申请列表 //查看是否在申请列表
if ret != nil { if ret != nil {
if ret.ApplySnids != nil { if ret.ApplySnids != nil {
for i, as := range ret.ApplySnids { for i, as := range ret.ApplySnids {
if as.SnId == destP.SnId { if as.SnId == destP.SnId {
//在申请列表 删除 // 删除被申请者的申请列表
ret.ApplySnids = append(ret.ApplySnids[:i], ret.ApplySnids[i+1:]...) ret.ApplySnids = append(ret.ApplySnids[:i], ret.ApplySnids[i+1:]...)
model.UpsertFriendApply(p.Platform, p.SnId, ret) model.UpsertFriendApply(p.Platform, p.SnId, ret)
// 删除发起方的申请列表
data, err := model.QueryFriendApplyListBySnid(p.Platform, destP.SnId) data, err := model.QueryFriendApplyListBySnid(p.Platform, destP.SnId)
if err != nil { if err != nil {
logger.Logger.Errorf("QueryFriendApplyListBySnid err:%v", err) logger.Logger.Errorf("QueryFriendApplyListBySnid err:%v", err)
@ -646,12 +662,12 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
} }
//同意者加入到被同意者好友里 //同意者加入到被同意者好友里
if destPlayer := FriendMgrSington.GetPlayer(destP.Platform, destP.SnId); destPlayer != nil { if destPlayer := FriendMgrSingleton.GetPlayer(destP.Platform, destP.SnId); destPlayer != nil {
roleId := common.DefaultRoleId roleId := common.DefaultRoleId
if p.Roles != nil { if p.Roles != nil {
roleId = int(p.Roles.ModId) roleId = int(p.Roles.ModId)
} }
result := FriendMgrSington.AgreeApply(destP.Platform, destP.SnId, &model.BindFriend{ result := FriendMgrSingleton.AgreeApply(destP.Platform, destP.SnId, &model.BindFriend{
SnId: p.SnId, SnId: p.SnId,
CreateTime: time.Now().Unix(), CreateTime: time.Now().Unix(),
Platform: p.Platform, Platform: p.Platform,
@ -670,7 +686,7 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
} }
// 被同意者加入到同意者好友里 // 被同意者加入到同意者好友里
result := FriendMgrSington.AgreeApply(p.Platform, p.SnId, destP) result := FriendMgrSingleton.AgreeApply(p.Platform, p.SnId, destP)
if result != friend.OpResultCode_OPRC_Sucess { if result != friend.OpResultCode_OPRC_Sucess {
SendToClick(result, false) SendToClick(result, false)
SendToClick(result) SendToClick(result)
@ -685,7 +701,7 @@ func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
var applyList []int32 var applyList []int32
SendToClick := func(retCode friend.OpResultCode, self ...bool) { SendToClick := func(retCode friend.OpResultCode, self ...bool) {
pack := &friend.SCFriendOp{ pack := &friend.SCFriendOp{
OpCode: proto.Int32(OpType_Refuse), OpCode: proto.Int32(OpTypeRefuse),
SnId: proto.Int32(destP.SnId), SnId: proto.Int32(destP.SnId),
OpRetCode: retCode, OpRetCode: retCode,
} }
@ -699,7 +715,7 @@ func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
} }
logger.Logger.Tracef(">>FriendRefuse %d -> %d, %v", p.SnId, destP.SnId, pack) logger.Logger.Tracef(">>FriendRefuse %d -> %d, %v", p.SnId, destP.SnId, pack)
} }
if FriendMgrSington.IsFriend(p.Platform, p.SnId, destP.SnId) { if FriendMgrSingleton.IsFriend(p.Platform, p.SnId, destP.SnId) {
SendToClick(friend.OpResultCode_OPRC_Friend_AlreadyAdd) SendToClick(friend.OpResultCode_OPRC_Friend_AlreadyAdd)
return return
} }
@ -744,6 +760,7 @@ func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
} }
SendToClick(friend.OpResultCode_OPRC_Sucess) SendToClick(friend.OpResultCode_OPRC_Sucess)
// 刷新发起者的申请好友列表
destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId) destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId)
if destPs != nil && destPs.IsOnLine() { if destPs != nil && destPs.IsOnLine() {
if applyList != nil { if applyList != nil {
@ -757,7 +774,7 @@ func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
func (this *FriendMgr) FriendDelete(p *Player, destP *model.BindFriend) { func (this *FriendMgr) FriendDelete(p *Player, destP *model.BindFriend) {
SendToClick := func(retCode friend.OpResultCode, self ...bool) { SendToClick := func(retCode friend.OpResultCode, self ...bool) {
pack := &friend.SCFriendOp{ pack := &friend.SCFriendOp{
OpCode: proto.Int32(OpType_Delete), OpCode: proto.Int32(OpTypeDelete),
SnId: proto.Int32(destP.SnId), SnId: proto.Int32(destP.SnId),
OpRetCode: retCode, OpRetCode: retCode,
} }
@ -774,17 +791,17 @@ func (this *FriendMgr) FriendDelete(p *Player, destP *model.BindFriend) {
} }
} }
} }
f := FriendMgrSington.GetPlayer(p.Platform, destP.SnId) f := FriendMgrSingleton.GetPlayer(p.Platform, destP.SnId)
if f != nil { if f != nil {
//发起者删除被删除者 //发起者删除被删除者
isok1 := FriendMgrSington.RemoveFriend(p.Platform, p.SnId, f.SnId) isok1 := FriendMgrSingleton.RemoveFriend(p.Platform, p.SnId, f.SnId)
if !isok1 { if !isok1 {
logger.Logger.Warn("RemoveFriend error: ", p.SnId, " del friend:", f.SnId) logger.Logger.Warn("RemoveFriend error: ", p.SnId, " del friend:", f.SnId)
SendToClick(friend.OpResultCode_OPRC_Error) SendToClick(friend.OpResultCode_OPRC_Error)
return return
} }
//被删除者删除发起者 //被删除者删除发起者
isok2 := FriendMgrSington.RemoveFriend(f.Platform, f.SnId, p.SnId) isok2 := FriendMgrSingleton.RemoveFriend(f.Platform, f.SnId, p.SnId)
if !isok2 { if !isok2 {
logger.Logger.Warn("RemoveFriend error: ", f.SnId, " del friend:", p.SnId) logger.Logger.Warn("RemoveFriend error: ", f.SnId, " del friend:", p.SnId)
//删除失败不用通知 //删除失败不用通知
@ -817,7 +834,7 @@ func (this *FriendMgr) FriendDelete(p *Player, destP *model.BindFriend) {
return return
} else { } else {
//发起者删除被删除者 //发起者删除被删除者
isok1 := FriendMgrSington.RemoveFriend(p.Platform, p.SnId, destP.SnId) isok1 := FriendMgrSingleton.RemoveFriend(p.Platform, p.SnId, destP.SnId)
if !isok1 { if !isok1 {
logger.Logger.Warn("RemoveFriend error: ", p.SnId, " del friend:", destP.SnId) logger.Logger.Warn("RemoveFriend error: ", p.SnId, " del friend:", destP.SnId)
//SendToClick(friend.OpResultCode_OPRC_Error) //SendToClick(friend.OpResultCode_OPRC_Error)
@ -875,6 +892,7 @@ func (this *FriendMgr) LoadAfter(platform string, snid int32) *internal.PlayerLo
Snid: snid, Snid: snid,
} }
// 查询好友列表
friendDB, err := model.QueryFriendBySnid(platform, snid) friendDB, err := model.QueryFriendBySnid(platform, snid)
if err != nil { if err != nil {
logger.Logger.Error("QueryFriendBySnid:", err, snid) logger.Logger.Error("QueryFriendBySnid:", err, snid)
@ -886,6 +904,7 @@ func (this *FriendMgr) LoadAfter(platform string, snid int32) *internal.PlayerLo
return ret return ret
} }
// 查询好友信息
var offSnID []int32 var offSnID []int32
for _, v := range friendDB.BindFriend { for _, v := range friendDB.BindFriend {
roleId := common.DefaultRoleId roleId := common.DefaultRoleId
@ -1011,6 +1030,6 @@ func (this *FriendMgr) Release(platform string, snid int32) {
} }
func init() { func init() {
module.RegisteModule(FriendMgrSington, time.Hour, 0) module.RegisteModule(FriendMgrSingleton, time.Hour, 0)
internal.RegisterPlayerLoad(FriendMgrSington) internal.RegisterPlayerLoad(FriendMgrSingleton)
} }

View File

@ -100,7 +100,7 @@ func (this *FriendUnreadMgr) CheckSendFriendUnreadData(platform string, snid int
} }
pack := &friend.SCFriendUnreadData{} pack := &friend.SCFriendUnreadData{}
for cSnid, unreadNum := range ful { for cSnid, unreadNum := range ful {
isFriend := FriendMgrSington.IsFriend(platform, snid, cSnid) isFriend := FriendMgrSingleton.IsFriend(platform, snid, cSnid)
if isFriend { if isFriend {
fu := &friend.FriendUnread{ fu := &friend.FriendUnread{
Snid: proto.Int32(cSnid), Snid: proto.Int32(cSnid),
@ -135,7 +135,7 @@ func (this *FriendUnreadMgr) SaveFriendUnreadData(platform string, snid int32) {
if ful, ok := this.FriendUnreadList[platform][snid]; ok { if ful, ok := this.FriendUnreadList[platform][snid]; ok {
fu := model.NewFriendUnread(snid) fu := model.NewFriendUnread(snid)
for cSnid, unreadNum := range ful { for cSnid, unreadNum := range ful {
if unreadNum > 0 && FriendMgrSington.IsFriend(platform, snid, cSnid) { if unreadNum > 0 && FriendMgrSingleton.IsFriend(platform, snid, cSnid) {
us := &model.FriendUnreadSnid{ us := &model.FriendUnreadSnid{
SnId: cSnid, SnId: cSnid,
UnreadNum: int32(unreadNum), UnreadNum: int32(unreadNum),

View File

@ -395,7 +395,7 @@ func (this *Player) OnRehold() {
//登录事件 //登录事件
this.ReportLoginEvent() this.ReportLoginEvent()
FriendMgrSington.ApplyList(this.Platform, this.SnId) FriendMgrSingleton.ApplyList(this.Platform, this.SnId)
FriendUnreadMgrSington.CheckSendFriendUnreadData(this.Platform, this.SnId) FriendUnreadMgrSington.CheckSendFriendUnreadData(this.Platform, this.SnId)
if !this.IsRob { if !this.IsRob {
@ -1200,7 +1200,7 @@ func (this *Player) DropLine() {
this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_PLAYERDROPLINE), pack) this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_PLAYERDROPLINE), pack)
} }
FriendMgrSington.UpdateLogoutTime(this.Platform, this.SnId) FriendMgrSingleton.UpdateLogoutTime(this.Platform, this.SnId)
PlayerMgrSington.DropPlayer(this) PlayerMgrSington.DropPlayer(this)
} }
@ -1212,7 +1212,7 @@ func (this *Player) Logout() {
} }
this.SendToClient(int(loginproto.LoginPacketID_PACKET_SC_LOGOUT), scLogout) this.SendToClient(int(loginproto.LoginPacketID_PACKET_SC_LOGOUT), scLogout)
FriendMgrSington.UpdateLogoutTime(this.Platform, this.SnId) FriendMgrSingleton.UpdateLogoutTime(this.Platform, this.SnId)
PlayerMgrSington.DropPlayer(this) PlayerMgrSington.DropPlayer(this)
} }
@ -2006,7 +2006,7 @@ func (this *Player) SendDiffData() {
} }
if dirty { if dirty {
FriendMgrSington.UpdateInfo(this.Platform, this.SnId) FriendMgrSingleton.UpdateInfo(this.Platform, this.SnId)
this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_PLAYERDATAUPDATE), pack) this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_PLAYERDATAUPDATE), pack)
logger.Logger.Trace("(this *Player) SendDiffData() ", pack) logger.Logger.Trace("(this *Player) SendDiffData() ", pack)
} }

View File

@ -410,7 +410,7 @@ func (this *PlayerMgr) BroadcastMessageToPlatformWithHall(platform string, snid
mgs := make(map[*netlib.Session][]*srvproto.MCSessionUnion) mgs := make(map[*netlib.Session][]*srvproto.MCSessionUnion)
for _, p := range players { for _, p := range players {
if p != nil && p.gateSess != nil && p.IsOnLine() && p.scene == nil { if p != nil && p.gateSess != nil && p.IsOnLine() && p.scene == nil {
if FriendMgrSington.IsShield(p.Platform, p.SnId, snid) { if FriendMgrSingleton.IsShield(p.Platform, p.SnId, snid) {
continue continue
} }
mgs[p.gateSess] = append(mgs[p.gateSess], &srvproto.MCSessionUnion{ mgs[p.gateSess] = append(mgs[p.gateSess], &srvproto.MCSessionUnion{
@ -663,7 +663,7 @@ func (this *PlayerMgr) RecommendFriendRule(platform string, snid int32) []Recomm
rets := []RecommendFriend{} rets := []RecommendFriend{}
players := this.playerOfPlatform[platform] players := this.playerOfPlatform[platform]
for _, player := range players { //优先真人 for _, player := range players { //优先真人
if player.SnId != snid && !FriendMgrSington.IsFriend(platform, snid, player.SnId) { if player.SnId != snid && !FriendMgrSingleton.IsFriend(platform, snid, player.SnId) {
roleId := common.DefaultRoleId roleId := common.DefaultRoleId
if player.Roles != nil { if player.Roles != nil {
roleId = int(player.Roles.ModId) roleId = int(player.Roles.ModId)
@ -734,8 +734,8 @@ func init() {
PlayerSubjectSign.AttachHeadOutline(PlayerMgrSington) PlayerSubjectSign.AttachHeadOutline(PlayerMgrSington)
PlayerSubjectSign.AttachHeadUrl(PlayerMgrSington) PlayerSubjectSign.AttachHeadUrl(PlayerMgrSington)
PlayerSubjectSign.AttachName(FriendMgrSington) PlayerSubjectSign.AttachName(FriendMgrSingleton)
PlayerSubjectSign.AttachHead(FriendMgrSington) PlayerSubjectSign.AttachHead(FriendMgrSingleton)
// 定时器 // 定时器
common.RegisterClockFunc(&common.ClockFunc{ common.RegisterClockFunc(&common.ClockFunc{