[1.1.33] Rcon polling for data does not "respect" pause at all

Bugs that are actually features.
Post Reply
KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

[1.1.33] Rcon polling for data does not "respect" pause at all

Post by KeepResearchinSpoons »

the funniest demo of these all is this one.
So very much TLDR!
The forum engine does not allow me to embed the ah wait, let's use the weird self-reference for the file we've just loaded...
here:

Boy: look, mommy! I have a game paused!
Mommy: But it still does run as usual?

rcon_unpause.webm
(the same one, I've just embedded it)
(367.73 KiB) Downloaded 130 times



lol


Shall paste details in the next message.
> The history of mishaps... No, spare me this one, it is a huge fine print.
> What tests I've done already
> What it affects all the time around
And even
> what a dirty solution may possibly save half your day, if it also affects your setup with rcon stats you collect (spoiler: it does)

KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all. The vid. The details. Possible hot-fixes.

Post by KeepResearchinSpoons »

It all started with servers magically running even when noone was around.
The is_the_server_alive poll in this story happens once a sec.
(In the video above it happens ~120 times a sec, so you can see it in the real time.)

The fixes for events that failed when there was not a player were introduced,
the problem of the servers still running, bitters evolving, miners depleting etc remained though.

In the nutshell, being polled once per sec made them run at 1/60 the real speed.
So in an hour a minute passed by.

Over the night with 8 hours it was a 10 minutes.
Not exactly enough to kill a well-defended base.
Well, if the scenario was a hard one, with a constant pressure...
All hail the ruins, welcome to the next run! (The fish market is died, soft-reset initiated!)
Or welcome to the half-dead market that may still be possible to save. if you were lucky that is.

And the bug was well known but not confirmed till this week.

This is what exactly an auto-pause exists for, you prevent the map from running when no one is around.
As you can see in the vid, it is not the option.
* provided, you want to know admin-side, if your server is alive.
* or you want to update the server banlist via lua (via rcon)
* or if you update "Trusted" players list globally over all the servers;
* or if you keep the "ups" being measured (this is even more buggy due to the issue)

KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all. The vid. The details. Possible hot-fixes.

Post by KeepResearchinSpoons »

The current workaround
You can't prevent the game time from rising. Sorry.
But! You can use the "editor" option to prevent the ticks from affecting entities!

lua-api for game.tick_paused yay! It is RW!
It is dirty, since it uses some hacks, but here's the idea:
hana_rcon_fix.png
hana_rcon_fix.png (11.66 KiB) Viewed 2393 times

This prevents the game.tick from running on each rcon poll.
Should also prevent on_tick, but well you can add `if game.tick < next_tick` or something for the worst case anyways.
Same way as `/editor` works actually.

You still have the `game.ticks_played` increase with each rcon request
So do the server-time shown in the lobby (and `/time`) increase.
At least you can save yourself the trouble of all soft-resets occured for the bitters...

KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all

Post by KeepResearchinSpoons »

Now for the tests having been made.
If you poll faster than 60/sec,
both game.tick and game.ticks_played increase no faster than the current game.speed.

You can't set game.speed lower than 0.01, so this was not an option for the "real_pause module".

However when you do set paused to true ( or effectively use an /editor, same )
you get

Code: Select all

[    10]@2021-05-10<UTC>19:32 >> {"r_id":13,"ct":2559,"ctp":2707,"t2r":0,"istp":true}
[    11]@2021-05-10<UTC>19:32 >> {"r_id":18,"ct":2559,"ctp":2708,"t2r":0,"istp":true}
[    12]@2021-05-10<UTC>19:32 >> {"r_id":19,"ct":2559,"ctp":2708,"t2r":0,"istp":true}
[    13]@2021-05-10<UTC>19:32 >> {"r_id":20,"ct":2559,"ctp":2708,"t2r":0,"istp":true}
[    14]@2021-05-10<UTC>19:32 >> {"r_id":22,"ct":2559,"ctp":2709,"t2r":0,"istp":true}
[    15]@2021-05-10<UTC>19:32 >> {"r_id":23,"ct":2559,"ctp":2709,"t2r":0,"istp":true}
[    16]@2021-05-10<UTC>19:32 >> {"r_id":24,"ct":2559,"ctp":2709,"t2r":0,"istp":true}
[    17]@2021-05-10<UTC>19:32 >> {"r_id":26,"ct":2559,"ctp":2710,"t2r":0,"istp":true}
[    18]@2021-05-10<UTC>19:32 >> {"r_id":27,"ct":2559,"ctp":2710,"t2r":0,"istp":true}
[    19]@2021-05-10<UTC>19:32 >> {"r_id":28,"ct":2559,"ctp":2710,"t2r":0,"istp":true}
with the game.tick remaining the same, while the game.ticks_played (`/time` ?) does update.

The weirdest part about pauses,
krs_rcon_fix.png
krs_rcon_fix.png (12.29 KiB) Viewed 2388 times

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all

Post by boskid »

Thanks for the report, however this is Not a bug.

In order for the Rcon to work properly, its commands have to be processed as soon as possible. By "polling" i assume you are running "\c" commands and they have to be processed as InputAction because they are distributed to all connected clients and they are persisted for the purpose of replay (if enabled). InputActions have to be assigned to one particular tick and to obtain the results of running such command the input action has to be processed by the game state which requires running an update. Update is atomic as you cannot run part of it, throw some input actions to get results, throw more input actions in the same tick based on the previous results and continue. Because all of that, everything works exactly as designed for the implementation to be reasonable. Having commands in queue overrides server pause. Once they are processed, pause is effective again.

You can use the tick_paused and its a valid solution, however it does not make a game to pause entirely: it simply prevents some parts of update happening (machines are not crafting, fluids are not moving) but there are still some that are still running (like editor controller is able to move) - There are 2 tick counters, one for how many update ticks passed and one for how many game ticks passed.

KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all

Post by KeepResearchinSpoons »

[edit: this reply was written before the aforeplaced reply post, the nature of the forums... #include a grain of salt, since most parts of it should be obsolete]
spoila
Last edited by KeepResearchinSpoons on Tue May 11, 2021 5:35 am, edited 1 time in total.

KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all

Post by KeepResearchinSpoons »

boskid wrote:
Mon May 10, 2021 9:33 pm
In order for the Rcon to work properly, its commands have to be processed as soon as possible. By "polling" i assume you are running "\c" commands and they have to be processed as InputAction because they are distributed to all connected clients and they are persisted for the purpose of replay (if enabled). InputActions have to be assigned to one particular tick and to obtain the results of running such command the input action has to be processed by the game state which requires running an update.
Yay! a reply!

With this kind of a reply being expected though,
g_rcon_fix.png
g_rcon_fix.png (14.66 KiB) Viewed 2302 times

Well a replay would probably crash on a big enough command anyways, same way tsubodai crashed it with a big enough bp string imported at once... Oh sweet it has no length limit! well replays are great anyways


I have but 3 questions left here:
1) About the current state of the pause logic:

would it be possible to somehow get
events.on_game_paused({paused_by_player:player/nil if autopause}) / events.on_game_resumed (player/nil)
that also has some form of a r/o game.is_game_paused or something
at least?

There is no way to tell if a game is "paused" currently.
Same thing about precise ups measurements.

You can guess: (somehow poll very rare, lol, ofc not possible, and guess this is 1 of 60 so -- paused! (chance is 1 of 6 among net issues and such, not bad))
But that's it.


For what is worth, lua-api tick_paused does not mention that tick_paused can actually be set to `false` when the game IS paused.
Should I report this one as a bug instead?
The bug: tick_paused is false when the game *seems* to be paused (spoiler, it is not, only some events are paused :kappa:).

From that point it works as a charm; game is not actually paused, it's just that you don't know the password or da wai to supply inputs.
And if requested for an update it runs perfectly! Cuz it is not game.tick_paused!
(which we can see)



2) is it possible to tweak the rcon logic a bit?
It is just 2 side effects that are nasty.
And aside from the pause issue the next one is the "3rd counter for the time _players_ played"

Just run an rcon command as it is NOW, but
> without force-running the simulate-entities part
(just respect the `paused_state && game.tick_paused` to decide the game.tick update really)
(if it IS necessary to run a tick while paused we can safely incr ticks_to_run or undo the eh "game_paused" state then?)
and
> without incrementing the game.ticks_played?
or, better yet, calc the map_played time without bot-updates part somehow?
I see this as an 3rd counter, since it would be just player-side updates, and not the "server-side" ones

This is actually the least effort route,
if the entities simulation would not run on pause
. (should it be
. "a dirty fix working on autopause only" +
. "another dirty fix that actually forbids the usual pause and introduces a custom one..."
. or
. "a code fix that respects game_paused"
. does not exactly matter, a "taste preference", so to say)
and
if the map_played time does not rise while it IS idle (0 players or better yet, paused state check)

then
we can run as many "full updates", as possible, as required or as necessary.
It is just that those mp-wide "updates" have terrible side effects of
> updating the entities (even when paused) and
> increasing the time_played(also when paused)

If you need to run a full logic loop for an API-read call, so be it, as strange as it sounds.
Let's call it a non-optimised API-read-write-etc call, same backend route, whatever.
just remove those side effects please and the issue of this whole thread ceases to exist.


and 3)
Is this "not-a-bug" triage a final all-things-considered official decision on the "Wube's current factorio-team" level that I can link to?
I don't exactly need a fast reply there, better yet a wording that I could report to a group of server-owners, this would be nice.
Like, the cost is too much, not a bother, can't do or something but in right terms.
If possible, before the 2021-05-15 (mid Q2, about a week ahead) or better yet a day or 2 before the line.
I would just report this as a "dead" bug that is not possible to fix both client and server side for a reasonable price,
but I need a solid confirmation, as the future resources allocation levels are somehow affected by this and I need to know for sure if this is worth it on my side as well before going into it further.
It's fine for any answer; they are not pressing the issue, just have to know for sure.



Anyways, thanks for the ride,
shout outs for
"game.encode_string"
"game.decode_string"
"game.json_to_table"
"game.table_to_json"
which proved very useful in overcoming rcon limitations!
(along with the serpent for the debug slices part)

On a side of the road,
spoiler

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.33] Rcon polling for data does not "respect" pause at all

Post by boskid »

KeepResearchinSpoons wrote:
Tue May 11, 2021 5:32 am
would it be possible to somehow get events.on_game_paused({paused_by_player:player/nil if autopause}) / events.on_game_resumed (player/nil)
It is something that is possible to be implemented but that is a modding interface request. It would need the server to inject some extra input actions when the game is paused and resumed, but this feature has quite low value added because in almost all use cases from the perspective of the scripting, it would be visible as pair of on_game_paused + on_game_resumed events called in the same tick since "game paused" state is one where no update is happening. The only case where it would differ would be literally this one case where RCON forces game to update to execute the command. If the only thing you would like to do with those events would be enabling tick_paused, you can do some workarounds for that, for example include the `game.tick_paused = #game.connected_players == 0` in the command sent to the server.
KeepResearchinSpoons wrote:
Tue May 11, 2021 5:32 am
For what is worth, lua-api tick_paused does not mention that tick_paused can actually be set to `false` when the game IS paused.
Should I report this one as a bug instead?
The bug: tick_paused is false when the game *seems* to be paused (spoiler, it is not, only some events are paused :kappa:).
For the brief moment when the server command is executed, the game is not considered paused so there is nothing wrong here. There are 2 types of pause: "game pause" and "entity pause". First one prevents update from happening at all, second one reduces update to the reasonable minimum which still allows players with editor controller to make changes in the world. Entity pause is exposed to lua because mods may also pause the entity update when showing some guis (i think Helmod is able to do something like that). Game pause is not exposed because game state is not aware of it as it is literally increasing time between updates for undetermined amount of time.
KeepResearchinSpoons wrote:
Tue May 11, 2021 5:32 am
Just run an rcon command as it is NOW, but
> without force-running the simulate-entities part
(just respect the `paused_state && game.tick_paused` to decide the game.tick update really)
"paused_state" (game pause) is not part of the game state so it cannot be used to decide if the update should run the entity update or not. To make a paused_state part of the game state, server would need to inject some extra input actions and that would be part of the modding interface request mentioned previously.
KeepResearchinSpoons wrote:
Tue May 11, 2021 5:32 am
If you need to run a full logic loop for an API-read call, so be it, as strange as it sounds.
Let's call it a non-optimised API-read-write-etc call, same backend route, whatever.
just remove those side effects please and the issue of this whole thread ceases to exist.
"/c" commands run lua code which is able to mutate game state so it never is a clean "read" access. Multiple commands while being executed will trigger some extra lua events like defines.events.on_console_command which may mutate game state even if you think your command is doing only a read. Trying to fulfill your use case would break other APIs.
KeepResearchinSpoons wrote:
Tue May 11, 2021 5:32 am
Is this "not-a-bug" triage a final all-things-considered official decision on the "Wube's current factorio-team" level that I can link to?
I don't exactly need a fast reply there, better yet a wording that I could report to a group of server-owners, this would be nice.
Like, the cost is too much, not a bother, can't do or something but in right terms.
It is a "not a bug" because this behavior is intentionally here to make RCON work at all when the game is paused. If it would not be intentional then it could be a bug. Every topic can be discussed further. Those extra events could be implemented but that is modding interface request.

Post Reply

Return to “Not a bug”