Skip to content

Commit

Permalink
add: Added book flag tracking and view flagged books does not crash s…
Browse files Browse the repository at this point in the history
…erver (#4191)
  • Loading branch information
Vladisvell authored Feb 20, 2024
1 parent 54216fe commit aaa5068
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions SQL/updates/32-33.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Adds tracking of who flagged which book.
ALTER TABLE `library` ADD COLUMN `flaggedby` VARCHAR(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ' ' AFTER `flagged`;
2 changes: 1 addition & 1 deletion code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
#define EXPLOSION_BLOCK_PROC -1

// The SQL version required by this version of the code
#define SQL_VERSION 32
#define SQL_VERSION 33

// Vending machine stuff
#define CAT_NORMAL 1
Expand Down
7 changes: 4 additions & 3 deletions code/modules/library/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
if(!usr.client.holder)
return

var/dat = {"<meta charset="UTF-8"><table><tr><th>ISBN</th><th>Title</th><th>Total Flags</th><th>Options</th></tr>"}
var/dat = {"<meta charset="UTF-8"><table><tr><th>ISBN</th><th>Title</th><th>Total Flags</th><th>Flagged by (Last ckey)</th><th>Options</th></tr>"}

var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, title, flagged FROM [format_table_name("library")] WHERE \
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, title, flagged, flaggedby FROM [format_table_name("library")] WHERE \
flagged > 0 ORDER BY flagged DESC LIMIT :lowerlimit, :upperlimit", list(
"lowerlimit" = text2num((page_num - 1) * FLAGGED_BOOKS_PER_PAGE),
"upperlimit" = FLAGGED_BOOKS_PER_PAGE
))


if(!query.warn_execute())
qdel(query)
return
Expand All @@ -53,7 +54,7 @@
while(query.NextRow())
books++
var/isbn = query.item[1]
dat += "<tr><td>[add_zero(isbn, 4)]</td><td>[query.item[2]]</td><td>[query.item[3]]</td><td>"
dat += "<tr><td>[add_zero(isbn, 4)]</td><td>[query.item[2]]</td><td>[query.item[3]]</td><td>[query.item[4]]</td><td>"
dat += "<a href='?_src_=holder;library_book_id=[isbn];view_library_book=1;'>View Content</a>"
dat += "<a href='?_src_=holder;library_book_id=[isbn];unflag_library_book=1;'>Unflag</a>"
dat += "<a href='?_src_=holder;library_book_id=[isbn];delete_library_book=1;'>Delete</a>"
Expand Down
12 changes: 8 additions & 4 deletions code/modules/library/lib_machines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A
var/forbidden=0
var/path = /obj/item/book // Type path of the book to generate
var/flagged = 0
var/flaggedby

/datum/cachedbook/proc/LoadFromRow(var/list/row)
id = row["id"]
Expand All @@ -34,6 +35,7 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A
category = row["category"]
ckey = row["ckey"]
flagged = row["flagged"]
flaggedby = row["flaggedby"]
if("content" in row)
content = row["content"]
programmatic=0
Expand Down Expand Up @@ -80,8 +82,9 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A

log_game("[user] (ckey: [user.key]) has flagged book #[id] as inappropriate.")

var/datum/db_query/query = SSdbcore.NewQuery("UPDATE [format_table_name("library")] SET flagged = flagged + 1 WHERE id=:id", list(
"id" = text2num(id)
var/datum/db_query/query = SSdbcore.NewQuery("UPDATE [format_table_name("library")] SET flagged = flagged + 1, flaggedby=:flaggedby WHERE id=:id", list(
"id" = text2num(id),
"flaggedby" = user.key
))
if(!query.warn_execute())
qdel(query)
Expand All @@ -107,7 +110,7 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A
if("[id]" in cached_books)
return cached_books["[id]"]

var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category, content, ckey, flagged FROM [format_table_name("library")] WHERE id=:id", list(
var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category, content, ckey, flagged, flaggedby FROM [format_table_name("library")] WHERE id=:id", list(
"id" = text2num(id)
))
if(!query.warn_execute())
Expand All @@ -124,7 +127,8 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A
"category"=query.item[4],
"content" =query.item[5],
"ckey" =query.item[6],
"flagged" =query.item[7]
"flagged" =query.item[7],
"flaggedby"=query.item[8]
))
results += CB
cached_books["[id]"]=CB
Expand Down
2 changes: 1 addition & 1 deletion config/example/dbconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## This value must be set to the version of the paradise schema in use.
## If this value does not match, the SQL database will not be loaded and an error will be generated.
## Roundstart will be delayed.
DB_VERSION 32
DB_VERSION 33

## Server the MySQL database can be found at.
# Examples: localhost, 200.135.5.43, www.mysqldb.com, etc.
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/dbconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Dont use it ingame
# Remember to update this when you increase the SQL version! -aa
SQL_ENABLED
DB_VERSION 32
DB_VERSION 33
ADDRESS 127.0.0.1
PORT 3306
FEEDBACK_DATABASE feedback
Expand Down

0 comments on commit aaa5068

Please sign in to comment.