Event request: on_pre_player_spilled_items

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Hanakocz
Inserter
Inserter
Posts: 39
Joined: Sun Jun 24, 2018 7:06 pm
Contact:

Event request: on_pre_player_spilled_items

Post by Hanakocz »

Heya,

recently, we got huge problems on public servers, where people intentionally crash servers by exploiting the inefficiency of surface.spill_item_stack() function. They mainly do it by using crafting queue, they basically fill their queue by thousands of items, then cancel whole queue at once and as their inventory cannot fit all the items, they get spilled on ground. When there is too many items spilled, server needs exponencially more cpu power to find next free position for spilled items (this causes huge lag spike once the range of filled space goes over chunk or two already), and if there isn't enough free space (for example they are on island, or on separate small surface - think about factorissimo, ribbon world, or similar), it even can cause the server to run out of cpu and basically all you can do is to shut it down.

So, if there would be something like on_pre_player_spilled_items event, I can make a script that would hook into this event, and deny the spilling by doing some action prior to spill is called, for example killing the character (as character corpse has unlimited size of inventory, thus won't spill anything). This would be great antigrief, or even just safety measure.

on_pre_player_spilled_items event would ideally contain:
- player
- buffer of items that are about to be spilled (so I can count them, plus I can just .clear() the buffer similar to on_player_mined_entity, or do any other stuff with it)
- cause : if the spill was due to change of inventory size, or cancelling crafting, or something else

- called when player is about to eject items automatically on ground around, for example due to cancelled crafting queue or due to removed armor, but before the spilling happens, so we can intercept it.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13198
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Event request: on_pre_player_spilled_items

Post by Rseding91 »

Not saying i'm against adding something like this, but the cost to spill stuff is linear with the number of items spilled.

It's actually *incredibly* fast. Just if there's no space (limited size surface) then it literally can't resolve a location to drop stuff and will get stuck.
If you want to get ahold of me I'm almost always on Discord.

Hanakocz
Inserter
Inserter
Posts: 39
Joined: Sun Jun 24, 2018 7:06 pm
Contact:

Re: Event request: on_pre_player_spilled_items

Post by Hanakocz »

Well, okay, maybe I did overstated it a bit, but certainly it caused big lag issues, once people noticed it can shut the server down, they use it fairly often, and cannot really be solved without interrupting the game itself (for example disabling cancellations of crafting or such).

As our scenarios use a lot of "something drops items", for example ores from rocks, or coins from biters, I can say that we got rid of lag by getting rid of this incredibly fast function in favor of spawning item entities directly (especially because then one can spawn item entity containing whole stack, thus it is 50x less objects, plus it does not search for free spot as multiple can overlap). So yes, in small scale I guess it is good, but once players get silly and don't clean up after themselves (for whatever reason), the lag spikes are just huge pain, and even on high end computers.

My goal would certainly be to limit the effects when the amounts of dropped items would be above certain size, to deny people attacking the server's performance.

Thanks for oyur consideration!

Post Reply

Return to “Modding interface requests”