Skip to content

Commit 415bca4

Browse files
authored
Prefs cleanup (cid history), admin stuff (#13212)
* removes ignore_cid_warning, it ws never used * Moves guard to preferences datum to make it persistent * use database instead of savefile for the cid list, adds new admin panels for ip and cid history * adds cap for cid requests too * fix * hide from logless admins
1 parent 1bd2892 commit 415bca4

File tree

15 files changed

+177
-77
lines changed

15 files changed

+177
-77
lines changed

code/__DEFINES/varedit.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
/* hidden variables */
5353
#define VE_HIDDEN_LOG \
54-
list("address", "computer_id", "guard", "related_accounts_ip", "related_accounts_cid", "lastKnownIP", "telemetry_connections")
54+
list("address", "computer_id", "guard", "related_accounts_ip", "related_accounts_cid", "admin_cid_request_cache", "admin_ip_request_cache", "lastKnownIP", "telemetry_connections")
5555

5656
var/global/list/duplicate_forbidden_vars = list(
5757
"tag", "area", "type", "loc", "locs", "vars", "verbs", "contents",

code/__HELPERS/_lists.dm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333

3434
return "[output][and_text][input[index]]"
3535

36+
/proc/list2text(list/input, separator = ", ")
37+
. = ""
38+
39+
for(var/line in input)
40+
if(length(.))
41+
. += separator
42+
. += line
43+
3644
//Returns list element or null. Should prevent "index out of bounds" error.
3745
/proc/listgetindex(list/list,index)
3846
if(istype(list) && list.len)

code/game/area/shuttle_areas.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
/area/shuttle/arrival/velocity/Entered(mob/M)
7272
..()
7373
if(istype(M) && M.client)
74-
M.client.guard.time_velocity_shuttle = world.timeofday
74+
M.client.prefs.guard.time_velocity_shuttle = world.timeofday
7575

7676
/area/shuttle/arrival/transit
7777
name = "Space"

code/game/machinery/computer/arrival_shuttle.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ var/global/lastMove = 0
174174
else
175175
to_chat(usr, "<span class='notice'>Шаттл уже движется или состыкован со станцией.</span>")
176176

177-
usr.client.guard.velocity_console = TRUE
177+
usr.client.prefs.guard.velocity_console = TRUE
178178

179179
/obj/machinery/computer/arrival_shuttle/dock
180180
name = "Arrival Shuttle Communication Console"
@@ -204,7 +204,7 @@ var/global/lastMove = 0
204204
else
205205
to_chat(usr, "<span class='notice'>Шаттл уже движется или состыкован со станцией.</span>")
206206

207-
usr.client.guard.velocity_console_dock = TRUE
207+
usr.client.prefs.guard.velocity_console_dock = TRUE
208208

209209
/obj/machinery/computer/arrival_shuttle/proc/radio_message_via_ai(msg)
210210
if (!msg)

code/modules/admin/admin.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ var/global/BSACooldown = 0
7171
<a href='?src=\ref[src];adminplayerobservefollow=\ref[M]'>FLW</a>
7272
<br>
7373
<b>Mob type</b> = [M.type]<br><br>
74-
<b>Guard:</b> <A href='?src=\ref[src];guard=\ref[M]'>Show</A> |
75-
<b>List of CIDs:</b> <A href='?src=\ref[src];cid_list=\ref[M]'>Get</A>|<A href='?src=\ref[src];cid_ignore=\ref[M]'>Ignore Warning</A><br>
76-
<b>Related accounts by IP and cid</b>: <A href='?src=\ref[src];related_accounts=\ref[M]'>Get</A><br>
74+
<b>Guard:</b> <A href='?src=\ref[src];guard=\ref[M]'>Show</A><br>
75+
<b>Related accounts by current IP and CID</b>: <A href='?src=\ref[src];related_accounts=\ref[M]'>Get</A><br>
76+
<b>Slow queries:</b> <A href='?src=\ref[src];cid_history=\ref[M]'>CID history</A> | <A href='?src=\ref[src];ip_history=\ref[M]'>IP history</A><br>
7777
<b>CentCom (other server bans)</b>: <A target='_blank' href='https://centcom.melonmesa.com/viewer/view/[M.ckey]'>CentCom (ENG)</A><br>
7878
<b>BYOND profile</b>: <A target='_blank' href='http://byond.com/members/[M.ckey]'>[M.ckey]</A><br><br>
7979
<A href='?src=\ref[src];boot2=\ref[M]'>Kick</A> |

code/modules/admin/topic.dm

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -956,38 +956,69 @@
956956
if (ismob(M))
957957
if(!M.client)
958958
return
959-
M.client.guard.print_report()
959+
M.client.prefs.guard.print_report()
960960

961-
else if(href_list["cid_list"])
961+
else if(href_list["cid_history"])
962962
if(!check_rights(R_LOG))
963963
return
964+
965+
var/mob/M = locate(href_list["cid_history"])
966+
if (!ismob(M) || !M.client)
967+
return
968+
969+
var/client/C = M.client
970+
if(!C.prefs.admin_cid_request_cache)
971+
C.prefs.admin_cid_request_cache = C.generate_cid_history()
972+
973+
var/dat = ""
974+
if(length(C.prefs.admin_cid_request_cache))
975+
dat += "<table><tr><th>CID</th><th>First seen</th><th>Last seen</th><th>Related accounts</th></tr>"
976+
for(var/cid in C.prefs.admin_cid_request_cache)
977+
dat += "<tr>"
978+
dat += "<td>[cid]</td>"
979+
dat += "<td>[C.prefs.admin_cid_request_cache[cid]["first_seen"]]</td>"
980+
dat += "<td>[C.prefs.admin_cid_request_cache[cid]["last_seen"]]</td>"
981+
dat += "<td>[list2text(C.prefs.admin_cid_request_cache[cid]["match"], separator = "; ")]</td>"
982+
dat += "</tr>"
983+
dat += "</table>"
964984
else
965-
var/mob/M = locate(href_list["cid_list"])
966-
if (ismob(M))
967-
if(!M.client)
968-
return
969-
var/client/C = M.client
970-
var/dat = ""
971-
dat += "<center><b>Ckey:</b> [C.ckey] | <b>Ignore warning:</b> [C.prefs.ignore_cid_warning ? "yes" : "no"]</center>"
972-
for(var/x in C.prefs.cid_list)
973-
dat += "<b>computer_id:</b> [x] - <b>first seen:</b> [C.prefs.cid_list[x]["first_seen"]] - <b>last seen:</b> [C.prefs.cid_list[x]["last_seen"]]<br>"
985+
dat += "<b>No history or we can't access database</b>"
986+
dat += "<i>By default, we check only for the last 2 years and last 30 cid</i>"
974987

975-
var/datum/browser/popup = new(usr, "[C.ckey]_cid_list", "[C.ckey] cid list")
976-
popup.set_content(dat)
977-
popup.open()
988+
var/datum/browser/popup = new(usr, "[C.ckey]_cid_history", "Computer ID history for [C.ckey]", 700, 300)
989+
popup.set_content(dat)
990+
popup.open()
978991

979-
else if(href_list["cid_ignore"])
992+
else if(href_list["ip_history"])
980993
if(!check_rights(R_LOG))
981994
return
995+
996+
var/mob/M = locate(href_list["ip_history"])
997+
if (!ismob(M) || !M.client)
998+
return
999+
1000+
var/client/C = M.client
1001+
if(!C.prefs.admin_ip_request_cache)
1002+
C.prefs.admin_ip_request_cache = C.generate_ip_history()
1003+
1004+
var/dat = ""
1005+
if(length(C.prefs.admin_ip_request_cache))
1006+
dat += "<table><tr><th>CID</th><th>First seen</th><th>Last seen</th><th>Related accounts</th></tr>"
1007+
for(var/ip in C.prefs.admin_ip_request_cache)
1008+
dat += "<tr>"
1009+
dat += "<td>[ip]</td>"
1010+
dat += "<td>[C.prefs.admin_ip_request_cache[ip]["first_seen"]]</td>"
1011+
dat += "<td>[C.prefs.admin_ip_request_cache[ip]["last_seen"]]</td>"
1012+
dat += "<td>[list2text(C.prefs.admin_ip_request_cache[ip]["match"], separator = "; ")]</td>"
1013+
dat += "</tr>"
1014+
dat += "</table>"
9821015
else
983-
var/mob/M = locate(href_list["cid_ignore"])
984-
if (ismob(M))
985-
if(!M.client)
986-
return
987-
var/client/C = M.client
988-
C.prefs.ignore_cid_warning = !(C.prefs.ignore_cid_warning)
989-
log_admin("[key_name(usr)] has [C.prefs.ignore_cid_warning ? "disabled" : "enabled"] multiple cid notice for [C.ckey].")
990-
message_admins("[key_name_admin(usr)] has [C.prefs.ignore_cid_warning ? "disabled" : "enabled"] multiple cid notice for [C.ckey].")
1016+
dat += "<b>No history or we can't access database</b>"
1017+
dat += "<i>By default, we check only for the last 2 years and last 30 ip</i>"
1018+
1019+
var/datum/browser/popup = new(usr, "[C.ckey]_ip_history", "IP history for [C.ckey]", 700, 300)
1020+
popup.set_content(dat)
1021+
popup.open()
9911022

9921023
else if(href_list["related_accounts"])
9931024
if(!check_rights(R_LOG))

code/modules/bridge/commands/player_panel.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676

7777
// guard
7878
if(online_client)
79-
if(!length(online_client.guard.short_report))
80-
online_client.guard.prepare()
79+
if(!length(online_client.prefs.guard.short_report))
80+
online_client.prefs.guard.prepare()
8181

82-
message += "**Guard report**: [online_client.guard.short_report]"
82+
message += "**Guard report**: [online_client.prefs.guard.short_report]"
8383

8484
else
8585
message += "**Guard report**: not available for offline player"

code/modules/client/client_defines.dm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
// Set on login.
6060
var/datum/media_manager/media = null
6161

62-
var/datum/guard/guard = null
63-
6462
var/datum/tooltip/tooltips
6563

6664
var/list/datum/browser/browsers

code/modules/client/client_procs.dm

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ var/global/list/blacklisted_builds = list(
247247
if(connection != "seeker") //Invalid connection type.
248248
return null
249249

250-
if(!guard)
251-
guard = new(src)
252-
253250
// Change the way they should download resources.
254251
if(config.resource_urls)
255252
src.preload_rsc = pick(config.resource_urls)
@@ -289,26 +286,17 @@ var/global/list/blacklisted_builds = list(
289286
update_supporter_status()
290287

291288
//preferences datum - also holds some persistant data for the client (because we may as well keep these datums to a minimum)
292-
prefs = preferences_datums[ckey]
293-
if(prefs)
294-
prefs.parent = src
289+
if(preferences_datums[ckey])
290+
prefs = preferences_datums[ckey]
291+
prefs.reattach_to_client(src)
295292
else
296293
prefs = new /datum/preferences(src)
297294
preferences_datums[ckey] = prefs
295+
298296
prefs.last_ip = address //these are gonna be used for banning
299297
prefs.last_id = computer_id //these are gonna be used for banning
300298
fps = (prefs.clientfps < 0) ? RECOMMENDED_FPS : prefs.clientfps
301299

302-
var/cur_date = time2text(world.realtime, "YYYY/MM/DD hh:mm:ss")
303-
if("[computer_id]" in prefs.cid_list)
304-
prefs.cid_list["[computer_id]"]["last_seen"] = cur_date
305-
else
306-
prefs.cid_list["[computer_id]"] = list("first_seen"=cur_date, "last_seen"=cur_date)
307-
308-
if(prefs.cid_list.len > 2)
309-
log_admin("[ckey] has [prefs.cid_list.len] different computer_id.")
310-
message_admins("[ckey] has <span class='red'>[prefs.cid_list.len]</span> different computer_id.")
311-
312300
prefs.save_preferences()
313301

314302
prefs_ready = TRUE // if moved below parent call, Login feature with lobby music will be broken and maybe anything else.
@@ -545,7 +533,7 @@ var/global/list/blacklisted_builds = list(
545533
query_update.Execute()
546534
else if(!config.bunker_ban_mode)
547535
//New player!! Need to insert all the stuff
548-
guard.first_entry = TRUE
536+
prefs.guard.first_entry = TRUE
549537
var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_player (id, ckey, firstseen, lastseen, ip, computerid, lastadminrank, ingameage) VALUES (null, '[sql_ckey]', Now(), Now(), '[sql_ip]', '[sql_computerid]', '[sql_admin_rank]', '[sql_player_ingame_age]')")
550538
query_insert.Execute()
551539

@@ -558,6 +546,76 @@ var/global/list/blacklisted_builds = list(
558546
var/DBQuery/query_accesslog = dbcon.NewQuery("INSERT INTO `erro_connection_log`(`id`,`datetime`,`serverip`,`ckey`,`ip`,`computerid`) VALUES(null,Now(),'[serverip]','[sql_ckey]','[sql_ip]','[sql_computerid]');")
559547
query_accesslog.Execute()
560548

549+
query_accesslog = dbcon.NewQuery("SELECT count(DISTINCT computerid) from erro_connection_log where ckey='[sql_ckey]';")
550+
query_accesslog.Execute()
551+
552+
if(query_accesslog.NextRow())
553+
prefs.cid_count = text2num(query_accesslog.item[1])
554+
555+
/client/proc/generate_cid_history(years = 2, hardcap = 30)
556+
if(!establish_db_connection("erro_connection_log"))
557+
return FALSE
558+
559+
var/sql_ckey = ckey(ckey)
560+
var/years_cap_sql
561+
var/hard_cap_sql
562+
if(years && isnum(years))
563+
years_cap_sql = "AND datetime > (Now() - interval [years] year)"
564+
if(hardcap && isnum(hardcap))
565+
hard_cap_sql = "LIMIT [hardcap]"
566+
567+
var/list/cid_list = list()
568+
569+
var/DBQuery/query = dbcon.NewQuery("SELECT computerid, MIN(datetime) as first, MAX(datetime) as last from erro_connection_log WHERE ckey='[sql_ckey]' [years_cap_sql] GROUP BY computerid ORDER BY last DESC [hard_cap_sql];")
570+
query.Execute()
571+
while(query.NextRow())
572+
cid_list[query.item[1]] = list("first_seen" = query.item[2], "last_seen" = query.item[3])
573+
574+
for(var/query_cid in cid_list)
575+
var/list/match_ckeys = list()
576+
577+
query = dbcon.NewQuery("SELECT DISTINCT ckey from erro_connection_log WHERE computerid = '[query_cid]' AND ckey!='[sql_ckey]';")
578+
query.Execute()
579+
while(query.NextRow())
580+
match_ckeys += query.item[1]
581+
582+
if(length(match_ckeys))
583+
cid_list[query_cid]["match"] = match_ckeys
584+
585+
return cid_list
586+
587+
/client/proc/generate_ip_history(years = 2, hardcap = 30)
588+
if(!establish_db_connection("erro_connection_log"))
589+
return FALSE
590+
591+
var/sql_ckey = ckey(ckey)
592+
var/years_cap_sql
593+
if(years && isnum(years))
594+
years_cap_sql = "AND datetime > (Now() - interval [years] year)"
595+
var/hard_cap_sql
596+
if(hardcap && isnum(hardcap))
597+
hard_cap_sql = "LIMIT [hardcap]"
598+
599+
var/list/ip_list = list()
600+
601+
var/DBQuery/query = dbcon.NewQuery("SELECT ip, MIN(datetime) as first, MAX(datetime) as last from erro_connection_log WHERE ckey='[sql_ckey]' [years_cap_sql] GROUP BY ip ORDER BY last DESC [hard_cap_sql];")
602+
query.Execute()
603+
while(query.NextRow())
604+
ip_list[query.item[1]] = list("first_seen" = query.item[2], "last_seen" = query.item[3])
605+
606+
for(var/query_ip in ip_list)
607+
var/list/match_ckeys = list()
608+
609+
query = dbcon.NewQuery("SELECT DISTINCT ckey from erro_connection_log WHERE ip = '[query_ip]' AND ckey!='[sql_ckey]';")
610+
query.Execute()
611+
while(query.NextRow())
612+
match_ckeys += query.item[1]
613+
614+
if(length(match_ckeys))
615+
ip_list[query_ip]["match"] = match_ckeys
616+
617+
return ip_list
618+
561619
/client/proc/check_randomizer(topic)
562620
. = FALSE
563621
if (connection != "seeker")

code/modules/client/guard.dm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var/global/list/guard_blacklist = list("IP" = list(), "ISP" = list())
22

33
/datum/guard
44
var/client/holder
5+
56
var/total_alert_weight = 0
67
var/bridge_reported = FALSE
78

@@ -31,6 +32,7 @@ var/global/list/guard_blacklist = list("IP" = list(), "ISP" = list())
3132
addtimer(CALLBACK(src, PROC_REF(trigger_init)), 20 SECONDS) // time for other systems to collect data
3233

3334
/datum/guard/proc/trigger_init()
35+
// if client was lost somehow, mob/login should restart test again
3436
if(holder && isnum(holder.player_ingame_age) && holder.player_ingame_age < GUARD_CHECK_AGE)
3537
load_geoip() // this may takes a few minutes in bad case
3638

@@ -171,19 +173,19 @@ var/global/list/guard_blacklist = list("IP" = list(), "ISP" = list())
171173

172174
total_alert_weight += related_db_weight
173175

174-
if(holder.prefs.cid_list.len > 1)
176+
if(holder.prefs.cid_count > 1)
175177
var/multicid_weight = 0
176178
var/allowed_amount = 1
177179

178180
if(isnum(holder.player_age) && holder.player_age > 60)
179181
allowed_amount++
180182

181-
multicid_weight += min(((holder.prefs.cid_list.len - allowed_amount) * 0.35), 2) // new account, should not be many. 4 cids in the first hour -> +1 weight
183+
multicid_weight += min(((holder.prefs.cid_count - allowed_amount) * 0.35), 2) // new account, should not be many. 4 cids in the first hour -> +1 weight
182184

183185
new_report += {"<div class='Section'><h3>Differents CID's ([multicid_weight]):</h3>
184-
Has [holder.prefs.cid_list.len] different computer_id.</div>"}
186+
Has [holder.prefs.cid_count] different computer_id.</div>"}
185187

186-
new_short_report += "Has [holder.prefs.cid_list.len] CID's (tw: [multicid_weight]); "
188+
new_short_report += "Has [holder.prefs.cid_count] CID's (tw: [multicid_weight]); "
187189

188190
total_alert_weight += multicid_weight
189191

0 commit comments

Comments
 (0)