Example #1
0
        public override bool TakeAction()
        {
            var cacheSet = new ShareCacheStruct<UserFriends>();
            if (_friendId != "" && _friendId != ContextUser.UserID)
            {
                //找到本玩家的数据
                List<UserFriends> friendArray = cacheSet.FindAll(m => m.UserID == ContextUser.UserID);
                int friendNum = ConfigEnvSet.GetInt("UserFriends.MaxFriendNum");
                //添加的好友上限
                if (friendArray.Count >= friendNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St9103_TheMaximumReachedAFriend;
                    return false;
                }

                //查看是否在user库中有该玩家
                GameUser userInfo = new GameDataCacheSet<GameUser>().FindKey(_friendId);
                if (userInfo == null)
                {
                    UserCacheGlobal.LoadOffline(_friendId);
                    userInfo = new GameDataCacheSet<GameUser>().FindKey(_friendId);
                }
                if (userInfo == null)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St9103_NotFriendsUserID;
                    return false;
                }

                //在好友表中查找本玩家 和添加好友的关系
                var userFriend = cacheSet.FindKey(ContextUser.UserID, _friendId);
                var userFriend1 = cacheSet.FindKey(_friendId, ContextUser.UserID);
                //同意
                if (_ops == 1)
                {
                   //有信息表 没信息表
                   if (userFriend == null)
                   {
                       //创建新的数据 并且添加成关注类型
                       var friends = new UserFriends
                       {
                           UserID = ContextUser.UserID,
                           FriendID = _friendId,
                           FriendType = FriendType.Friend
                       };
                       cacheSet.Add(friends);
                       //todo test
                       friends.ChatTime = DateTime.Now;

                   }else
                   {
                       //玩家原来就有数据
                       //判断两个玩家的关系
                       if (userFriend.FriendType == FriendType.Friend)
                       {
                           ErrorCode = LanguageManager.GetLang().ErrorCode;
                           ErrorInfo = LanguageManager.GetLang().St9103_TheUserHasAFriendIn;
                           return false;
                       }
                       userFriend.FriendType = FriendType.Friend;
                   }

                   //判断对方是否有和本玩家的数据 如果没有创建 有改状态
                   if (userFriend1 == null)
                   {
                       var friends2 = new UserFriends
                       {
                           UserID = _friendId,
                           FriendID = ContextUser.UserID,
                           FriendType = FriendType.Friend,
                       };
                       cacheSet.Add(friends2);
                       //todo test
                       friends2.ChatTime = DateTime.Now;
                   }
                   else
                   {
                         userFriend1.FriendType = FriendType.Friend;
                    }

                    //加为好友成功后发送一条邮件
                   try
                   {
                       Guid newGuid = Guid.NewGuid();
                       UserMail userMail = new UserMail(newGuid);
                       userMail.UserId = Int32.Parse(_friendId);
                       userMail.MailType = (int)MailType.Friends;
                       userMail.Title = LanguageManager.GetLang().St_AskFirendMailTitle;
                       userMail.Content = string.Format(LanguageManager.GetLang().St_FirendNotice, ContextUser.NickName);
                       userMail.SendDate = DateTime.Now;
                       userMail.FromUserId = Int32.Parse(ContextUser.UserID);
                       userMail.FromUserName = ContextUser.NickName;
                       TjxMailService mailService = new TjxMailService(ContextUser);
                       mailService.Send(userMail);

                       var noticeMail = mailService.ReadMail(ContextUser.UserID, _mailId);
                       noticeMail.ReplyStatus = 1;

                   }
                   catch (Exception)
                   {

                   }

                }else
                {

                    //不同意
                    TjxMailService mailService = new TjxMailService(ContextUser);
                    var noticeMail = mailService.ReadMail(ContextUser.UserID, _mailId);
                    noticeMail.ReplyStatus = 1;

                }
            }
            return true;
        }
Example #2
0
 /// <summary>
 /// 增加仇敌
 /// </summary>
 /// <param name="user"></param>
 /// <param name="toUser"></param>
 private static void AddFoe(GameUser user, GameUser toUser)
 {
     var cacheSet = new ShareCacheStruct<UserFriends>();
     var friends = cacheSet.Find(s => s.FriendID == user.UserID && s.UserID == toUser.UserID && s.FriendType == FriendType.Friend);
     var choudiFriends = cacheSet.Find(s => s.FriendID == user.UserID && s.UserID == toUser.UserID && s.FriendType == FriendType.ChouDi);
     if (friends == null && choudiFriends == null)
     {
         var list = cacheSet.FindAll(s => s.UserID == toUser.UserID && s.FriendType == FriendType.ChouDi);
         if (list.Count >= 50)
         {
             list.QuickSort((x, y) =>
             {
                 if (x == null && y == null) return 0;
                 if (x != null && y == null) return 1;
                 if (x == null) return -1;
                 return (x.FightTime).CompareTo(y.FightTime);
             });
             int count = list.Count - 49 + 1;
             for (int i = 0; i < count; i++)
             {
                 cacheSet.Delete(list[i]);
             }
         }
         var userFriends = new UserFriends();
         userFriends.UserID = toUser.UserID;
         userFriends.FriendID = user.UserID;
         userFriends.FightTime = DateTime.Now;
         userFriends.FriendType = FriendType.ChouDi;
         userFriends.ChatTime = DateTime.Now;
         cacheSet.Add(userFriends, GameEnvironment.CacheGlobalPeriod);
     }
 }
Example #3
0
        public override bool TakeAction()
        {
            var cacheSet = new ShareCacheStruct<UserFriends>();
            _isSuccess = 1;
            if (_friendId != "")
            {
                //找到本玩家的数据
                List<UserFriends> friendArray = cacheSet.FindAll(m => m.UserID == ContextUser.UserID);
                int friendNum = ConfigEnvSet.GetInt("UserFriends.MaxFriendNum");
                //添加的好友上限
                if (friendArray.Count >= friendNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St9103_TheMaximumReachedAFriend;
                    return false;
                }
                //查看是否在user库中有该玩家
                GameUser userInfo = new GameDataCacheSet<GameUser>().FindKey(_friendId);
                if (userInfo == null)
                {
                    UserCacheGlobal.LoadOffline(_friendId);
                    userInfo = new GameDataCacheSet<GameUser>().FindKey(_friendId);
                }
                if (userInfo == null)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St9103_NotFriendsUserID;
                    return false;
                }

                //在好友表中查找本玩家 和添加好友的关系
                var userFriend = cacheSet.FindKey(ContextUser.UserID, _friendId);
                var userFriend1 = cacheSet.FindKey(_friendId, ContextUser.UserID);

                if (userFriend == null)
                {
                    //创建新的数据 并且添加成关注类型
                    var friends = new UserFriends
                                      {
                                          UserID = ContextUser.UserID,
                                          FriendID = _friendId,
                                          FriendType = FriendType.Attention
                                      };
                    cacheSet.Add(friends, GameEnvironment.CacheGlobalPeriod);
                    //todo test
                    friends.ChatTime = DateTime.Now;

                }
                //如果玩家数据不为空
                else
                {
                    //判断两个玩家的关系
                    if (userFriend.FriendType == FriendType.Friend)
                    {
                        ErrorCode = LanguageManager.GetLang().ErrorCode;
                        ErrorInfo = LanguageManager.GetLang().St9103_TheUserHasAFriendIn;
                        return false;
                    }

                    ////如果已经发送请求就不在继续发
                    //if (userFriend.FriendType == FriendType.Attention)
                    //{
                    //    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    //    ErrorInfo = LanguageManager.GetLang().St_FirendNoticeTip;
                    //    return false;
                    //}

                    //加好友都是变为关注 从仇敌那里也能转换为关注
                    if (userFriend.FriendType != FriendType.Friend)
                    {
                        userFriend.FriendType = FriendType.Attention;
                    }

                }

                //判断对方是否有和本玩家的数据 如果没有创建 有改状态
                if (userFriend1 == null)
                {
                    var friends2 = new UserFriends
                    {
                        UserID = _friendId,
                        FriendID = ContextUser.UserID,
                        FriendType = FriendType.Fans,
                    };
                    cacheSet.Add(friends2, GameEnvironment.CacheGlobalPeriod);
                    //todo test
                    friends2.ChatTime = DateTime.Now;
                }

                // 发送系统信件
                try
                {
                    Guid newGuid = Guid.NewGuid();
                    UserMail userMail = new UserMail(newGuid);
                    userMail.UserId = Int32.Parse(_friendId);
                    userMail.MailType = (int)MailType.Friends;
                    userMail.Title = LanguageManager.GetLang().St_AskFirendMailTitle;
                    userMail.Content = string.Format(LanguageManager.GetLang().St_AskFirendTip, ContextUser.NickName);
                    userMail.SendDate = DateTime.Now;
                    userMail.IsReply = true;
                    userMail.ReplyStatus = 0;
                    userMail.FromUserId = Int32.Parse(ContextUser.UserID);
                    userMail.FromUserName = ContextUser.NickName;
                    TjxMailService mailService = new TjxMailService(ContextUser);
                    mailService.Send(userMail);
                }
                catch (Exception)
                {

                }
            }
            //上传的好友名字不为空
            else if (_friendName != null)
            {
                List<UserFriends> friendArray = cacheSet.FindAll(m => m.UserID == ContextUser.UserID);
                int friendNum = ConfigEnvSet.GetInt("UserFriends.MaxFriendNum");
                if (friendArray.Count >= friendNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St9103_TheMaximumReachedAFriend;
                    return false;
                }
                GameUser friend = null;
                new GameDataCacheSet<GameUser>().Foreach((personalId, key, user) =>
                {
                    if (user.NickName == _friendName)
                    {
                        friend = user;
                        return false;
                    }
                    return true;
                });
                if (friend != null)
                {
                    GameUser gameUser = new GameDataCacheSet<GameUser>().FindKey(friend.UserID);
                    UserFriends userFriend = cacheSet.FindKey(ContextUser.UserID, _friendId);
                    if (userFriend != null)
                    {
                        if (userFriend.FriendType == FriendType.Fans)
                        {
                            this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                            this.ErrorInfo = LanguageManager.GetLang().St9103_TheUserHasTheFansIn;
                            return false;
                        }
                        else if (userFriend.FriendType == FriendType.Blacklist)
                        {
                            this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                            this.ErrorInfo = LanguageManager.GetLang().St9103_TheUserHasTheBlacklist;
                            return false;
                        }
                        else
                        {
                            this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                            this.ErrorInfo = LanguageManager.GetLang().St9103_TheUserHasAFriendIn;
                            return false;
                        }
                    }
                    UserFriends friends = new UserFriends()
                    {
                        UserID = ContextUser.UserID,
                        FriendID = gameUser.UserID,
                        FriendType = FriendType.Attention
                    };
                    cacheSet.Add(friends, GameEnvironment.CacheGlobalPeriod);

                    UserFriends friends2 = new UserFriends()
                    {
                        UserID = gameUser.UserID,
                        FriendID = ContextUser.UserID,
                        FriendType = FriendType.Fans,
                    };
                    cacheSet.Add(friends2, GameEnvironment.CacheGlobalPeriod);
                }
                else
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St9103_DoesNotExistTheUser;
                    return false;
                }
            }
            return true;
        }