Ejemplo n.º 1
0
    public static ChatMessage OnAddChatHistory(string senderUsername, string targetUsername, string type, string content, string head)
    {
        var time = ApiDateTime.SecondsFromBegin();

        var cm = new ChatMessage();

        cm.s  = senderUsername;
        cm.t  = targetUsername;
        cm.tp = typeParser.intParse(type);
        cm.c  = content;
        cm.tm = time;
        cm.h  = typeParser.intParse(head);

        AWebServices.Avatar.dbavatar.UpdateOneData(TableChat
                                                   , ADBAccessor.filter_eq(InfoNameDefs.SenderName, cm.s)
                                                   & ADBAccessor.filter_eq(InfoNameDefs.TargetName, cm.t)
                                                   & ADBAccessor.filter_eq(InfoNameDefs.SendTime, cm.tm)
                                                   & ADBAccessor.filter_eq(InfoNameDefs.SendContent, cm.c)
                                                   , ADBAccessor.updates_build(
                                                       ADBAccessor.update(InfoNameDefs.SendTime, cm.tm)
                                                       , ADBAccessor.update(InfoNameDefs.SenderName, cm.s)
                                                       , ADBAccessor.update(InfoNameDefs.TargetName, cm.t)
                                                       , ADBAccessor.update(InfoNameDefs.ChatType, cm.tp)
                                                       , ADBAccessor.update(InfoNameDefs.SendTime, cm.tm)
                                                       , ADBAccessor.update(InfoNameDefs.SendContent, cm.c)
                                                       )
                                                   , true);
        return(cm);
    }
Ejemplo n.º 2
0
        public void accountregister(string username, string password, string mail)
        {
            if (!mail.Contains("@") || !mail.Contains(".") || mail.IndexOf("@") > mail.IndexOf("."))
            {
                SendError(ErrorDefs.InvalidEmailAddress);
                return;
            }

            var result = dbaccount.FindOneData(tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username), null);

            if (result != null)
            {
                SendError(ErrorDefs.DuplicateUsername);
            }
            else
            {
                var fdresult = dbaccount.UpdateOneData(tUserData, ADBAccessor.filter_eq(InfoNameDefs.Username, username)
                                                       , ADBAccessor.updates_build(
                                                           ADBAccessor.update(InfoNameDefs.UserPassword, MD5String.Hash32(password))
                                                           , ADBAccessor.update(InfoNameDefs.UserMail, mail)
                                                           , ADBAccessor.update(InfoNameDefs.Username, username)
                                                           ), true);
                if (fdresult)
                {
                    SendError(Context.Response, "username", username);
                }
                else
                {
                    SendDBError();
                }
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public void wikiadd(string subject, string content)
        {
            var id = ++totalcount;
            var t  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            adb.UpdateOneData(TableName
                              , ADBAccessor.filter_eq("i", id)
                              , ADBAccessor.updates_build(
                                  ADBAccessor.update("i", id)
                                  , ADBAccessor.update("s", subject)
                                  , ADBAccessor.update("c", content)
                                  , ADBAccessor.update("t", t)
                                  )
                              , true);
            SendError("s", subject, "c", content, "t", t);
        }
Ejemplo n.º 7
0
    public void OnAddItem(int itemID, int count)
    {
        DoAddItem(itemID, count);

        if (dItems[itemID] <= 0)
        {
            dItems.Remove(itemID);

            ADatabaseConfigsManager.avatarDB.UpdateOneData(tableName, ADBAccessor.filter_eq(InfoNameDefs.AvatarName, owner.OnGetStringParamValue(InfoNameDefs.AvatarName)),
                                                           ADBAccessor.updates_build(ADBAccessor.update(InfoNameDefs.BagSlotPre + itemID, 0, false)));
        }
        else
        {
            ADatabaseConfigsManager.avatarDB.UpdateOneData(tableName, ADBAccessor.filter_eq(InfoNameDefs.AvatarName, owner.OnGetStringParamValue(InfoNameDefs.AvatarName)),
                                                           ADBAccessor.updates_build(ADBAccessor.update(InfoNameDefs.BagSlotPre + itemID, dItems[itemID])), true);
        }
    }
Ejemplo n.º 8
0
    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);
    }
Ejemplo n.º 9
0
        public void wikimodify(string id, string content)
        {
            AWikiCell cell = OnLoadWikiCellWithoutContent(id);

            if (cell == null)
            {
                SendError("1");
                return;
            }
            cell.content = content;
            var t = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            adb.UpdateOneData(TableName
                              , ADBAccessor.filter_eq("i", cell.id)
                              , ADBAccessor.updates_build(
                                  ADBAccessor.update("c", content)
                                  , ADBAccessor.update("lt", t)
                                  ));
            SendError(cell.ToArray());
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
    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);
        }
    }
Ejemplo n.º 12
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);
    }
Ejemplo n.º 13
0
        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();
                }
            }
        }
    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)));
        }
    }
    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);
        }
    }