Пример #1
0
        public static async Task <Models.Member> AddMember(Models.Member member)
        {
            using (var context = new Lobby.Models.CommonContext())
            {
                await context.member.AddAsync(member);

                await context.SaveChangesAsync();

                return(member);
            }
        }
Пример #2
0
        public static async Task <(Models.Member, Models.User, bool, bool)> GetMemberUser(string player_id)
        {
            Models.Member last_member = null;
            Models.User   last_user   = null;
            bool          hasMember   = false;
            bool          hasUser     = false;

            last_member = await MemberQuery.GetMember(player_id);

            if (last_member != default(Models.Member))
            {
                hasMember = true;

                last_user = await UserQuery.GetUser(last_member.member_no, last_member.user_no);

                if (last_user != default(Models.User))
                {
                    hasUser = true;
                }
            }
            return(last_member, last_user, hasMember, hasUser);
        }
Пример #3
0
        public static async Task <(Session, ErrorCode, string)> LoginSession(string endpoint, string player_id, string device_uid, bool check_device_uid, Models.Member member)
        {
            var  db        = Cache.Instance.GetDatabase();
            bool hasMember = false;
            bool hasUser   = false;

            Models.User user = null;

            if (player_id == "")
            {
                // 게스트 계정 발급, prefix 'G'
                player_id = $"G{Guid.NewGuid().ToString("N")}";
            }
            else
            {
                Models.Member last_member = null;
                Models.User   last_user   = null;

                // 캐시 확인
                var ret = await db.StringGetAsync($"player_id:{player_id}");

                if (ret.HasValue == false)
                {
                    // 디비 확인
                    (last_member, last_user, hasMember, hasUser) = await GetMemberUser(player_id);
                }
                else
                {
                    string session_id = ret;

                    var timeout = await IsDuplicateTimeout(session_id);

                    // 세션이 만료되지 않았다면 가져와서 사용
                    var last_session = await GetSession(session_id, false);

                    if (last_session != null)
                    {
                        // SystemInfo.deviceUniqueIdentifier 비교
                        if (check_device_uid &&
                            string.IsNullOrEmpty(last_session.device_uid) == false && // 이전 로그인이 어드민 무시
                            last_session.device_uid != device_uid)
                        {
                            Log.Information($"LoginSession diff last : {last_session.device_uid}, new : {device_uid}, timeout : {timeout}");

                            if (timeout)
                            {
                                // 이전 세션을 클리어
                                await ClearSession(session_id);

                                //캐싱된 데이터를 사용하지 않고 로그인 처리
                                (last_member, last_user, hasMember, hasUser) = await GetMemberUser(player_id);
                            }
                            else
                            {
                                return(null, ErrorCode.DuplicateLogin, player_id);
                            }
                        }
                        else
                        {
                            await last_session.Touch();

                            return(last_session, ErrorCode.Success, player_id);
                        }
                    }
                    else
                    {
                        (last_member, last_user, hasMember, hasUser) = await GetMemberUser(player_id);
                    }
                }

                if (hasMember)
                {
                    member = last_member;
                }

                if (hasUser)
                {
                    user = last_user;
                }
            }

            if (hasMember == false)
            {
                member.user_no   = 0;
                member.player_id = player_id;

                member = await MemberQuery.AddMember(member);
            }


            if (hasUser == false)
            {
                user = new Models.User()
                {
                    user_no      = member.member_no,
                    character_no = 0,
#if USE_TEMP_SET_NICKNAME
                    user_name = Guid.NewGuid().ToString("N"), // todo 임시코드
#endif
                    map_id = defaultUserMapId,
                };

#if USE_TEMP_SET_NICKNAME
                // todo : 임시 닉네임 설정
                // 유저로부터 입력 받도록 수정이 필요
                (var ret, var user_name) = await GetCandidateName();

                if (ret == true)
                {
                    user.user_name = user_name;
                }
#endif

                user = await UserQuery.AddUser(member.member_no, user);
            }

            if (member.user_no != user.user_no)
            {
                // member 와 user 연결
                // member테이블에 데이터는 있는데 user테이블에 데이터가 없는 경우
                await MemberQuery.UpdateMember(member.member_no, user.user_no);
            }


            int character_rank_level = defaultMinRank;
            if (user.character_no != 0)
            {
                var charac = await CharacterCache.Instance.GetEntity(member.member_no, user.character_no, true, false, false);

                if (charac != null && charac != default(Models.Character))
                {
                    var rankData = ACDC.RankData.GetRank(charac.battle_score);
                    if (rankData != null)
                    {
                        character_rank_level = rankData.Rank;
                    }
                }
            }

            var session = new Session()
            {
                remote_endpoint = endpoint,
                user_no         = user.user_no,
                user_name       = member.user_name,
                player_id       = player_id,
                member_no       = member.member_no,
                character_no    = user.character_no,
                rank            = character_rank_level,
                device_uid      = device_uid,
                map_id          = user.map_id
            };

            bool result = await TryInsertSession(session);

            if (result == false)
            {
                Log.Error($"CreateSession 1 try count over player_id:{player_id}");
                return(null, ErrorCode.TryCountOver, player_id);
            }

            await db.StringSetAsync($"player_id:{player_id}", session.session_id.ToString(), session_expire);


            return(session, ErrorCode.Success, player_id);
        }
Пример #4
0
        /// <summary>
        /// 로그인
        /// </summary>
        /// <param name="request"></param>
        /// <param name="responseStream"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task Login(LoginRequest request, IServerStreamWriter <LoginReply> responseStream, ServerCallContext context)
        {
            try
            {
                Log.Information($"login player ID:{request.PlayerId}");
                if (request.PlayerId != "")
                {
                    // 유저 아이디 영문과 숫자 조합만 허용
                    //if (Regex.IsMatch(request.UserId, @"^[a-zA-Z0-9]+$") == false)
                    //{
                    //    Log.Error($"login error {request.UserId}");

                    //    await responseStream.WriteAsync(new LoginReply() { Code = ErrorCode.WrongLetters });
                    //    return;
                    //}
                }

                var(ret, responseValidate) = await WebAPIClient.Web.validate(request.PlayerId, request.AccessToken);

                if (ret == false)
                {
                    Log.Error($"Login auth error player_id:{request.PlayerId}, peer:{context.Peer}");

                    // IDP 인증 실패시 로그인 실패처리 할 것인지
                    if (context.Peer.Contains("203.246.171.143") == true)
                    {
                        Log.Warning($"Login auth white list :{request.PlayerId}");
                    }
                    else if (ServerConfiguration.Instance.EnableCheckAccessToken)
                    {
                        await responseStream.WriteAsync(new LoginReply()
                        {
                            Code = ErrorCode.Auth
                        });

                        return;
                    }
                }

                // todo : 클라이언트로 부터 맴버 초기값 세팅이 필요.
                Models.Member member = new Models.Member()
                {
                    device_model_name = "",
                    os_version        = "",
                    language_code     = responseValidate == null ? "" : responseValidate.lang,
                    nation_code       = responseValidate == null ?  "" : responseValidate.country,
                    create_time       = DateTime.UtcNow,
                };

                (var session, var err, var player_id) = await Session.LoginSession(context.Peer, request.PlayerId, request.DeviceUniqueIdentifier, true, member);

                if (session == null)
                {
                    Log.Error("login {0}", context.Peer);

                    await responseStream.WriteAsync(new LoginReply()
                    {
                        Code = err
                    });

                    return;
                }

                bool           IsPlaying;
                StartPlayReply ReloadStartPlay = null;
                long           match_id;
                if (ServerConfiguration.Instance.gameSetting.EnableReJoin)
                {
                    (IsPlaying, ReloadStartPlay, match_id) = await RankMatchmaking.RestoreMatchUser(session);
                }
                else
                {
                    IsPlaying = false;
                }

                Log.Information($"login user_no:{session.user_no}, player_id:{player_id}, session_id:{session.session_id}, user_name:{session.user_name}, IsPlaying:{IsPlaying}, ReloadStartPlay:{ReloadStartPlay?.BattleServerAddr}");

                var reply = new LoginReply();
                reply.UserId          = player_id;
                reply.SessionId       = session.session_id;
                reply.Code            = ErrorCode.Success;
                reply.IsPlaying       = IsPlaying;
                reply.ReloadStartPlay = ReloadStartPlay;
                reply.JsonData.Add(JsonData.Instance.OriginalData);
                reply.UserName   = session.user_name ?? "";
                reply.ServerTime = DateTime.UtcNow.ToTimestamp();

                await responseStream.WriteAsync(reply);

                History.Info(session.member_no, session.user_no, session.character_no, HistoryLogAction.Login, (byte)HistoryLogReason.None, 0, 0, request.PlayerId, session.user_name);
            }
            catch (Exception ex)
            {
                Log.Error($"Login error {ex.ToString()}");
            }
        }