public override void InitComponent()
    {
        var result = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname)
                     .FindOneData(tableName, ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ownerServer.objectId), null);

        if (result != null)
        {
            foreach (var r in result)
            {
                if (r.Name.StartsWith(ParamNameDefs.BagSlotPre))
                {
                    var itemID  = r.Name.Substring(ParamNameDefs.BagSlotPre.Length);
                    var itemNum = r.Value.AsInt32;
                    DoAddItem(typeParser.intParse(itemID), itemNum);
                }
            }
        }
        else
        {
            ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(tableName, ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ownerServer.objectId)
                                                                                        , ADBAccessor.updates_build(ADBAccessor.update(ParamNameDefs.AvatarName, owner.OnGetStringParamValue(ParamNameDefs.AvatarName))), true);
        }
    }
Esempio n. 2
0
        AWikiCell OnLoadWikiCellWithContent(string id)
        {
            var       i    = typeParser.intParse(id);
            AWikiCell cell = OnGetWiki(id);

            if (cell == null || string.IsNullOrEmpty(cell.content))
            {
                var r = adb.FindOneData(TableName, ADBAccessor.filter_eq("i", i)
                                        , ADBAccessor.projections("s", "c", "t"));
                if (r == null)
                {
                    SendError("1");
                    return(null);
                }
                if (cell == null)
                {
                    cell = new AWikiCell();
                }
                cell.id      = i;
                cell.content = r["c"].AsString;
                cell.time    = r["t"].AsString;
                cell.subject = r["s"].AsString;
                if (r.Contains("lt"))
                {
                    cell.lastmodifytime = r["lt"].AsString;
                }
                if (dWikis.ContainsKey(cell.id))
                {
                    dWikis[cell.id] = cell;
                }
                else
                {
                    dWikis.Add(cell.id, cell);
                }
            }
            return(cell);
        }
        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);

            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);

            ATokenManager.Instance.OnSetToken(username, token);
            return(ResultToJson.GetJsonResponse(InfoNameDefs.Username, username, InfoNameDefs.UserToken, token));
        }
    public bool OnCheckToken(string username, string token)
    {
        var eCheck = DoCheckToken(username, token);

        if (eCheck == ECheckTokenResult.NotInCache)
        {
            var res = ADatabaseConfigsManager.userDB.FindOneData(ADatabaseConfigsManager.tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username) & ADBAccessor.filter_eq(InfoNameDefs.UserToken, token));
            if (res == null)
            {
                return(false);
            }
        }
        else if (eCheck == ECheckTokenResult.Invalid)
        {
            return(false);
        }
        OnSetToken(username, token);
        return(true);
    }
    public override void OnAddItem(int itemID, int count)
    {
        base.OnAddItem(itemID, count);

        if (dItems.ContainsKey(itemID))
        {
            ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(tableName, ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ownerServer.objectId),
                                                                                        ADBAccessor.updates_build(ADBAccessor.update(ParamNameDefs.BagSlotPre + itemID, dItems[itemID])), true);
        }
        else
        {
            ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(tableName, ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ownerServer.objectId),
                                                                                        ADBAccessor.updates_build(ADBAccessor.update_unset(ParamNameDefs.BagSlotPre + itemID)));
        }
    }
Esempio n. 6
0
    public AAvatarServer OnCreateAvatar(EPartnerID ePartnerID, string uid, string avatarName, int sex, Player player)
    {
        var oid  = ObjectId.GenerateNewId();
        var inst = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(ParamNameDefs.TableAvatar
                                                                                               , ADBAccessor.filter_eq(ParamNameDefs.UID, uid) & ADBAccessor.filter_eq(ParamNameDefs.PartnerID, (int)ePartnerID) & ADBAccessor.filter_eq(ParamNameDefs.AvatarName, avatarName)
                                                                                               , ADBAccessor.updates_build(ADBAccessor.update(ParamNameDefs.AvatarSex, sex), ADBAccessor.update(ParamNameDefs.CollectionID, oid)), true);
        var a = new AAvatarServer(uid, null, oid, player);

        OnAddAvatar(a, player);
        return(a);
    }
 private void DoSaveFriend(string f1, string f2, string requester = "")
 {
     ADatabaseConfigsManager.avatarDB.UpdateOneData(TableName
                                                    , (ADBAccessor.filter_eq(InfoNameDefs.Friend1, f1) & ADBAccessor.filter_eq(InfoNameDefs.Friend2, f2))
                                                    | (ADBAccessor.filter_eq(InfoNameDefs.Friend1, f2) & ADBAccessor.filter_eq(InfoNameDefs.Friend2, f1))
                                                    , ADBAccessor.updates_build(ADBAccessor.update(InfoNameDefs.Friend1, f1)
                                                                                , ADBAccessor.update(InfoNameDefs.Friend2, f2)
                                                                                , (string.IsNullOrEmpty(requester)
                 ? ADBAccessor.update_unset(InfoNameDefs.FriendRequester)
                 : ADBAccessor.update(InfoNameDefs.FriendRequester, requester))), true);
 }
        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(avatar.GetAllParamResponse());
                }
                return(ResultToJson.GetErrorJsonResponse(ErrorDefs.DBError));
            }
        }
    private AAvatar LoadFromDB(string username)
    {
        var result = ADatabaseConfigsManager.avatarDB.FindOneData(ADatabaseConfigsManager.tAvatarData, ADBAccessor.filter_eq(InfoNameDefs.Username, username), null);

        if (result != null && result.Contains(InfoNameDefs.AvatarName))
        {
            var a = new AAvatar(username, result[InfoNameDefs.AvatarName].AsString, result);
            OnAddAvatar(a);
            return(a);
        }
        return(null);
    }
Esempio n. 10
0
    public override void OnSave()
    {
        if (lDirtyParams.Count == 0)
        {
            return;
        }
        var u = new List <UpdateDefinition <BsonDocument> >();

        foreach (var v in lDirtyParams)
        {
            if (!dParams.ContainsKey(v))
            {
                AOutput.LogError("Cannot find param " + v);
                return;
            }
            var aparam = dParams[v];
            switch (aparam.eParamType)
            {
            case EParamType.String:
                u.Add(ADBAccessor.update(v, aparam.sParamValue));
                break;

            case EParamType.Double:
                u.Add(ADBAccessor.update(v, aparam.dParamValue));
                break;

            case EParamType.Int:
                u.Add(ADBAccessor.update(v, aparam.iParamValue));
                break;

            case EParamType.Long:
                u.Add(ADBAccessor.update(v, aparam.lParamValue));
                break;
            }
        }
        ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(ParamNameDefs.TableAvatar
                                                                                    , ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ownerServer.objectId),
                                                                                    Builders <BsonDocument> .Update.Combine(u));

        AOutput.Log("avatar " + owner.OnGetStringParamValue(ParamNameDefs.AvatarName) + " saved " + lDirtyParams.Count + " params");
        var update = new LibPacket.PktParamUpdate();

        foreach (var dp in lDirtyParams)
        {
            var info = new LibPacket.ParamInfo();
            info.paramName  = dp;
            info.paramValue = OnGetStringParamValue(dp);
            update.lInfos.Add(info);
        }
        ownerServer.OnSendToClient(update);

        lDirtyParams.Clear();
    }
        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 override void InitComponent()
    {
        var result = ADatabaseConfigsManager.avatarDB.FindOneData(tableName, ADBAccessor.filter_eq(InfoNameDefs.AvatarName, owner.OnGetStringParamValue(InfoNameDefs.AvatarName)), null);

        if (result != null && result.Contains(InfoNameDefs.AvatarName))
        {
            foreach (var r in result)
            {
                if (r.Name.StartsWith(InfoNameDefs.BagSlotPre))
                {
                    var itemID  = r.Name.Substring(InfoNameDefs.BagSlotPre.Length);
                    var itemNum = r.Value.AsInt32;
                    DoAddItem(typeParser.intParse(itemID), itemNum);
                }
            }
        }
        else
        {
            ADatabaseConfigsManager.avatarDB.UpdateOneData(tableName, ADBAccessor.filter_eq(InfoNameDefs.AvatarName, owner.OnGetStringParamValue(InfoNameDefs.AvatarName))
                                                           , ADBAccessor.updates_build(ADBAccessor.update(InfoNameDefs.AvatarName, owner.OnGetStringParamValue(InfoNameDefs.AvatarName))), true);
        }
    }
Esempio n. 13
0
        private void Handler_EnterGame(IResponer responer, PktEnterGameRequest vo)
        {
            var player = AAvatarManager.Instance.OnGetPlayer(responer.playerConnDesc);

            if (player == null)
            {
                return;
            }

            var res = new PktEnterGameResult();
            var dbr = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).FindOneData(ParamNameDefs.TableAvatar
                                                                                                , ADBAccessor.filter_eq(ParamNameDefs.PartnerID, (int)player.ePartnerID) & ADBAccessor.filter_eq(ParamNameDefs.UID, player.uid));

            if (dbr != null)
            {
                var a = AAvatarManager.Instance.OnGetAvatar(player.uid);
                if (a == null)
                {
                    a = AAvatarManager.Instance.OnCreateAvatar(player.uid, dbr, player);
                }
                res.info = a.ToPkt();
            }
            responer.Response(res);
        }
Esempio n. 14
0
        private void Handler_CreateAvatar(IResponer responer, PktCreateAvatarRequest vo)
        {
            var player = AAvatarManager.Instance.OnGetPlayer(responer.playerConnDesc);

            if (player == null)
            {
                return;
            }
            if (player.avatar != null)
            {
                return;
            }

            var res = new PktCreateAvatarResult();
            var dbr = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).FindOneData(ParamNameDefs.TableAvatar
                                                                                                , ADBAccessor.filter_eq(ParamNameDefs.PartnerID, (int)player.ePartnerID) & ADBAccessor.filter_eq(ParamNameDefs.UID, player.uid));

            if (dbr != null)
            {
                res.eResult = PktCreateAvatarResult.EResult.MaxCount;
            }
            else
            {
                var dnr = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).FindOneData(ParamNameDefs.TableAvatar
                                                                                                    , ADBAccessor.filter_eq(ParamNameDefs.AvatarName, vo.avatarName));
                if (dnr != null)
                {
                    res.eResult = PktCreateAvatarResult.EResult.SameName;
                }
                else
                {
                    res.eResult = PktCreateAvatarResult.EResult.Success;

                    var a = AAvatarManager.Instance.OnCreateAvatar(player.ePartnerID, player.uid, vo.avatarName, vo.sex, player);
                    res.info = a.ToPkt();
                }
            }
            responer.Response(res);
        }
Esempio n. 15
0
        public static void Tick()
        {
            if (CakeCache.dIDDirtyParams.Count > 0)
            {
                foreach (var idk in CakeCache.dIDDirtyParams)
                {
                    var filter = ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ObjectId.Parse(idk.Key));
                    foreach (var cakeTypek in idk.Value)
                    {
                        var lupdate = new List <UpdateDefinition <BsonDocument> >();
                        var vs      = cakeTypek.Value.Values.ToArray();
                        foreach (var pv in vs)
                        {
                            lupdate.Add(pv.GetUpdate());
                        }
                        ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(cakeTypek.Key, filter
                                                                                                    , Builders <BsonDocument> .Update.Combine(lupdate));
                    }

                    if (!dAccessTimes.ContainsKey(idk.Key))
                    {
                        dAccessTimes.Add(idk.Key, DateTime.Now);
                    }
                    else
                    {
                        dAccessTimes[idk.Key] = DateTime.Now;
                    }
                }
                CakeCache.dIDDirtyParams.Clear();
            }
            if (CakeCache.dIIDDirtyParams.Count > 0)
            {
                foreach (var idk in CakeCache.dIIDDirtyParams)
                {
                    var ll = idk.Value.ToArray();
                    foreach (var iidk in ll)
                    {
                        var filter = ADBAccessor.filter_eq(ParamNameDefs.OwnerID, idk.Key)
                                     & ADBAccessor.filter_eq(ParamNameDefs.ContentID, iidk.Key);
                        var lll = iidk.Value.ToArray();
                        foreach (var cakeTypek in lll)
                        {
                            var lupdate = new List <UpdateDefinition <BsonDocument> >();
                            var llll    = cakeTypek.Value.ToArray();
                            foreach (var pv in llll)
                            {
                                lupdate.Add(pv.Value.GetUpdate());
                            }
                            lupdate.Add(ADBAccessor.update(ParamNameDefs.ContentID, iidk.Key));
                            lupdate.Add(ADBAccessor.update(ParamNameDefs.OwnerID, idk.Key));
                            ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).UpdateOneData(cakeTypek.Key, filter
                                                                                                        , Builders <BsonDocument> .Update.Combine(lupdate), true);
                        }
                    }

                    if (!dAccessTimes.ContainsKey(idk.Key))
                    {
                        dAccessTimes.Add(idk.Key, DateTime.Now);
                    }
                    else
                    {
                        dAccessTimes[idk.Key] = DateTime.Now;
                    }
                }
                CakeCache.dIIDDirtyParams.Clear();
            }
            var remove = new List <string>();

            foreach (var dk in dAccessTimes)
            {
                if (APlayerManager.Instance.IsOnline(dk.Key))
                {
                    continue;
                }
                if ((DateTime.Now - dk.Value).TotalSeconds > 30)
                {
                    remove.Add(dk.Key);
                }
            }
            foreach (var r in remove)
            {
                dAccessTimes.Remove(r);
                if (CakeCache.dIDDirtyParams.ContainsKey(r))
                {
                    CakeCache.dIDDirtyParams.Remove(r);
                }
                if (CakeCache.dIIDDirtyParams.ContainsKey(r))
                {
                    CakeCache.dIIDDirtyParams.Remove(r);
                }
            }
        }
        private void GameHandler_CreateAvatar(IResponer responer, PktCreateAvatarRequest vo)
        {
            var player = APlayerManager.Instance.OnGetPlayerByConn(responer.playerConnDesc);

            if (player == null)
            {
                return;
            }
            var res = new PktCreateAvatarResult();
            {
                var dbr = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).FindOneData(ParamNameDefs.TableAvatar
                                                                                                    , ADBAccessor.filter_eq(ParamNameDefs.AvatarName, vo.avatarName)
                                                                                                    | ADBAccessor.filter_eq(ParamNameDefs.UnionID, player.unionid)
                                                                                                    , ADBAccessor.projections(ParamNameDefs.AvatarLevel));
                if (dbr != null)
                {
                    res.eResult = PktCreateAvatarResult.EResult.SameName;
                    responer.Response(res);
                    return;
                }
            }
            {
                var dbr = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).FindOneData(ParamNameDefs.TableAvatar
                                                                                                    , ADBAccessor.filter_eq(ParamNameDefs.UnionID, player.unionid), ADBAccessor.projections(ParamNameDefs.AvatarLevel));
                if (dbr != null)
                {
                    res.eResult = PktCreateAvatarResult.EResult.MaxCount;
                    responer.Response(res);
                    return;
                }
            }
            var psid = ObjectId.GenerateNewId().ToString();
            var cake = new CakeAvatar(psid);

            cake.Create(player.unionid, player.ePartnerID, vo.avatarName, vo.sex);
            APlayerManager.Instance.OnAddAvatar(cake, player);
            res.info    = cake.ToPkt();
            res.eResult = PktCreateAvatarResult.EResult.Success;
            responer.Response(res);
        }
        private void GameHandler_EnterGame(IResponer responer, PktEnterGameRequest vo)
        {
            var player = APlayerManager.Instance.OnGetPlayerByConn(responer.playerConnDesc);

            if (player == null)
            {
                return;
            }

            var res = new PktEnterGameResult();
            var dbr = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname).FindOneData(ParamNameDefs.TableAvatar
                                                                                                , ADBAccessor.filter_eq(ParamNameDefs.PartnerID, (int)player.ePartnerID) & ADBAccessor.filter_eq(ParamNameDefs.UnionID, player.unionid));

            if (dbr != null)
            {
                var c = new CakeAvatar(dbr[ParamNameDefs.CollectionID].ToString());
                APlayerManager.Instance.OnAddAvatar(c, player);
                res.info = c.ToPkt();
            }
            responer.Response(res);
        }
    internal AAvatar OnCreateAvatar(string username, string avatarname, int isex)
    {
        var updateRes = ADatabaseConfigsManager.avatarDB.UpdateOneData(ADatabaseConfigsManager.tAvatarData, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                                                       , ADBAccessor.updates_build(
                                                                           ADBAccessor.update(InfoNameDefs.AvatarName, avatarname)
                                                                           )
                                                                       , true);

        if (updateRes)
        {
            var a = new AAvatar(username, avatarname, null);
            OnAddAvatar(a);

            a.OnSetParamValue(InfoNameDefs.AvatarName, avatarname);
            a.OnSetParamValue(InfoNameDefs.AvatarSex, isex);
            return(a);
        }
        return(null);
    }
        public void avatarcreate(string username, string token, string avatarname, string sex)
        {
            avatarname = filtername(avatarname);
            var len = CommonUtil.GetStringLength(avatarname);

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

            if (isex != 0 && isex != 1)
            {
                SendError(ErrorDefs.InvalidSex);
                return;
            }
            var check = CheckToken(username, token);

            if (!check)
            {
                SendError(ErrorDefs.InvalidToken);
                return;
            }
            {
                var a = AAvatarManager.Instance.OnGetAvatar(username);
                if (a != null)
                {
                    SendError(ErrorDefs.AlreadyHasAvatar);
                    return;
                }
            }
            var findRes = dbavatar.FindOneData(TableName, ADBAccessor.filter_eq(InfoNameDefs.AvatarName, avatarname));

            if (findRes != null && findRes.Contains(InfoNameDefs.AvatarName))
            {
                SendError(ErrorDefs.DuplicateAvatarName);
            }
            else
            {
                var updateRes = dbavatar.UpdateOneData(TableName, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                                       , ADBAccessor.updates_build(
                                                           ADBAccessor.update(InfoNameDefs.AvatarName, avatarname)
                                                           )
                                                       , true);
                if (updateRes)
                {
                    var a = new AAvatar(username, avatarname, null);
                    AAvatarManager.Instance.OnAddAvatar(a);

                    a.OnSetParamValue(InfoNameDefs.AvatarName, avatarname);
                    a.OnSetParamValue(InfoNameDefs.AvatarSex, isex);
                    a.OnSetParamValue(InfoNameDefs.AvatarMoney, 1000);
                    a.OnSetParamValue(InfoNameDefs.AvatarGold, 1000);
                    SendError(InfoNameDefs.AvatarName, avatarname);
                }
                else
                {
                    SendDBError();
                }
            }
        }
Esempio n. 20
0
        public void accountlogin(string username, string password)
        {
            if (username == "fs" && password == "111")
            {
                if (!dUserTokens.ContainsKey(username))
                {
                    dUserTokens.Add(username, "1");
                }
                SendError("token", "1");
                return;
            }
            var result = dbaccount.FindOneData(tUserData
                                               , ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                               & ADBAccessor.filter_eq(InfoNameDefs.UserPassword, MD5String.Hash32(password))
                                               , null);

            if (result != null)
            {
                if (result.Contains(InfoNameDefs.Username))
                {
                    var token = "";
                    if (result.Contains(InfoNameDefs.UserToken))
                    {
                        token = result[InfoNameDefs.UserToken].AsString;
                    }
                    else
                    {
                        token = AWebServerUtils.GetEncryptCode();
                        var updateRes = dbaccount.UpdateOneData(tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                                                , ADBAccessor.updates_build(ADBAccessor.update(InfoNameDefs.UserToken, token)), false);
                        if (!updateRes)
                        {
                            SendDBError();
                            return;
                        }
                    }
                    if (!dUserTokens.ContainsKey(username))
                    {
                        dUserTokens.Add(username, token);
                    }
                    SendError(InfoNameDefs.Username, username, InfoNameDefs.UserToken, dUserTokens[username]);
                }
                else
                {
                    SendError(ErrorDefs.UsernamePasswordMismatch);
                }
            }
            else
            {
                SendError(ErrorDefs.UsernamePasswordMismatch);
            }
        }
    public AFriend(string f1, string f2)
    {
        friend1 = f1;
        friend2 = f2;

        if (!dFriendInfos.ContainsKey(f1))
        {
            var res = ADatabaseConfigsManager.avatarDB.FindOneData(ADatabaseConfigsManager.tAvatarData
                                                                   , ADBAccessor.filter_eq(InfoNameDefs.AvatarName, f1), ADBAccessor.projections(InfoNameDefs.AvatarHead, InfoNameDefs.Username));
            if (res != null)
            {
                var info = new AFriendInfo();
                info.name = f1;
                if (res.Contains(InfoNameDefs.AvatarHead))
                {
                    info.head = res[InfoNameDefs.AvatarHead].AsInt32;
                }
                if (res.Contains(InfoNameDefs.Username))
                {
                    info.accid = res[InfoNameDefs.Username].AsString;
                }
                dFriendInfos.Add(f1, info);
            }
        }
        if (!dFriendInfos.ContainsKey(f2))
        {
            var res = ADatabaseConfigsManager.avatarDB.FindOneData(ADatabaseConfigsManager.tAvatarData
                                                                   , ADBAccessor.filter_eq(InfoNameDefs.AvatarName, f2), ADBAccessor.projections(InfoNameDefs.AvatarHead, InfoNameDefs.Username));
            if (res != null)
            {
                var info = new AFriendInfo();
                info.name = f2;
                if (res.Contains(InfoNameDefs.AvatarHead))
                {
                    info.head = res[InfoNameDefs.AvatarHead].AsInt32;
                }
                if (res.Contains(InfoNameDefs.Username))
                {
                    info.accid = res[InfoNameDefs.Username].AsString;
                }
                dFriendInfos.Add(f2, info);
            }
        }
    }
Esempio n. 22
0
        public void accountlogout(string username, string token)
        {
            var result = dbaccount.FindOneData(tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                               & ADBAccessor.filter_eq(InfoNameDefs.UserToken, token), null);

            if (result != null)
            {
                if (result.Contains(InfoNameDefs.UserToken))
                {
                    var updateRes = dbaccount.UpdateOneData(tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                                            , ADBAccessor.updates_build(ADBAccessor.update(InfoNameDefs.UserToken, token, false)), false);
                    if (updateRes)
                    {
                        SendError();
                    }
                    else
                    {
                        SendDBError();
                    }
                }
                else
                {
                    SendError(ErrorDefs.InvalidToken);
                }
            }
            else
            {
                SendError(ErrorDefs.InvalidToken);
            }
        }
        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()));
        }
 private void SetOneParam(string paramname, string value)
 {
     ADatabaseConfigsManager.avatarDB.UpdateOneData(ADatabaseConfigsManager.tAvatarData
                                                    , ADBAccessor.filter_eq(InfoNameDefs.Username, username), ADBAccessor.update(paramname, value));
 }
        public HttpResponseMessage Logout(string username, string token)
        {
            var eCheck = ATokenManager.Instance.OnCheckToken(username, token);

            if (!eCheck)
            {
                return(ResultToJson.GetErrorJsonResponse("Invalid token."));
            }

            ATokenManager.Instance.OnRemoveToken(username);
            ADatabaseConfigsManager.userDB.UpdateOneData(ADatabaseConfigsManager.tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username), ADBAccessor.update_unset(InfoNameDefs.UserToken));
            return(ResultToJson.GetErrorJsonResponse());
        }
    internal bool OnAnswer(string answer)
    {
        var res = ADatabaseConfigsManager.avatarDB.FindOneData(ADatabaseConfigsManager.tAvatarData
                                                               , ADBAccessor.filter_eq(InfoNameDefs.Username, username), ADBAccessor.projections("qa"));

        if (res != null && res.Contains("qa"))
        {
            var a = res["qa"].ToString();
            if (a == answer)
            {
                OnAddExp(AvatarLevel);
                return(true);
            }
        }
        return(false);
    }