Exemplo n.º 1
0
        public void Initialize_PrimitiveCriteria_NoExceptionRaised()
        {
            // Arrange
            bool executed = false;
            PrimitiveCriteria       criteria           = new PrimitiveCriteria(1);
            ApplicationContext      applicationContext = _testDIContext.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = criteria,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act
            sut.Initialize(args);
            executed = true;

            // Assert
            Assert.IsTrue(executed);
        }
        public void Initialize(InterceptArgs e)
        {
            // put any logic that is needed in the first step of a DP lifecycle (not instantiated yet)
#if DEBUG
            Debug.WriteLine(string.Format("{0} has started the DataPortal lifecycle.", e.ObjectType.ToString()));
#endif
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates an instance of the type.
 /// </summary>
 /// <param name="result">InterceptArgs object from the data portal</param>
 public Activity(InterceptArgs result)
 {
     ObjectType = result.ObjectType;
     Operation  = result.Operation;
     Runtime    = result.Runtime;
     Exception  = result.Exception;
 }
Exemplo n.º 4
0
        public void Initialize_InvalidGrandChildObject_ExceptionRaised()
        {
            // Arrange
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();
            Root  rootObject  = dataPortal.Create(new Root.Criteria("Test Data"));
            Child childObject = rootObject.Children.AddNew();

            childObject.Data = "Test child data";
            GrandChild              grandChildObject   = childObject.GrandChildren.AddNew();
            ApplicationContext      applicationContext = _testDIContext.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = rootObject,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act and Assert
            Assert.ThrowsException <Rules.ValidationException>(() => sut.Initialize(args));
        }
Exemplo n.º 5
0
        public void Initialize_ValidRootObjectWithChild_NoExceptionRaised()
        {
            // Arrange
            bool executed = false;
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();
            Root  rootObject  = dataPortal.Fetch(new Root.Criteria("Test Data"));
            Child childObject = rootObject.Children.AddNew();

            childObject.Data = "Test child data";
            ApplicationContext      applicationContext = _testDIContext.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = rootObject,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act
            sut.Initialize(args);
            executed = true;

            // Assert
            Assert.IsTrue(executed);
        }
Exemplo n.º 6
0
        private void HandlePossibleAchievement(InterceptArgs e)
        {
            Achievement achievement = Achievement.Parse(e.Packet);

            Achievements?.Update(achievement);

            OnAchievementUpdated(achievement);
        }
Exemplo n.º 7
0
    public override void Invoke(InterceptArgs e)
    {
        if (Target is null)
        {
            throw new NullReferenceException("Open intercept callback target is null.");
        }

        _callback(Target, e);
    }
Exemplo n.º 8
0
        // @Update [InterceptIn(nameof(Incoming.RemoveHabboItem))]
        private void HandleRemoveHabboItem(InterceptArgs e)
        {
            int itemId = e.Packet.ReadInt();

            if (_inventory.TryRemove(itemId, out IInventoryItem item))
            {
                OnItemRemoved(item);
            }
        }
Exemplo n.º 9
0
        // @Update [InterceptIn(nameof(Incoming.InventoryRefresh))]
        private void HandleInventoryRefresh(InterceptArgs e)
        {
            IsRefreshNeeded = true;

            if (_loadTask.IsCompleted)
            {
                _loadTask = ReceiveInventoryAsync(Manager.DisposeToken);
            }
        }
Exemplo n.º 10
0
        private void HandleActivityPointNotification(InterceptArgs e)
        {
            int amount             = e.Packet.ReadInt();
            int change             = e.Packet.ReadInt();
            ActivityPointType type = (ActivityPointType)e.Packet.ReadInt();

            Points[type] = amount;

            OnPointsUpdated(type, amount, change);
        }
Exemplo n.º 11
0
 private void OnInterceptChat(InterceptArgs e)
 {
     // Changes incoming chat messages to upper-case if enabled.
     if (EnablePacketManipulation)
     {
         // Replaces a string after the first int (4 bytes)
         // in the packet using a transform function.
         e.Packet.ReplaceAt(4, s => s.ToUpper());
     }
 }
Exemplo n.º 12
0
 protected void OnUserSearchResult(InterceptArgs e)
 {
     try
     {
         if (SetResult(UserSearchResults.Parse(e.Packet)))
         {
             e.Block();
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 13
0
 protected void HandleUserData(InterceptArgs e)
 {
     try
     {
         if (SetResult(UserData.Parse(e.Packet)))
         {
             e.Block();
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 14
0
 protected void OnAchievementList(InterceptArgs e)
 {
     try
     {
         if (SetResult(Achievements.Parse(e.Packet)))
         {
             e.Block();
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 15
0
        private void HandleUserData(InterceptArgs e)
        {
            UserData = UserData.Parse(e.Packet);

            _tcsUserData?.TrySetResult(UserData);
            _tcsUserData = null;

            _taskUserData = Task.FromResult <IUserData>(UserData);

            OnLoadedUserData();
        }
Exemplo n.º 16
0
        private void HandleWalletBalance(InterceptArgs e)
        {
            if (_isLoadingCredits)
            {
                _isLoadingCredits = false;
                e.Block();
            }

            Credits = (int)e.Packet.ReadFloatAsString();

            OnCreditsUpdated();
        }
Exemplo n.º 17
0
        private void HandleUpdateFigure(InterceptArgs e)
        {
            if (UserData is null)
            {
                return;
            }

            UserData.Figure = e.Packet.ReadString();
            UserData.Gender = H.ToGender(e.Packet.ReadString());

            OnUserDataUpdated();
        }
Exemplo n.º 18
0
        private void OnInterceptMove(InterceptArgs e)
        {
            if (EnablePacketBlocking)
            {
                // Flags the packet to be blocked, this cannot be reversed.
                e.Block();

                int x = e.Packet.ReadInt(),
                    y = e.Packet.ReadInt();

                Log($"Blocked move packet to ({x}, {y}).");
            }
        }
Exemplo n.º 19
0
 private void OnIntercept(InterceptArgs e)
 {
     try
     {
         if (SetResult(e.Packet.Copy()))
         {
             if (_block)
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 20
0
 protected void HandleCatalogIndex(InterceptArgs e)
 {
     try
     {
         var catalog = Catalog.Parse(e.Packet);
         if (catalog.Mode == mode)
         {
             if (SetResult(catalog))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 21
0
 protected void OnUserProfile(InterceptArgs e)
 {
     try
     {
         var userProfile = UserProfile.Parse(e.Packet);
         if (userProfile.Id == _userId)
         {
             if (SetResult(userProfile))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 22
0
 protected void OnRoomData(InterceptArgs e)
 {
     try
     {
         var roomData = RoomData.Parse(e.Packet);
         if (roomData.Id == _roomId)
         {
             if (SetResult(roomData))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 23
0
 protected void OnHabboGroupDetails(InterceptArgs e)
 {
     try
     {
         var groupData = GroupData.Parse(e.Packet);
         if (groupData.Id == groupId)
         {
             if (SetResult(groupData))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 24
0
        protected override Task OnExecuteAsync() => throw new NotImplementedException(); // @Update SendAsync(Out.RequestPetInfo);

        // @Update [InterceptIn(nameof(Incoming.PetInfo))]
        protected void OnPetInfo(InterceptArgs e)
        {
            try
            {
                var petInfo = PetInfo.Parse(e.Packet);
                if (petInfo.Id == petId)
                {
                    if (SetResult(petInfo))
                    {
                        e.Block();
                    }
                }
            }
            catch (Exception ex) { SetException(ex); }
        }
Exemplo n.º 25
0
 protected void OnPostItData(InterceptArgs e)
 {
     try
     {
         var sticky = Sticky.Parse(e.Packet);
         if (sticky.Id == _stickyId)
         {
             if (SetResult(sticky))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 26
0
        // @Update [InterceptIn(nameof(Incoming.AddHabboItem))]
        private void HandleAddHabboItem(InterceptArgs e)
        {
            /*
             * Dictionary<int, List<int>>
             *
             * int {
             *  int local_2
             *  int local_3 {
             *      int
             *  }
             * }
             */

            // ???
        }
Exemplo n.º 27
0
 // @Update [InterceptIn(nameof(Incoming.InventoryItemUpdate))]
 private void HandleInventoryItemUpdate(InterceptArgs e)
 {
     if (_inventory != null)
     {
         var item = InventoryItem.Parse(e.Packet);
         if (_inventory.AddOrUpdate(item))
         {
             OnItemAdded(item);
         }
         else
         {
             OnItemUpdated(item);
         }
     }
 }
Exemplo n.º 28
0
 protected void OnNavigatorSearchResults(InterceptArgs e)
 {
     try
     {
         var results = NavigatorSearchResults.Parse(e.Packet);
         if (results.Category == category &&
             results.Filter == filter)
         {
             if (SetResult(results))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 29
0
 protected void HandleCatalogPage(InterceptArgs e)
 {
     try
     {
         var catalogPage = CatalogPage.Parse(e.Packet);
         if (catalogPage.Id == _pageId &&
             catalogPage.Mode == _mode)
         {
             if (SetResult(catalogPage))
             {
                 e.Block();
             }
         }
     }
     catch (Exception ex) { SetException(ex); }
 }
Exemplo n.º 30
0
        private async void HandleLatencyResponse(InterceptArgs e)
        {
            if (UserData is null)
            {
                await SendAsync(Out.InfoRetrieve);
            }
            if (Achievements is null)
            {
                await SendAsync(Out.GetUserAchievements);
            }

            if (Credits is null && !_isLoadingCredits)
            {
                _isLoadingCredits = true;
                await SendAsync(Out.GetCredits);
            }
        }