Example #1
0
    internal List <ChatMessage> OnGetHistory(string targetUsername, int page, int count)
    {
        var lcm   = new List <ChatMessage>();
        var start = page * count;
        var res   = AWebServices.Avatar.dbavatar.FindManyData(TableChat
                                                              , (ADBAccessor.filter_eq(InfoNameDefs.SenderName, username)
                                                                 & ADBAccessor.filter_eq(InfoNameDefs.TargetName, targetUsername))
                                                              | (ADBAccessor.filter_eq(InfoNameDefs.SenderName, targetUsername)
                                                                 & ADBAccessor.filter_eq(InfoNameDefs.TargetName, username))
                                                              , null, count, start
                                                              , ADBAccessor.sort_Descending(InfoNameDefs.SendTime));

        foreach (var r in res)
        {
            ChatMessage cm     = new ChatMessage();
            var         sender = AAvatarManager.Instance.OnGetAvatar(r[InfoNameDefs.SenderName].AsString);
            var         target = AAvatarManager.Instance.OnGetAvatar(r[InfoNameDefs.TargetName].AsString);
            cm.s  = sender.AvatarName;
            cm.t  = target.AvatarName;
            cm.h  = sender.AvatarHead;
            cm.tm = r[InfoNameDefs.SendTime].AsInt32;
            cm.c  = r[InfoNameDefs.SendContent].AsString.Replace("[", "").Replace("]", "").Replace("\"", "").Replace("\'", "");
            cm.tp = r[InfoNameDefs.ChatType].AsInt32;
            lcm.Add(cm);
        }
        return(lcm);
    }
        public void avatargetrank(string username, string token, string ranktype, string count)
        {
            int icount = typeParser.intParse(count);

            if (icount <= 0 || icount > 100)
            {
                SendError("Invalid count " + count);
                return;
            }
            var iranktype = typeParser.intParse(ranktype);

            if (iranktype < 0 || iranktype >= (int)ERankType.RankNum)
            {
                SendError("Invalid ranktype " + ranktype);
                return;
            }
            var a = GetAvatar(username, token);

            if (a != null)
            {
                switch ((ERankType)iranktype)
                {
                case ERankType.Money:
                    var res = dbavatar.FindManyData(TableName, null
                                                    , ADBAccessor.projections(InfoNameDefs.AvatarName, InfoNameDefs.AvatarMoney, InfoNameDefs.AvatarHead)
                                                    , icount, 0, ADBAccessor.sort_Descending(InfoNameDefs.AvatarMoney));
                    var lres = new List <List <string> >();
                    foreach (var r in res)
                    {
                        var l = new List <string>();
                        l.Add(InfoNameDefs.AvatarName);
                        l.Add(r[InfoNameDefs.AvatarName].AsString);
                        if (r.Contains(InfoNameDefs.AvatarMoney))
                        {
                            l.Add(InfoNameDefs.AvatarMoney);
                            l.Add(r[InfoNameDefs.AvatarMoney].ToString());
                        }
                        if (r.Contains(InfoNameDefs.AvatarHead))
                        {
                            l.Add(InfoNameDefs.AvatarHead);
                            l.Add(r[InfoNameDefs.AvatarHead].AsInt32.ToString());
                        }
                        lres.Add(l);
                    }
                    SendError("rs", AWebServerUtils.ToJsonArray(lres.ToArray()));
                    return;
                }
                SendError("Invalid ranktype " + ranktype);
            }
        }
        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)));
        }