RPGGame.GameServer.UserData.GameUser.LoadFromDB C# (CSharp) Method

LoadFromDB() public method

GameDB에 저장된 유저의 모든 정보를 가져와 GameUser 객체를 설정합니다.
public LoadFromDB ( Action actionOnComplete ) : void
actionOnComplete Action
return void
        public void LoadFromDB(Action<Int32> actionOnComplete)
        {
            using (DBCommand cmd = GameDB.NewCommand(UserNo))
            {
                Boolean isNewUser = false;

                cmd.CommandText.Append("select nickname, level, exp, vip_level, vip_exp, main_characterno, last_managermailno");
                cmd.CommandText.Append(" from t_userinfo where userno=@userno;");

                cmd.CommandText.Append("select characterno, characterid, level, exp, gradeid, promotionid");
                cmd.CommandText.Append(" from t_inventory_character where userno=@userno;");

                cmd.CommandText.Append("select itemno, itemid, promotionid, quantity");
                cmd.CommandText.Append(" from t_inventory_item where userno=@userno;");

                cmd.CommandText.Append("select decktype, slotno, characterno");
                cmd.CommandText.Append(" from t_playdeck where userno=@userno;");

                cmd.CommandText.Append("select energyid, point, last_updatetime");
                cmd.CommandText.Append(" from t_userinfo_energy where userno=@userno;");

                cmd.CommandText.Append("select resourceid, point");
                cmd.CommandText.Append(" from t_userinfo_resource where userno=@userno;");

                cmd.BindParameter("@userno", UserNo);
                cmd.PostQuery(() =>
                {
                    var reader = cmd.Reader;
                    Int32 mainCharacterNo;

                    //  t_userinfo
                    if (reader.Read())
                    {
                        Nickname = reader.GetString(0);
                        Level = reader.GetInt16(1);
                        Exp = reader.GetInt32(2);
                        VIPLevel = reader.GetInt16(3);
                        VIPExp = reader.GetInt32(4);
                        mainCharacterNo = reader.GetInt32(5);
                        LastManagerMailNo = reader.GetInt32(6);

                        reader.NextResult(); InvenCharacter.LoadFromDB(reader);
                        reader.NextResult(); InvenItem.LoadFromDB(reader);
                        reader.NextResult(); PlayDeck.LoadFromDB(reader);
                        reader.NextResult(); Energy.LoadFromDB(reader);
                        reader.NextResult(); Resource.LoadFromDB(reader);

                        MainCharacter = InvenCharacter.Find(mainCharacterNo);
                    }
                    else
                    {
                        isNewUser = true;
                        return;
                    }
                },
                (exception) =>
                {
                    if (exception != null)
                    {
                        actionOnComplete(ResultCode.Database_Error);
                        Logger.Write(LogType.Err, 2, exception.ToString());
                    }
                    else if (isNewUser == true)
                        actionOnComplete(ResultCode.NewUser);
                    else
                        actionOnComplete(ResultCode.Ok);
                });
            }
        }

Usage Example

Example #1
0
        public static void Login(Int32 userNo, Int32 authKey, Action<GameUser, Int32> actionOnComplete)
        {
            GameUser user = Find(userNo);
            if (user != null)
                Logout(userNo);

            using (DBCommand cmd = AuthDB.NewCommand())
            {
                Int32 dbAuthKey = -1;

                cmd.CommandText.Append($"select authkey from t_accounts where userno={userNo};");
                cmd.PostQuery(() =>
                {
                    if (cmd.Reader.Read())
                        dbAuthKey = cmd.Reader.GetInt32(0);
                },
                (exception) =>
                {
                    if (exception != null)
                    {
                        actionOnComplete(null, ResultCode.Database_Error);
                        Logger.Write(LogType.Err, 2, exception.ToString());
                    }
                    //  인증키 확인
                    else if (dbAuthKey == authKey)
                    {
                        //  유저데이터 및 게임데이터 로드
                        user = new GameUser(userNo);
                        user.LoadFromDB((result) =>
                        {
                            _users.Add(userNo, new UserData(user));
                            actionOnComplete(user, result);
                        });
                    }
                    //  잘못된 인증키
                    else
                        actionOnComplete(null, ResultCode.InvalidAuthKey);
                });
            }
        }