Skip to content

Commit

Permalink
add temporary topic logging for 516
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Dec 19, 2024
1 parent bfd3f55 commit a2bb281
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
#define CURRENT_MINUTE 3
#define MINUTE_COUNT 4
#define ADMINSWARNED_AT 5

/*
When somebody clicks a link in game, this Topic is called first.
It does the stuff in this proc and then is redirected to the Topic() proc for the src=[0xWhatever]
Expand All @@ -33,8 +34,17 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
If you have any questions about this stuff feel free to ask. ~Carn
*/

#ifdef CIBUILDING
#warn REMOVE MTL/STL LOGGING BEFORE FULL MERGE!!!

Check warning on line 38 in code/modules/client/client_procs.dm

View workflow job for this annotation

GitHub Actions / Run Linters

OD1201: #warn REMOVE MTL/STL LOGGING BEFORE FULL MERGE!!!
#endif
/client
var/list/_mtl_log
var/_mtl_logged = FALSE
var/list/_stl_log
var/_stl_logged = FALSE

//the undocumented 4th argument is for ?[0x\ref] style topic links. hsrc is set to the reference and anything after the ] gets put into hsrc_command
/client/Topic(href, href_list, hsrc, hsrc_command)
/client/Topic(href, list/href_list, hsrc, hsrc_command)
if(!usr || usr != mob) //stops us calling Topic for somebody else's client. Also helps prevent usr=null
return

Expand All @@ -51,6 +61,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
return

// Rate limiting
var/is_516 = byond_version == 516
if(!holder && href_list["window_id"] != "statbrowser")
var/mtl = CONFIG_GET(number/minute_topic_limit)
if (mtl)
Expand All @@ -60,8 +71,15 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
if (minute != topiclimiter[CURRENT_MINUTE])
topiclimiter[CURRENT_MINUTE] = minute
topiclimiter[MINUTE_COUNT] = 0
_mtl_logged = FALSE
LAZYNULL(_mtl_log)
topiclimiter[MINUTE_COUNT] += 1
if(is_516 && !_mtl_logged)
LAZYADD(_mtl_log, list(href_list.Copy()))
if (topiclimiter[MINUTE_COUNT] > mtl)
if(is_516 && !_mtl_logged)
_mtl_logged = TRUE
log_href("[key_name(src)] hit mtl on 516:\n[json_encode(_mtl_log, JSON_PRETTY_PRINT)]")
var/msg = "Your previous action was ignored because you've done too many in a minute."
if (minute != topiclimiter[ADMINSWARNED_AT]) //only one admin message per-minute. (if they spam the admins can just boot/ban them)
topiclimiter[ADMINSWARNED_AT] = minute
Expand All @@ -75,12 +93,19 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
if (stl)
var/second = round(world.time, 1 SECONDS)
if (!topiclimiter)
topiclimiter = new(LIMITER_SIZE)
topiclimiter = new(LIMITER_SIZE + 1)
if (second != topiclimiter[CURRENT_SECOND])
topiclimiter[CURRENT_SECOND] = second
topiclimiter[SECOND_COUNT] = 0
_stl_logged = FALSE
LAZYNULL(_stl_log)
topiclimiter[SECOND_COUNT] += 1
if(is_516 && !_stl_logged)
LAZYADD(_stl_log, list(href_list.Copy()))
if (topiclimiter[SECOND_COUNT] > stl)
if(is_516 && !_stl_logged)
_stl_logged = TRUE
log_href("[key_name(src)] hit stl on 516:\n[json_encode(_stl_log, JSON_PRETTY_PRINT)]")
to_chat(src, span_danger("Your previous action was ignored because you've done too many in a second"))
return

Expand Down

0 comments on commit a2bb281

Please sign in to comment.