Example #1
0
        public LoginAccountPacketRes LoginAccount([FromBody] LoginAccountPacketReq req)
        {
            LoginAccountPacketRes res = new LoginAccountPacketRes();

            AccountDb account = _context.Accounts
                                .AsNoTracking()
                                .Where(a => a.AccountName == req.AccountName && a.Password == req.Password)
                                .FirstOrDefault();

            if (account == null)
            {
                res.LoginOk = false;
            }
            else
            {
                res.LoginOk = true;

                // 토큰 발급
                DateTime expired = DateTime.UtcNow;
                expired.AddSeconds(600);

                TokenDB tokenDb = _shared.Tokens.Where(t => t.AccountDbId == account.AccountDbId).FirstOrDefault();

                if (tokenDb != null)
                {
                    tokenDb.Token   = new Random().Next(Int32.MinValue, Int32.MaxValue);
                    tokenDb.Expired = expired;
                    _shared.SaveChangesEx();
                }
                else
                {
                    tokenDb = new TokenDB()
                    {
                        AccountDbId = account.AccountDbId,
                        Token       = new Random().Next(Int32.MinValue, Int32.MaxValue),
                        Expired     = expired
                    };

                    _shared.Add(tokenDb);
                    _shared.SaveChangesEx();
                }

                res.AccountId  = account.AccountDbId;
                res.Token      = tokenDb.Token;
                res.ServerList = new List <ServerInfo>();

                foreach (ServerDb serverDb in _shared.Servers)
                {
                    res.ServerList.Add(new ServerInfo()
                    {
                        Name      = serverDb.Name,
                        IpAddress = serverDb.IpAddress,
                        Port      = serverDb.Port,
                        BusyScore = serverDb.BusyScore
                    });
                }
            }

            return(res);
        }
Example #2
0
    // 로그인 버튼 클릭
    public void OnClickLoginButton(PointerEventData evt)
    {
        string account  = Get <GameObject>((int)GameObjects.AccountName).GetComponent <InputField>().text;
        string password = Get <GameObject>((int)GameObjects.Password).GetComponent <InputField>().text;

        // 패킷생성
        LoginAccountPacketReq packet = new LoginAccountPacketReq()
        {
            AccountName = account,
            Password    = password
        };

        // 로그인시도
        Managers.Web.SendPostRequest <LoginAccountPacketRes>("account/login", packet, (res) =>
        {
            Debug.Log($"Account Login : {res.LoginOk}");

            Get <GameObject>((int)GameObjects.AccountName).GetComponent <InputField>().text = "";
            Get <GameObject>((int)GameObjects.Password).GetComponent <InputField>().text    = "";

            if (res.LoginOk)
            {
                // 토큰(영화표) 들고 있기
                Managers.Network.AccountId = res.AccountId;
                Managers.Network.Token     = res.Token;

                // 로그인 성공시 서버목록
                UI_SelectServerPopup popup = Managers.UI.ShowPopupUI <UI_SelectServerPopup>();
                popup.SetServer(res.ServerList);
            }
        });
    }
Example #3
0
    public static void SendLoginAccount(string account, string password)
    {
        LoginAccountPacketReq packet = new LoginAccountPacketReq
        {
            AccountName = account,
            Password    = password
        };

        Managers.Web.SendPostRequest <LoginAccountPacketRes>("account/create", packet, (res) =>
        {
            Debug.Log(res.LoginOk);
        });
    }