Make prayer timeouts longer in very long games
This is a security fix, intended to avoid a DoS attack (that has been used in practice against public servers) in which a situation is created in which the same short loop of commands can be run over and over indefinitely; this causes a lot of CPU usage on the public server as it simulates the game turns, and requires hardly any network or CPU usage for an attacker. Once the turn counter goes above 100000, the average prayer timeout increases by 1 for every additional 100 turns spent. Thus, even with a ring of slow digestion, nutrition prayers will no longer be possible after turn 2 million or so. This is unlikely to have any noticeable effect on any strategy that does not rely heavily on prayer for nutrition; even in an implausible 200000-turn game, prayer timeout will only be increased by 1000 or so, which should be easily manageable for a character that powerful.
This commit is contained in:
@@ -1217,6 +1217,14 @@ aligntyp g_align;
|
||||
if (kick_on_butt)
|
||||
u.ublesscnt += kick_on_butt * rnz(1000);
|
||||
|
||||
/* Avoid games that go into infinite loops of copy-pasted commands with no
|
||||
human interaction; this is a DoS vector against the computer running
|
||||
NetHack. Once the turn counter is over 100000, every additional 100 turns
|
||||
increases the prayer timeout by 1, thus eventually nutrition prayers will
|
||||
fail and some other source of nutrition will be required. */
|
||||
if (g.moves > 100000L)
|
||||
u.ublesscnt += (g.moves - 100000L) / 100;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user