Skip to content

Commit

Permalink
TGS Test Merge (#8369)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm13-github committed Feb 13, 2025
2 parents 4bb45c2 + 4f68835 commit b140b2e
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 52 deletions.
129 changes: 103 additions & 26 deletions code/modules/admin/NewBan.dm
Original file line number Diff line number Diff line change
Expand Up @@ -167,37 +167,114 @@ GLOBAL_DATUM(Banlist, /savefile)
timeleftstring = "[exp] Minutes"
return timeleftstring

/datum/admins/proc/unbanpanel()
var/data = {"
<B>Bans:</B> <span class='[INTERFACE_BLUE]'>(UP) = Unban Perma (UT) = Unban Timed"
</span> - <span class='[INTERFACE_GREEN]'>Ban Listing</span>
<br>
<input type='search' id='filter' onkeyup='handle_filter()' onblur='handle_filter()' name='filter_text' value='' style='width:100%;'>
<br>
<table border=1 rules=all frame=void cellspacing=0 cellpadding=3 id='searchable'>
"}

var/list/datum/view_record/players/PBV = DB_VIEW(/datum/view_record/players, DB_OR(DB_COMP("is_permabanned", DB_EQUALS, 1), DB_COMP("is_time_banned", DB_EQUALS, 1))) // a filter

for(var/datum/view_record/players/ban in PBV)
var/expiry
if(!ban.is_permabanned)
expiry = GetExp(ban.expiration)
/datum/unban_panel

/// The search term that is currently in use
var/search

/datum/unban_panel/tgui_interact(mob/user, datum/tgui/ui)
. = ..()

ui = SStgui.try_update_ui(user, src, ui)
if (!ui)
ui = new(user, src, "UnbanPanel", "Unban Panel")
ui.set_autoupdate(FALSE)
ui.open()

/datum/unban_panel/ui_state(mob/user)
return GLOB.admin_state

/datum/unban_panel/ui_data(mob/user)
. = ..()

var/list/datum/view_record/players/banned_players = DB_VIEW(/datum/view_record/players,
DB_AND(
DB_COMP("ckey", DB_EQUALS, search),
DB_OR(
DB_COMP("is_permabanned", DB_EQUALS, TRUE),
DB_COMP("is_time_banned", DB_EQUALS, TRUE)
)))

.["banned_players"] = list()
for(var/datum/view_record/players/player in banned_players)
var/expiry = "Permaban"
if(!player.is_permabanned)
expiry = GetExp(player.expiration)
if(!expiry)
expiry = "Removal Pending"
else
expiry = "Permaban"
var/unban_link
if(ban.is_permabanned)
unban_link = "<a href='byond://?src=\ref[src];[HrefToken()];unban_perma=[ban.ckey]'>(UP)</a>"
else
unban_link = "<A href='byond://?src=\ref[src];[HrefToken(forceGlobal = TRUE)];unbanf=[ban.ckey]'>(UT)</A>"

data += "<tr><td>[unban_link] Key: <B>[ban.ckey]</B></td><td>ComputerID: <B>[ban.last_known_cid]</B></td><td>IP: <B>[ban.last_known_ip]</B></td><td> [expiry]</td><td>(By: [ban.admin ? ban.admin : "AdminBot"])</td><td>(Reason: [ban.reason])</td></tr>"
.["banned_players"] += list(
list(
"ckey" = player.ckey,
"ip" = player.last_known_ip,
"cid" = player.last_known_cid,
"permaban" = player.is_permabanned,
"timeban" = player.is_time_banned,
"expiry" = expiry,
"admin" = player.admin,
"reason" = player.reason,
)
)

data += "</table>"
.["search"] = search

/datum/unban_panel/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()

var/mob/user = ui.user

switch(action)
if("change_search")
var/new_search = ckey(params["ckey"])
if(!length(new_search))
return

show_browser(usr, data, "Unban Panel", "unbanp", "size=875x400")
search = new_search
return TRUE

if("unban_timed")
var/ckey_to_unban = ckey(params["ckey"])
if(!length(ckey_to_unban))
return

var/datum/entity/player/unban_player = get_player_from_key(ckey_to_unban)
if(tgui_alert("Are you sure you want to remove timed ban from [unban_player.ckey]?", "Confirm", list("Yes", "No")) == "No")
return

if(!unban_player.remove_timed_ban())
tgui_alert(user, "This ban has already been lifted / does not exist.", "Error", list("Ok"))

return TRUE

if("unban_perma")
var/ckey_to_unban = ckey(params["ckey"])
if(!length(ckey_to_unban))
return

var/datum/entity/player/unban_player = get_player_from_key(ckey_to_unban)
if(!(tgui_alert(user, "Do you want to unban [unban_player.ckey]? They are currently permabanned for: [unban_player.permaban_reason], since [unban_player.permaban_date].", "Unban Player", list("Yes", "No")) == "Yes"))
return

if(!unban_player.is_permabanned)
to_chat(user, SPAN_WARNING("The player is not currently permabanned."))
return

unban_player.is_permabanned = FALSE
unban_player.permaban_admin_id = null
unban_player.permaban_date = null
unban_player.permaban_reason = null

unban_player.save()

message_admins("[key_name_admin(user)] has removed the permanent ban on [unban_player.ckey].")
important_message_external("[user.ckey] has removed the permanent ban on [unban_player.ckey].", "Permaban Removed")

return TRUE


/datum/admins/proc/unbanpanel()
var/datum/unban_panel/unban_panel = new
unban_panel.tgui_interact(owner.mob)

/datum/admins/proc/stickypanel()
var/add_sticky = "<a href='byond://?src=\ref[src];[HrefToken()];sticky=1;new_sticky=1'>Add Sticky Ban</a>"
Expand Down
26 changes: 0 additions & 26 deletions code/modules/admin/topic/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -262,32 +262,6 @@
X.set_hive_and_update(hivenumber)

/////////////////////////////////////new ban stuff
else if(href_list["unbanf"])
var/datum/entity/player/P = get_player_from_key(href_list["unbanf"])
switch(alert("Are you sure you want to remove timed ban from [P.ckey]?", , "Yes", "No"))
if("No")
return
if(!P.remove_timed_ban())
alert(usr, "This ban has already been lifted / does not exist.", "Error", "Ok")
unbanpanel()

else if(href_list["unban_perma"])
var/datum/entity/player/unban_player = get_player_from_key(href_list["unban_perma"])
if(!(tgui_alert(owner, "Do you want to unban [unban_player.ckey]? They are currently permabanned for: [unban_player.permaban_reason], since [unban_player.permaban_date].", "Unban Player", list("Yes", "No")) == "Yes"))
return

if(!unban_player.is_permabanned)
to_chat(owner, "The player is not currently permabanned.")

unban_player.is_permabanned = FALSE
unban_player.permaban_admin_id = null
unban_player.permaban_date = null
unban_player.permaban_reason = null

unban_player.save()

message_admins("[key_name_admin(owner)] has removed the permanent ban on [unban_player.ckey].")
important_message_external("[owner] has removed the permanent ban on [unban_player.ckey].", "Permaban Removed")

else if(href_list["sticky"])
if(href_list["view_all_ckeys"])
Expand Down
80 changes: 80 additions & 0 deletions tgui/packages/tgui/interfaces/UnbanPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useBackend } from '../backend';
import { Button, Input, Stack, Table } from '../components';
import { Window } from '../layouts';

type UnbanData = {
banned_players: Ban[];
search: string;
};

type Ban = {
ckey: string;
ip: string;
cid: string;
permaban: boolean;
timeban: boolean;
expiry: string;
admin: string;
reason: string;
};

export const UnbanPanel = () => {
const { data, act } = useBackend<UnbanData>();

const { banned_players, search } = data;

return (
<Window width={850} height={450}>
<Window.Content>
<Stack vertical>
<Stack.Item>
<Stack justify="end">
<Stack.Item>
<Input
placeholder="Search..."
value={search}
onChange={(_, val) => {
act('change_search', { ckey: val });
}}
/>
</Stack.Item>
</Stack>
</Stack.Item>
<Stack.Item>
<Table>
<Table.Row header>
<Table.Cell>Ckey</Table.Cell>
<Table.Cell>IP</Table.Cell>
<Table.Cell>CID</Table.Cell>
<Table.Cell>Reason</Table.Cell>
<Table.Cell>Admin</Table.Cell>
<Table.Cell>Expiry</Table.Cell>
</Table.Row>
{banned_players.map((ban) => (
<Table.Row key={ban.ckey}>
<Table.Cell>{ban.ckey}</Table.Cell>
<Table.Cell>{ban.ip}</Table.Cell>
<Table.Cell>{ban.cid}</Table.Cell>
<Table.Cell>{ban.reason}</Table.Cell>
<Table.Cell>{ban.admin}</Table.Cell>
<Table.Cell>{ban.expiry}</Table.Cell>
<Table.Cell width="30px">
<Button
onClick={() => {
act(ban.permaban ? 'unban_perma' : 'unban_timed', {
ckey: ban.ckey,
});
}}
>
Unban
</Button>
</Table.Cell>
</Table.Row>
))}
</Table>
</Stack.Item>
</Stack>
</Window.Content>
</Window>
);
};

0 comments on commit b140b2e

Please sign in to comment.