summaryrefslogtreecommitdiff
path: root/src/station_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-13 20:46:53 +0000
committerrubidium <rubidium@openttd.org>2007-07-13 20:46:53 +0000
commit7ed3c49bcd545cd2f9b8b689780ea0a83567f193 (patch)
tree382ede83ced05d277c7ee3f9398a6d8807454db0 /src/station_cmd.cpp
parent988d9b8da82df1e8ac45ee1163f0e95de04862df (diff)
downloadopenttd-7ed3c49bcd545cd2f9b8b689780ea0a83567f193.tar.xz
(svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index c870d6309..2f0602e8f 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2411,6 +2411,21 @@ static void UpdateStationRating(Station *st)
}
}
+ /* At some point we really must cap the cargo. Previously this
+ * was a strict 4095, but now we'll have a less strict, but
+ * increasingly agressive truncation of the amount of cargo. */
+ static const uint WAITING_CARGO_THRESHOLD = 1 << 12;
+ static const uint WAITING_CARGO_CUT_FACTOR = 1 << 6;
+ static const uint MAX_WAITING_CARGO = 1 << 15;
+
+ if (waiting > WAITING_CARGO_THRESHOLD) {
+ uint difference = waiting - WAITING_CARGO_THRESHOLD;
+ waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
+
+ waiting = min(waiting, MAX_WAITING_CARGO);
+ waiting_changed = true;
+ }
+
if (waiting_changed) ge->cargo.Truncate(waiting);
}
}