Esempio n. 1
0
        /// <summary>
        /// Protocol 001F
        /// </summary>
        /// <param name="session"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public async void UserLogin(EcoSession session, BasePacket packet)
        {
            var login_data = new LoginData(packet.Data);

            Logger.Debug($"Received Login Request, Username: {login_data.Username}, Password:{login_data.Password}, MacAddress:{login_data.MacAddress.ToHexString()}, SingleSignOn:{login_data.SingleSignOn.ToString()}");
            LoginAuthResult loginAuthResult;
            //select user info from db
            Account userAccount = await DatabaseManager.SelectAsync <Account>("username", $@"'{login_data.Username}'");

            if (userAccount.is_online)
            {
                loginAuthResult = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_ERR_ALREADY, 1);
                session.Send(loginAuthResult.ToPacket());
                Logger.Debug($"USER: {login_data.Username} has already logged in.");
                return;
            }

            if (userAccount.is_banned)
            {
                loginAuthResult = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_ERR_BFALOCK, 1);
                session.Send(loginAuthResult.ToPacket());
                Logger.Debug($"USER: {login_data.Username} is banned.");
                return;
            }

            string pass_hash = Utilities.PasswordHash(userAccount.password, session.FrontWord.ToString(), session.BackWord.ToString()).ToHexString();


            if (login_data.Password == pass_hash)
            {
                loginAuthResult          = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_SUCCESS, 1);
                session.UserLoginSuccess = true;
                session.AccountID        = userAccount.id;
                Logger.Debug($"USER: {login_data.Username} login success.");
            }
            else
            {
                loginAuthResult = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_ERR_BADPASS, 0);
                Logger.Debug($"USER: {login_data.Username} login disallowed (wrong password).");
            }


            session.Send(loginAuthResult.ToPacket());
        }
Esempio n. 2
0
        public void UserAuthentication(string username, string userPass, string userLocation)
        {
            List <LoginAuthResult> authResultList = new List <LoginAuthResult>();
            LoginAuthResult        authAttempt    = new LoginAuthResult();

            using (SqlConnection con = new SqlConnection(rois_connstring))
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_user_authentication", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@userPass", userPass);
                    cmd.Parameters.AddWithValue("@location", userLocation);

                    con.Open();

                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        authAttempt.AuthResult = (int)rdr["ID"];
                    }

                    authResultList.Add(authAttempt);
                }
                catch (SqlException ex)
                {
                }
                finally
                {
                    con.Close();
                    con.Dispose();
                }
            }

            JavaScriptSerializer js = new JavaScriptSerializer();

            Context.Response.ContentType = "text/event-stream";
            Context.Response.Write(js.Serialize(authResultList));
            Context.Response.Flush();
            Context.Response.End();
        }
        /// <summary>
        /// Protocol 001F
        /// </summary>
        /// <param name="session"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public async void UserLogin(EcoSession session, BasePacket packet)
        {
            try
            {
                var login_data = new LoginData(packet.Data);
                Logger.Debug($"Received Login Request, Username: {login_data.Username}, Password:{login_data.Password}, MacAddress:{login_data.MacAddress.ToHexString()}, SingleSignOn:{login_data.SingleSignOn.ToString()}");
                LoginAuthResult loginAuthResult;
                //select user info from db
                Account userAccount = await DatabaseManager.SelectAsync <Account>("username", $@"'{login_data.Username}'");

                if (userAccount.is_online)
                {
                    loginAuthResult = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_ERR_ALREADY, 1);
                    session.Send(loginAuthResult.ToPacket());
                    return;
                }

                if (userAccount.is_banned)
                {
                    loginAuthResult = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_ERR_BFALOCK, 1);
                    session.Send(loginAuthResult.ToPacket());
                    return;
                }

                string pass_hash = Utilities.PasswordHash(userAccount.password, session.FrontWord.ToString(), session.BackWord.ToString()).ToHexString();

                if (login_data.Password == pass_hash)
                {
                    loginAuthResult          = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_SUCCESS, 1);
                    session.UserLoginSuccess = true;
                    session.AccountID        = userAccount.id;
                }
                else
                {
                    loginAuthResult = new LoginAuthResult(LoginResultEnum.GAME_SMSG_LOGIN_ERR_BADPASS, 0);
                }

                session.Send(loginAuthResult.ToPacket());

                if (session.UserLoginSuccess)
                {
                    CharaSelectionInfo     sci = new CharaSelectionInfo();
                    EquipmentSelectionInfo sei = new EquipmentSelectionInfo();
                    //select chara data from db
                    List <SingleCharaSelectionInfoExt> lscsiws = await DatabaseManager.SelectMultiAsync <SingleCharaSelectionInfoExt>("account_id", session.AccountID.ToString(), "Chara");

                    foreach (var scsiws in lscsiws)
                    {
                        sci.AddChara(scsiws, scsiws.Slot);
                        SingleCharaEquipmentSelectionInfoExt scesi = await DatabaseManager.SelectAsync <SingleCharaEquipmentSelectionInfoExt>(scsiws.id, "Equip");

                        sei.AddEquipmentInfo(scesi, scsiws.Slot);
                    }

                    //test use
                    //sci.AddChara(new SingleCharaSelectionInfo {
                    //    Name = "TEST",
                    //    RebirthLv = 10, Sex = 1, HairStyle = 7, HairColor = 50, Wig = 0xffff, IsEmptySlot = 0xff, Face = 0, Map = 0x0098f058, Job = 91, LvBase = 15, LvJob1 = 15, LvJob2t = 50, LvJob2x = 1, LvJob3 = 1, Quest = 5 });

                    session.Send(sci.ToPacket());

                    //for test use
                    //sei.AddEquipmentInfo(new SingleCharaEquipmentSelectionInfo { Chestacce = 0x02fc6a3c, Tops = 0x0395d924, Backpack = 0x02fc3328, Shoes = 0x02fe8678 });

                    session.Send(sei.ToPacket());
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }