Exemplo n.º 1
0
        public HttpResponseMessage SelectAvatar(string username, string token)
        {
            if (!ATokenManager.Instance.OnCheckToken(username, token))
            {
                return(ResultToJson.GetErrorJsonResponse("Invalid token."));
            }
            var avatar = AAvatarManager.Instance.OnGetAvatar(username);

            if (avatar == null)
            {
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.NoAvatar));
            }
            return(ResultToJson.GetJsonResponse("avatar", ResultToJson.JsonFormat(avatar.ToAll())));
        }
Exemplo n.º 2
0
        public HttpResponseMessage CreateAvatar(string username, string token, string avatarname, string sex)
        {
            var check = ATokenManager.Instance.OnCheckToken(username, token);

            if (!check)
            {
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.InvalidToken));
            }
            avatarname = CommonUtil.filtername(avatarname);
            var len = CommonUtil.GetStringLength(avatarname);

            if (len <= 2 || len > 12)
            {
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.AvatarNameInvalidLength));
            }
            var isex = typeParser.intParse(sex);

            if (isex != 0 && isex != 1)
            {
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.InvalidSex));
            }
            {
                var a = AAvatarManager.Instance.OnGetAvatar(username);
                if (a != null)
                {
                    return(ResultToJson.GetErrorJsonResponse(ErrorDefs.AlreadyHasAvatar));
                }
            }
            var findRes = ADatabaseConfigsManager.avatarDB.FindOneData(ADatabaseConfigsManager.tAvatarData, ADBAccessor.filter_eq(InfoNameDefs.AvatarName, avatarname));

            if (findRes != null && findRes.Contains(InfoNameDefs.AvatarName))
            {
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.DuplicateAvatarName));
            }
            else
            {
                var avatar = AAvatarManager.Instance.OnCreateAvatar(username, avatarname, isex);
                if (avatar != null)
                {
                    return(ResultToJson.GetJsonResponse("avatar", ResultToJson.JsonFormat(avatar.ToAll())));
                }
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.DBError));
            }
        }
        public HttpResponseMessage Answer(string username, string token, string answer)
        {
            var eCheck = ATokenManager.Instance.OnCheckToken(username, token);

            if (!eCheck)
            {
                return(ResultToJson.GetErrorJsonResponse("Invalid token."));
            }
            var avatar = AAvatarManager.Instance.OnGetAvatar(username);

            if (avatar == null)
            {
                return(ResultToJson.GetErrorJsonResponse("No avatar."));
            }
            var res = avatar.OnAnswer(answer);

            if (res)
            {
                return(ResultToJson.GetJsonResponse("avatar", ResultToJson.JsonFormat(avatar.GetDirtyParams())));
            }
            return(ResultToJson.GetErrorJsonResponse("wrong"));
        }