mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-06-04 13:45:25 +01:00
ccef887efe
# MAINTAINER - USE THE BUTTON THAT SAYS "MERGE MASTER" THEN SET THE PR TO AUTO-MERGE! IT'S MUCH EASIER FOR ME TO FIX THINGS BEFORE THEY SKEW RATHER THAN AFTER THE FACT. ## About The Pull Request Hey there, This took a while to do, but here's the gist: Python file now regexes every file in `/code` except for those that have some valid reason to be tacking on more global defines. Some of those reasons are simply just that I don't have the time right now (doing what you see in this PR took a few hours) to refactor and parse what should belong and what should be thrown out. For the time being though, this PR will at least _halt_ people making the mistake of not `#undef`ing any files they `#define` "locally", or within the scope of a file. Most people forget to do this and this leads to a lot of mess later on due to how many variables can be unmanaged on the global level. I've made this mistake, you've made this mistake, it's a common thing. Let's automatically check for it so it can be fixed no-stress. Scenarios this PR corrects: * Forgetting to undef a define but undeffing others. * Not undeffing any defines in your file. * Earmarking a define as a "file local" define, but not defining it. * Having a define be a "file local" define, but having it be used elsewhere. * Having a "local" define not even be in the file that it only shows up in. * Having a completely unused define* (* I kept some of these because they seemed important... Others were junked.) ## Why It's Good For The Game If you wanna use it across multiple files, no reason to not make it a global define (maybe there's a few reasons but let's assume that this is the 95% case). Let me know if you don't like how I re-arranged some of the defines and how you'd rather see it be implemented, and I'd be happy to do that. This was mostly just "eh does it need it or not" sorta stuff. I used a pretty cool way to detect if we should use the standardized GitHub "error" output, you can see the results of that here https://github.com/san7890/bruhstation/actions/runs/4549766579/jobs/8022186846#step:7:792 ## Changelog Nothing that really concerns players. (I fixed up all this stuff using vscode, no regexes beyond what you see in the python script. sorry downstreams)
144 lines
3.8 KiB
Plaintext
144 lines
3.8 KiB
Plaintext
/*!
|
|
* Copyright (c) 2020 Aleksej Komarov
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/**
|
|
* Maximum number of connection records allowed to analyze.
|
|
* Should match the value set in the browser.
|
|
*/
|
|
#define TGUI_TELEMETRY_MAX_CONNECTIONS 5
|
|
|
|
/**
|
|
* Maximum time allocated for sending a telemetry packet.
|
|
*/
|
|
#define TGUI_TELEMETRY_RESPONSE_WINDOW (30 SECONDS)
|
|
|
|
/// Time of telemetry request
|
|
/datum/tgui_panel/var/telemetry_requested_at
|
|
/// Time of telemetry analysis completion
|
|
/datum/tgui_panel/var/telemetry_analyzed_at
|
|
/// List of previous client connections
|
|
/datum/tgui_panel/var/list/telemetry_connections
|
|
|
|
/**
|
|
* private
|
|
*
|
|
* Requests some telemetry from the client.
|
|
*/
|
|
/datum/tgui_panel/proc/request_telemetry()
|
|
telemetry_requested_at = world.time
|
|
telemetry_analyzed_at = null
|
|
window.send_message("telemetry/request", list(
|
|
"limits" = list(
|
|
"connections" = TGUI_TELEMETRY_MAX_CONNECTIONS,
|
|
),
|
|
))
|
|
|
|
/**
|
|
* private
|
|
*
|
|
* Analyzes a telemetry packet.
|
|
*
|
|
* Is currently only useful for detecting ban evasion attempts.
|
|
*/
|
|
/datum/tgui_panel/proc/analyze_telemetry(payload)
|
|
if(world.time > telemetry_requested_at + TGUI_TELEMETRY_RESPONSE_WINDOW)
|
|
message_admins("[key_name(client)] sent telemetry outside of the allocated time window.")
|
|
return
|
|
if(telemetry_analyzed_at)
|
|
message_admins("[key_name(client)] sent telemetry more than once.")
|
|
return
|
|
telemetry_analyzed_at = world.time
|
|
if(!payload)
|
|
return
|
|
telemetry_connections = payload["connections"]
|
|
var/len = length(telemetry_connections)
|
|
if(len == 0)
|
|
return
|
|
if(len > TGUI_TELEMETRY_MAX_CONNECTIONS)
|
|
message_admins("[key_name(client)] was kicked for sending a huge telemetry payload")
|
|
qdel(client)
|
|
return
|
|
|
|
var/ckey = client?.ckey
|
|
if (!ckey)
|
|
return
|
|
|
|
var/list/all_known_alts = GLOB.known_alts.load_known_alts()
|
|
var/list/our_known_alts = list()
|
|
|
|
for (var/known_alt in all_known_alts)
|
|
if (known_alt[1] == ckey)
|
|
our_known_alts += known_alt[2]
|
|
else if (known_alt[2] == ckey)
|
|
our_known_alts += known_alt[1]
|
|
|
|
var/list/found
|
|
|
|
var/list/query_data = list()
|
|
|
|
for(var/i in 1 to len)
|
|
if(QDELETED(client))
|
|
// He got cleaned up before we were done
|
|
return
|
|
var/list/row = telemetry_connections[i]
|
|
|
|
// Check for a malformed history object
|
|
if (!row || row.len < 3 || (!row["ckey"] || !row["address"] || !row["computer_id"]))
|
|
return
|
|
|
|
if (!isnull(GLOB.round_id))
|
|
query_data += list(list(
|
|
"telemetry_ckey" = row["ckey"],
|
|
"address" = row["address"],
|
|
"computer_id" = row["computer_id"],
|
|
))
|
|
|
|
if (row["ckey"] in our_known_alts)
|
|
continue
|
|
|
|
if (world.IsBanned(row["ckey"], row["address"], row["computer_id"], real_bans_only = TRUE))
|
|
found = row
|
|
break
|
|
|
|
CHECK_TICK
|
|
|
|
// This fucker has a history of playing on a banned account.
|
|
if(found)
|
|
var/msg = "[key_name(client)] has a banned account in connection history! (Matched: [found["ckey"]], [found["address"]], [found["computer_id"]])"
|
|
message_admins(msg)
|
|
log_admin_private(msg)
|
|
log_suspicious_login(msg, access_log_mirror = FALSE)
|
|
|
|
// Only log them all at the end, since it's not as important as reporting an evader
|
|
for (var/list/one_query as anything in query_data)
|
|
var/datum/db_query/query = SSdbcore.NewQuery({"
|
|
INSERT INTO [format_table_name("telemetry_connections")] (
|
|
ckey,
|
|
telemetry_ckey,
|
|
address,
|
|
computer_id,
|
|
first_round_id,
|
|
latest_round_id
|
|
) VALUES(
|
|
:ckey,
|
|
:telemetry_ckey,
|
|
INET_ATON(:address),
|
|
:computer_id,
|
|
:round_id,
|
|
:round_id
|
|
) ON DUPLICATE KEY UPDATE latest_round_id = :round_id
|
|
"}, list(
|
|
"ckey" = ckey,
|
|
"telemetry_ckey" = one_query["telemetry_ckey"],
|
|
"address" = one_query["address"],
|
|
"computer_id" = one_query["computer_id"],
|
|
"round_id" = GLOB.round_id,
|
|
))
|
|
query.Execute()
|
|
qdel(query)
|
|
|
|
#undef TGUI_TELEMETRY_MAX_CONNECTIONS
|
|
#undef TGUI_TELEMETRY_RESPONSE_WINDOW
|