public HttpResponseMessage GetTopGold(string count)
        {
            var icount = typeParser.intParse(count);

            if (icount > 10 || icount < 1)
            {
                icount = 10;
            }
            var ttop = ADatabaseConfigsManager.avatarDB.FindManyData(ADatabaseConfigsManager.tAvatarData, ADBAccessor.filter_Gte(InfoNameDefs.AvatarLevel, 0), ADBAccessor.projections(InfoNameDefs.AvatarName, InfoNameDefs.AvatarGold), icount, 0, ADBAccessor.sort_Descending(InfoNameDefs.AvatarGold));
            List <List <string> > lresults = new List <List <string> >();

            foreach (var t in ttop)
            {
                if (t.Contains(InfoNameDefs.AvatarGold) && t.Contains(InfoNameDefs.AvatarName))
                {
                    var l = new List <string>();
                    l.Add(InfoNameDefs.AvatarName);
                    l.Add(t[InfoNameDefs.AvatarName].ToString());
                    l.Add("value");
                    l.Add(t[InfoNameDefs.AvatarGold].ToString());
                    lresults.Add(l);
                }
            }
            return(ResultToJson.GetJsonResponse(ResultToJson.JsonFormatArray("r", lresults)));
        }
        public HttpResponseMessage CheckToken(string username, string token)
        {
            var eCheck = ATokenManager.Instance.OnCheckToken(username, token);

            if (!eCheck)
            {
                return(ResultToJson.GetErrorJsonResponse("Invalid token."));
            }
            return(ResultToJson.GetJsonResponse(InfoNameDefs.UserToken, token));
        }
    public HttpResponseMessage GetAllParamResponse()
    {
        var ps  = componentParam.AllParamsToSync;
        var obj = new JObject();

        foreach (var p in ps)
        {
            obj[p] = OnGetStringParamValue(p);
        }
        var res = new JObject();

        res["avatar"] = obj;
        return(ResultToJson.GetJsonResponse(res));
    }
Exemple #4
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())));
        }
    public HttpResponseMessage GetDiryParamResponse(params string[] extraParams)
    {
        var obj = GetDirtyParams();

        if (extraParams.Length > 0)
        {
            if (extraParams.Length % 2 != 0)
            {
                throw new Exception("Invalid extraParam length");
            }
            for (var i = 0; i < extraParams.Length; i += 2)
            {
                obj[extraParams[i]] = extraParams[i + 1];
            }
        }
        return(ResultToJson.GetJsonResponse(obj));
    }
        public HttpResponseMessage GetOne(string username, string token)
        {
            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 q = avatar.OnGetOneQuestion();

            return(ResultToJson.GetJsonResponse("q", q));
        }
Exemple #7
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 Login(string username, string password)
        {
            var res = ADatabaseConfigsManager.userDB.FindOneData(ADatabaseConfigsManager.tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username) & ADBAccessor.filter_eq(InfoNameDefs.UserPassword, MD5String.Hash32(password)));

            if (res == null)
            {
                return(ResultToJson.GetErrorJsonResponse("Username and password mismatch."));
            }
            var token = "";

            if (res.Contains(InfoNameDefs.UserToken))
            {
                token = res[InfoNameDefs.UserToken].ToString();
            }
            else
            {
                token = AWebServerUtils.GetEncryptCode(12);
                ADatabaseConfigsManager.userDB.UpdateOneData(ADatabaseConfigsManager.tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username), ADBAccessor.update(InfoNameDefs.UserToken, token));
            }
            return(ResultToJson.GetJsonResponse(InfoNameDefs.UserToken, res[InfoNameDefs.UserToken].ToString()));
        }
Exemple #9
0
        public HttpResponseMessage Register(string username, string password, string mail)
        {
            if (!mail.Contains("@") || !mail.Contains(".") || mail.IndexOf("@") > mail.IndexOf("."))
            {
                return(ResultToJson.GetErrorJsonResponse("Invalid mail address."));
            }

            if (username.Length < 4)
            {
                return(ResultToJson.GetErrorJsonResponse("Too short username."));
            }
            if (username.Length > 16)
            {
                return(ResultToJson.GetErrorJsonResponse("Too long username."));
            }

            var res = ADatabaseConfigsManager.userDB.FindOneData(ADatabaseConfigsManager.tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username));

            if (res != null)
            {
                return(ResultToJson.GetErrorJsonResponse("Username registered."));
            }
            var token = AWebServerUtils.GetEncryptCode(12);
            var ures  = ADatabaseConfigsManager.userDB.UpdateOneData(ADatabaseConfigsManager.tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                                                     , ADBAccessor.updates_build(
                                                                         ADBAccessor.update(InfoNameDefs.UserToken, token)
                                                                         , ADBAccessor.update(InfoNameDefs.Username, username)
                                                                         , ADBAccessor.update(InfoNameDefs.UserMail, mail)
                                                                         , ADBAccessor.update(InfoNameDefs.UserPassword, MD5String.Hash32(password))
                                                                         )
                                                                     , true);

            if (!ures)
            {
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.DBError));
            }

            ATokenManager.Instance.OnSetToken(username, token);
            return(ResultToJson.GetJsonResponse(InfoNameDefs.Username, username, InfoNameDefs.UserToken, token));
        }
        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"));
        }