Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readd cooldowns on the world topic #48542

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions code/game/world.dm
@@ -1,4 +1,6 @@
#define RESTART_COUNTER_PATH "data/round_counter.txt"
#define MAX_TOPIC_LEN 100
#define TOPIC_BANNED 1

GLOBAL_VAR(restart_counter)

Expand Down Expand Up @@ -164,10 +166,30 @@ GLOBAL_VAR(restart_counter)
log_runtime(GLOB.revdata.get_log_message())

/world/Topic(T, addr, master, key)
TGS_TOPIC //redirect to server tools if necessary

var/static/list/bannedsourceaddrs = list()
var/static/list/lasttimeaddr = list()
var/static/list/topic_handlers = TopicHandlers()

//LEAVE THIS COOLDOWN HANDLING IN PLACE, OR SO HELP ME I WILL MAKE YOU SUFFER
if (addr in bannedsourceaddrs)
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an associated list reference instead of in.

in is O(n), blah[key] is O(log n)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason I thought that gives a runtime about the key if it doesn't exist


if (length(T) >= MAX_TOPIC_LEN)
log_admin_private("[addr] banned from topic calls for a round for too long status message")
bannedsourceaddrs[addr] = TOPIC_BANNED
return
if (addr in lasttimeaddr)
var/lasttime = lasttimeaddr[addr]
if(world.time < (lasttime + 2 SECONDS))
log_admin_private("[addr] banned from topic calls for a round for too frequent messages")
bannedsourceaddrs[addr] = TOPIC_BANNED
return

lasttimeaddr[addr] = world.time
Comment on lines +183 to +188
Copy link

@NethIafin NethIafin Jan 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead use
lasttimeaddr[addr] = world.time + 2 SECONDS
and check that
if(world.time < lasttime)



TGS_TOPIC //redirect to server tools if necessary

var/list/input = params2list(T)
var/datum/world_topic/handler
for(var/I in topic_handlers)
Expand Down