Пример #1
0
        public override PropResult Apply(HttpRequest request, int threadID, string param)
        {
            List <int> forumIDs = StringUtil.Split2 <int>(param, ',');

            BasicThread thread = PostBOV5.Instance.GetThread(threadID);

            if (thread == null)
            {
                return(Error("指定主题不存在"));
            }
            else if (thread.PostUserID != User.Current.UserID)
            {
                return(Error("本道具只能用于您本人发表的主题"));
            }
            else if (forumIDs.Contains(-1) == false && forumIDs.Contains(thread.ForumID) == false)
            {
                return(Error("目标主题所属版块不在本道具有效范围中"));
            }

            if (PostBOV5.Instance.SetThreadsUp(User.Current, thread.ForumID, new int[] { threadID }, true, true, false, string.Empty) == false)
            {
                return(Error("发生了未知的错误,请联系管理员"));
            }

            PropResult result = Succeed();

            result.LogForUser = string.Format("您用道具对主题《{0}》进行了提升", thread.SubjectText);

            return(result);
        }
Пример #2
0
        public override PropResult Apply(HttpRequest request, int threadID, string param)
        {
            StringList paramList = StringList.Parse(param);

            int          timeLimit = int.Parse(paramList[0]);
            ThreadStatus stickType = StringUtil.TryParse <ThreadStatus>(paramList[1]);
            List <int>   forumIDs  = StringUtil.Split2 <int>(paramList[2], ',');
            string       unit      = paramList[3];

            BasicThread thread = PostBOV5.Instance.GetThread(threadID);

            if (thread == null)
            {
                return(Error("指定主题不存在"));
            }
            else if (thread.PostUserID != User.Current.UserID)
            {
                return(Error("本道具只能用于您本人发表的主题"));
            }
            else if (forumIDs.Contains(-1) == false && forumIDs.Contains(thread.ForumID) == false)
            {
                return(Error("目标主题所属版块不在本道具有效范围中"));
            }

            DateTime endDate = DateTimeUtil.Now;

            if (unit == "d")
            {
                endDate = endDate.AddDays(timeLimit);
            }
            else if (unit == "h")
            {
                endDate = endDate.AddHours(timeLimit);
            }
            else
            {
                endDate = endDate.AddMinutes(timeLimit);
            }


            PostBOV5.Instance.SetThreadsStickyStatus(User.Current, thread.ForumID, null, new int[] { threadID }, stickType, endDate, true, true, false, string.Empty);

            PropResult result = Succeed();

            if (stickType == ThreadStatus.GlobalSticky)
            {
                result.LogForUser = string.Format("您用道具对主题《{0}》进行{1}小时的全局置顶", thread.Subject, timeLimit);
            }
            else
            {
                result.LogForUser = string.Format("您用道具对主题《{0}》进行{1}小时的版块置顶", thread.Subject, timeLimit);
            }

            return(result);
        }
Пример #3
0
        public override PropResult Apply(HttpRequest request, int userID, string param)
        {
            int timeLimit = StringUtil.TryParse <int>(param);

            if (timeLimit <= 0)
            {
                return(Error("道具设置有误,请联系管理员"));
            }

            if (userID == User.Current.UserID)
            {
                return(Error("您不能对自己使用此道具"));
            }

            if (PropBO.Instance.TryUseProp(userID, typeof(PigAvatarProtectionProp).FullName))
            {
                PropResult result = Failed("道具的效果被对方的防御道具抵消了!");

                result.TargetUserID        = userID;
                result.LogForUser          = string.Format("您用道具把{0}的头像变成猪头,但是被对方的防御道具抵消了。", UserBO.Instance.GetUser(userID).PopupNameLink);
                result.LogForTargetUser    = string.Format("{0}用道具把您的头像变成猪头,但是被您的防御道具抵消了。", User.Current.PopupNameLink);
                result.NotifyForTargetUser = result.LogForTargetUser;

                return(result);
            }
            else
            {
                DateTime time = DateTime.Now.AddHours(timeLimit);

                if (UserBO.Instance.SetAttachAvatar(userID, this.AvatarSrc, time, false))
                // if(UserBO.Instance.UpdateAndLockAvatar(userID, this.AvatarSrc, time, string.Format("{0}对您使用了头像道具,您在{1}之前无法修改自己的头像", User.Current.PopupNameLink, time)))
                {
                    PropResult result = Succeed();

                    result.TargetUserID        = userID;
                    result.LogForUser          = string.Format("您用道具把{0}的头像变成猪头{1}小时。", UserBO.Instance.GetSimpleUser(userID).PopupNameLink, timeLimit);
                    result.LogForTargetUser    = string.Format("{0}用道具把您的头像变成猪头{1}小时", User.Current.PopupNameLink, timeLimit);
                    result.NotifyForTargetUser = string.Format("{0}用道具把您的头像变成了猪头", User.Current.PopupNameLink);

                    return(result);
                }
                else
                {
                    return(Error("道具使用失败了,可能对方正处于猪头状态。"));
                }
            }
        }
Пример #4
0
        public override PropResult Apply(HttpRequest request, int userID, string param)
        {
            if (userID == User.Current.UserID)
            {
                return(Error("您不能对自己使用本道具"));
            }

            User user = UserBO.Instance.GetUser(userID);

            if (user.IsOnline)
            {
                PropResult result = Succeed("用户“" + user.Username + "”当前处于在线状态。");

                result.TargetUserID        = userID;
                result.LogForUser          = string.Format("您对{0}使用了隐身探测道具。", UserBO.Instance.GetUser(userID).PopupNameLink);
                result.LogForTargetUser    = string.Format("{0}对您使用了隐身探测道具,但被您的隐身保护道具阻挡了。", User.Current.PopupNameLink);
                result.NotifyForTargetUser = result.LogForTargetUser;

                return(result);
            }
            else if (user.IsInvisible)
            {
                if (PropBO.Instance.TryUseProp(userID, typeof(OnlineProtectionProp).FullName) == false)
                {
                    PropResult result = Succeed("用户“" + user.Username + "”当前处于隐身状态。");

                    result.TargetUserID        = userID;
                    result.LogForUser          = string.Format("您对{0}使用了反隐身道具。", UserBO.Instance.GetUser(userID).PopupNameLink);
                    result.LogForTargetUser    = string.Format("{0}对您使用了反隐身道具,您的隐身状态被发现了。", User.Current.PopupNameLink);
                    result.NotifyForTargetUser = result.LogForTargetUser;

                    return(result);
                }
            }

            {
                PropResult result = Succeed("用户“" + user.Username + "”当前不在线。");

                result.TargetUserID        = userID;
                result.LogForUser          = string.Format("您对{0}使用了反隐身道具。", UserBO.Instance.GetUser(userID).PopupNameLink);
                result.LogForTargetUser    = string.Format("{0}对您使用了反隐身道具,正好您当时不在线。", User.Current.PopupNameLink);
                result.NotifyForTargetUser = result.LogForTargetUser;

                return(result);
            }
        }
Пример #5
0
        public override PropResult Apply(HttpRequest request, string param)
        {
            string newName = request.Form["newname"];

            using (ErrorScope es = new ErrorScope())
            {
                string oldName = User.Current.Name;

                UserBO.Instance.TryUpdateUsername(User.Current, User.Current.UserID, newName, true);

                if (es.HasError == false)
                {
                    PropResult result = Succeed();

                    result.LogForUser = string.Format("您使用改名工具将自己原有的“{0}”用户名改为了“{1}”", oldName, newName);

                    return(result);
                }
                else
                {
                    return(Error());
                }
            }
        }
        protected List<PropResult> ValidateProps(object obj, List<PropertyInfo> props)
        {
            var results = new List<PropResult>();

            foreach (var prop in props)
            {
                var result = new PropResult();

                result.Name = prop.Name;
                result.IsValid = true;

                if (prop.PropertyType == typeof(string))
                {
                    var value = prop.GetValue(obj, null) as string;

                    if (!string.IsNullOrEmpty(value))
                    { }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(Guid) ||
                   prop.PropertyType == typeof(Guid?))
                {
                    var value = prop.GetValue(obj, null) as Guid?;

                    if (value.HasValue && value.Value != default(Guid))
                    { }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(int) ||
                   prop.PropertyType == typeof(int?))
                {
                    var value = prop.GetValue(obj, null) as int?;

                    if (value.HasValue && value.Value > 0)
                    { }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(byte[]))
                {
                    var value = prop.GetValue(obj, null) as byte[];

                    if (value != null && value.Count() > 0)
                    { }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(object))
                {
                    var value = prop.GetValue(obj, null) as object;

                    if (value != null)
                    { }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }

                results.Add(result);
            }

            return results;
        }
        protected List <PropResult> ValidateProps(object obj, List <PropertyInfo> props)
        {
            var results = new List <PropResult>();

            foreach (var prop in props)
            {
                var result = new PropResult();

                result.Name    = prop.Name;
                result.IsValid = true;

                if (prop.PropertyType == typeof(string))
                {
                    var value = prop.GetValue(obj, null) as string;

                    if (!string.IsNullOrEmpty(value))
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(Guid) ||
                         prop.PropertyType == typeof(Guid?))
                {
                    var value = prop.GetValue(obj, null) as Guid?;

                    if (value.HasValue && value.Value != default(Guid))
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(int) ||
                         prop.PropertyType == typeof(int?))
                {
                    var value = prop.GetValue(obj, null) as int?;

                    if (value.HasValue && value.Value > 0)
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(byte[]))
                {
                    var value = prop.GetValue(obj, null) as byte[];

                    if (value != null && value.Count() > 0)
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(object))
                {
                    var value = prop.GetValue(obj, null) as object;

                    if (value != null)
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }

                results.Add(result);
            }

            return(results);
        }
        protected List <PropResult> ValidateProps(object obj, List <PropertyInfo> props)
        {
            var results = new List <PropResult>();

            foreach (var prop in props)
            {
                var result = new PropResult();

                result.Name    = prop.Name;
                result.IsValid = true;


                // Some properties can be 0, so we need to pass them as successes

                // Can't provision list with NoListTemplate template type #944
                // https://github.com/SubPointSolutions/spmeta2/issues/944

                if (prop.PropertyType == typeof(string))
                {
                    var value = prop.GetValue(obj, null) as string;

                    if (!string.IsNullOrEmpty(value))
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(Guid) ||
                         prop.PropertyType == typeof(Guid?))
                {
                    var value = prop.GetValue(obj, null) as Guid?;

                    if (value.HasValue && value.Value != default(Guid))
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(int) ||
                         prop.PropertyType == typeof(int?))
                {
                    var value = prop.GetValue(obj, null) as int?;

                    // any valud range?
                    // ExpectRequiredIntRange

                    var allowedRangeProperty = prop.GetCustomAttributes(typeof(ExpectRequiredIntRange), true)
                                               .FirstOrDefault() as ExpectRequiredIntRange;

                    if (allowedRangeProperty != null)
                    {
                        var minValue = allowedRangeProperty.MinValue;
                        var maxValue = allowedRangeProperty.MaxValue;

                        if (value.HasValue && (value.Value >= minValue && value.Value <= maxValue))
                        {
                        }
                        else
                        {
                            result.IsValid = false;
                        }
                    }
                    else
                    {
                        if (value.HasValue && value.Value > 0)
                        {
                        }
                        else
                        {
                            result.IsValid = false;
                        }
                    }
                }
                else if (prop.PropertyType == typeof(byte[]))
                {
                    var value = prop.GetValue(obj, null) as byte[];

                    if (value != null && value.Count() > 0)
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(object))
                {
                    var value = prop.GetValue(obj, null) as object;

                    if (value != null)
                    {
                    }
                    else
                    {
                        result.IsValid = false;
                    }
                }
                else if (prop.PropertyType == typeof(bool) ||
                         prop.PropertyType == typeof(bool?))
                {
                    var value = prop.GetValue(obj, null) as bool?;

                    // any valud range?
                    // ExpectRequiredBoolRange
                    var allowedBoolProperty = prop.GetCustomAttributes(typeof(ExpectRequiredBoolRange), true)
                                              .FirstOrDefault() as ExpectRequiredBoolRange;

                    if (allowedBoolProperty != null)
                    {
                        var allowedBoolPropertyValue = allowedBoolProperty.ExpectedValue;

                        if (value != null && value.HasValue)
                        {
                            result.IsValid = value == allowedBoolPropertyValue;
                        }
                        else
                        {
                            result.IsValid = false;
                        }
                    }
                    else
                    {
                        // all set 'boolean' values as to be true unless values are defined via ExpectRequiredBoolRange
                        if (value != null && value.HasValue)
                        {
                        }
                        else
                        {
                            result.IsValid = false;
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }

                results.Add(result);
            }

            return(results);
        }
Пример #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int?propID = _Request.Get <int>("id");

            if (propID == null)
            {
                ShowError("缺少必要的参数");
            }

            m_Prop = PropBO.Instance.GetPropByID(propID.Value);

            if (m_Prop == null)
            {
                ShowError("指定的道具不存在");
            }

            PropType propType = PropBO.GetPropType(m_Prop.PropType);

            if (propType == null)
            {
                ShowError("道具类型不存在,请联系管理员");
            }

            m_AutoUse = propType.IsAutoUse(m_Prop.PropParam);

            if (_Request.IsClick("buy"))
            {
                int count = _Request.Get <int>("count", 1);

                if (count <= 0)
                {
                    ShowError("够买数量必须大于0");
                    return;
                }

                using (ErrorScope es = new ErrorScope())
                {
                    if (m_AutoUse)
                    {
                        count = 1;
                    }

                    if (PropBO.Instance.BuyProp(My, propID.Value, count))
                    {
                        m_DisplayMessage = true;

                        if (m_AutoUse)
                        {
                            PropResult result = PropBO.Instance.UseProp(My, propID.Value, Request);

                            if (result.Type == PropResultType.Succeed)
                            {
                                ShowSuccess("道具购买并使用成功", 1);
                            }
                            else
                            {
                                ShowError("道具购买成功,但使用失败了,请联系网站管理员");
                            }
                        }
                        else
                        {
                            ShowSuccess("道具购买成功", 1);
                        }
                    }
                    else
                    {
                        m_DisplayMessage = true;

                        es.CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            ShowError(error.Message);
                        });
                    }
                }
            }
        }
Пример #10
0
        private static void CheckIfStringHasStringsBefore <T1, T2>(List <ValidationResult> result, PropResult valueResult,
                                                                   IEnumerable <string> symbols)
        {
            var stringValue = valueResult.Value as string;

            if (!string.IsNullOrEmpty(stringValue))
            {
                foreach (var ch in symbols)
                {
                    if (stringValue.StartsWith(ch))
                    {
                        result.Add(new ValidationResult
                        {
                            IsValid = false,
                            Message = string.Format("Property [{0}] of type [{1}] must not start with char:[{2}].",
                                                    valueResult.Name,
                                                    valueResult.ObjectType.FullName,
                                                    ch)
                        });
                    }
                }
            }
        }
Пример #11
0
        private static void CheckIfStringIsNoMoreThan <T1, T2>(List <ValidationResult> result, int lenght, PropResult valueResult)
        {
            var value = valueResult.Value as string;

            if (!string.IsNullOrEmpty(value) && value.Length > lenght)
            {
                result.Add(new ValidationResult
                {
                    PropertyName = valueResult.Name,
                    ResultType   = ValidationResultType.NoMoreThan,
                    IsValid      = false,
                    Message      = string.Format("Property [{0}] of type [{1}] must string with no more than [{2}] chars. Current lenght is: [{3}]",
                                                 valueResult.Name,
                                                 valueResult.ObjectType.FullName,
                                                 lenght,
                                                 value.Length)
                });
            }
        }
Пример #12
0
 private static void CheckIfString <TSource, TProperty>(List <ValidationResult> result, PropResult valueResult)
 {
     if (!(valueResult.Value is string))
     {
         result.Add(new ValidationResult
         {
             PropertyName = valueResult.Name,
             ResultType   = ValidationResultType.MustBeString,
             IsValid      = false,
             Message      = string.Format("Property [{0}] of type [{1}] must be string type.",
                                          valueResult.Name,
                                          valueResult.ObjectType.FullName)
         });
     }
 }
Пример #13
0
 private static void CheckIfStringIsNotNullOrEmpty <TSource, TProperty>(List <ValidationResult> result, PropResult valueResult)
 {
     if (string.IsNullOrEmpty(valueResult.Value as string))
     {
         result.Add(new ValidationResult
         {
             PropertyName = valueResult.Name,
             ResultType   = ValidationResultType.NotEmptyString,
             IsValid      = false,
             Message      = string.Format("Property [{0}] of type [{1}] must be not null and not empty string.",
                                          valueResult.Name,
                                          valueResult.ObjectType.FullName)
         });
     }
 }
Пример #14
0
        private static void CheckIfStringHasSpacesBeforeOrAfter <T1, T2>(List <ValidationResult> result, PropResult valueResult)
        {
            var stringValue = valueResult.Value as string;

            if (!string.IsNullOrEmpty(stringValue))
            {
                if (stringValue.StartsWith(" "))
                {
                    result.Add(new ValidationResult
                    {
                        PropertyName = valueResult.Name,
                        ResultType   = ValidationResultType.NoSpacesBeforeOrAfter,
                        IsValid      = false,
                        Message      = string.Format("Property [{0}] of type [{1}] must not start with space.",
                                                     valueResult.Name,
                                                     valueResult.ObjectType.FullName)
                    });
                }

                if (stringValue.EndsWith(" "))
                {
                    result.Add(new ValidationResult
                    {
                        PropertyName = valueResult.Name,
                        ResultType   = ValidationResultType.NoSpacesBeforeOrAfter,
                        IsValid      = false,
                        Message      = string.Format("Property [{0}] of type [{1}] must not end with space.",
                                                     valueResult.Name,
                                                     valueResult.ObjectType.FullName)
                    });
                }
            }
        }
Пример #15
0
        public override PropResult Apply(HttpRequest request, int threadID, string param)
        {
            StringList paramList = StringList.Parse(param);

            int        timeLimit = int.Parse(paramList[0]);
            string     color     = paramList[1];
            List <int> forumIDs  = StringUtil.Split2 <int>(paramList[2], ',');
            string     unit      = paramList[3];

            string style = color;

            if (paramList.Count > 4)
            {
                string font_family = paramList[4];
                string font_size   = paramList[5];
                string font_style  = paramList[6];
                string font_color  = paramList[7];
                string back_color  = paramList[8];

                style = string.Empty;

                if (string.IsNullOrEmpty(font_family) == false)
                {
                    style += "font-family:" + font_family + ";";
                }

                if (string.IsNullOrEmpty(font_size) == false)
                {
                    style += "font-size:" + font_size + ";";
                }

                if (font_style != null)
                {
                    if (font_style.Contains("bold"))
                    {
                        style += "font-weight:bold;";
                    }

                    if (font_style.Contains("italic"))
                    {
                        style += "font-style:italic;";
                    }

                    if (font_style.Contains("underline"))
                    {
                        if (font_style.Contains("linethrough"))
                        {
                            style += "text-decoration: underline line-through;";
                        }
                        else
                        {
                            style += "text-decoration: underline;";
                        }
                    }
                    else if (font_style.Contains("linethrough"))
                    {
                        style += "text-decoration: line-through;";
                    }
                }

                if (string.IsNullOrEmpty(font_color) == false)
                {
                    style += "color:" + font_color + ";";
                }

                if (string.IsNullOrEmpty(back_color) == false)
                {
                    style += "background-color:" + back_color + ";";
                }
            }

            BasicThread thread = PostBOV5.Instance.GetThread(threadID);

            if (thread == null)
            {
                return(Error("指定主题不存在"));
            }
            else if (thread.PostUserID != User.Current.UserID)
            {
                return(Error("本道具只能用于您本人发表的主题"));
            }
            else if (forumIDs.Contains(-1) == false && forumIDs.Contains(thread.ForumID) == false)
            {
                return(Error("目标主题所属版块不在本道具有效范围中"));
            }

            DateTime endDate = DateTimeUtil.Now;

            if (unit == "d")
            {
                endDate = endDate.AddDays(timeLimit);
            }
            else if (unit == "h")
            {
                endDate = endDate.AddHours(timeLimit);
            }
            else
            {
                endDate = endDate.AddMinutes(timeLimit);
            }

            PostBOV5.Instance.SetThreadsSubjectStyle(User.Current, thread.ForumID, new int[] { threadID }, style, endDate, true, true, false, string.Empty);

            PropResult result = Succeed();

            result.LogForUser = string.Format("您用道具对主题《{0}》进行{1}小时的标题加亮", thread.Subject, timeLimit);

            return(result);
        }
Пример #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            m_PropID = _Request.Get <int>("propid", -1);

            if (m_PropID != -1)
            {
                m_Prop = PropBO.Instance.GetUserProp(MyUserID, m_PropID);

                if (m_Prop == null)
                {
                    m_PropID = -1;
                }
                else
                {
                    PropType propType = PropBO.GetPropType(m_Prop.PropType);

                    if (propType == null)
                    {
                        m_PropID = -1;
                    }
                    else
                    {
                        m_PropHtml = propType.GetPropApplyFormHtml(Request);
                    }
                }
                if (m_Prop == null)
                {
                    ShowError("您选择的道具不存在");
                }
            }

            if (m_PropID == -1)
            {
                m_PropList = PropBO.Instance.GetUserProps(My);

                PropTypeCategory?category = _Request.Get <PropTypeCategory>("cat");

                if (category != null)
                {
                    for (int i = 0; i < m_PropList.Count;)
                    {
                        PropType type = PropBO.GetPropType(m_PropList[i].PropType);

                        if (type.Category != category.Value)
                        {
                            if (type.Category == PropTypeCategory.User && (category.Value == PropTypeCategory.Thread || category.Value == PropTypeCategory.ThreadReply))
                            {
                                i++;
                            }
                            else
                            {
                                m_PropList.RemoveAt(i);
                            }
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if (m_PropList.Count == 0)
                    {
                        ShowError("在您的道具包中,没有找到适合当前场景使用的道具。");
                    }
                }
            }

            if (_Request.IsClick("use"))
            {
                using (ErrorScope es = new ErrorScope())
                {
                    PropResult result = PropBO.Instance.UseProp(My, m_PropID, Request);

                    if (result.Type == PropResultType.Succeed)
                    {
                        ShowSuccess(string.IsNullOrEmpty(result.Message) ? "道具使用成功!" : result.Message, true);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(result.Message))
                        {
                            es.CatchError <ErrorInfo>(delegate(ErrorInfo error)
                            {
                                ShowError(error);
                            });
                        }
                        else
                        {
                            ShowError(result.Message);
                        }
                    }
                }
            }
        }