Frexsim / grid-pack

An easy way to create grid/tetris style inventories.
https://grid-pack.ifrex.xyz/
MIT License
17 stars 5 forks source link

Server Managed Inventories #18

Open Frexsim opened 3 months ago

Frexsim commented 3 months ago

This change is going to bring massive breaking changes since it rewrites how inventories will be created.

Why I feel that this change is necessary

Many have trouble figuring out how to sync their items between the server and client. And I also feel like the current implementation is not very robust and secure.

What should change

Inventories should instead be server managed to improve on security and easily get the correct data for saving via DataStoreService.

Problems with this change

The biggest problem with this is keeping it simple and easy to understand. Since this is the main goal of this resource.

Hzodx commented 1 month ago

Related Suggestion: Dont yield for MoveMiddleware function

Server validation feels much worse with higher ping (even with very low)

My probably not the best solution that doesn't seem to have caused any problems for me yet: Essentially just update it as if there was no MoveMiddleware function and if it doesnt agree then move it back

                if self.MoveMiddleware then
                    task.spawn(function()
                        local lastPos, lastRot, lastManager = self.Position, self.Rotation, self.HoveringItemManager
                        local middlewareReturn = self.MoveMiddleware(self, gridPos, self.PotentialRotation, self.ItemManager, newItemManager)

                        if middlewareReturn == false then
                            -- Move item
                            self.Position = lastPos
                            self.Rotation = lastRot

                            -- Switch ItemManager if the item was hovering above one
                            if newItemManager then
                                self:SetItemManager(lastManager)
                            end
                        else
                            self.PositionChanged:Fire(gridPos)
                        end
                    end)
                end

                -- Move item
                self.Position = gridPos
                self.Rotation = self.PotentialRotation

                -- Switch ItemManager if the item was hovering above one
                if newItemManager then
                    self:SetItemManager(self.HoveringItemManager)
                end