Files
siliconsGitHubVM_USER <VM_USER>
7dffc24138 DBCore (#4205)
* clown time

* let the shitfest begin

* wild

* kill me

* sad

* format

* regex

* erase manual dbcore connect procs

* fix async

* replacements, RunQuery()

* replacements

* more

* update

* epic

* fix

* a

* a

* more queries

* queries

* queries

* queries

* test

* 4

* conversions

* fix

* a

* that

* prefixed

* connection log

* schema

* prefixed

* wack

* oops

* fix

* Travis gaming

* rid that

* a

* prefix that

* prefix that

* OH THATS IMPORTANT

* bandaid

* fixes

* Update database_changelog.md

Co-authored-by: VM_USER <VM_USER>
2022-08-02 02:51:01 -07:00

127 lines
3.1 KiB
Plaintext

#define BOOK_VERSION_MIN 1
#define BOOK_VERSION_MAX 2
#define BOOK_PATH "data/books/"
/// no guarentee for this branch to work right with sql
#define BOOKS_USE_SQL 0
var/global/datum/book_manager/book_mgr = new()
datum/book_manager/proc/path(id)
if(isnum(id)) // kill any path exploits
return "[BOOK_PATH][id].sav"
datum/book_manager/proc/getall()
var/list/paths = flist(BOOK_PATH)
var/list/books = new()
for(var/path in paths)
var/datum/archived_book/B = new(BOOK_PATH + path)
books += B
return books
datum/book_manager/proc/freeid()
var/list/paths = flist(BOOK_PATH)
var/id = paths.len + 101
// start at 101+number of books, which will be correct id if none have been deleted, etc
// otherwise, keep moving forward until we find an open id
while(fexists(path(id)))
id++
return id
/client/proc/delbook()
set name = "Delete Book"
set desc = "Permamently deletes a book from the database."
set category = "Admin"
if(!src.holder)
to_chat(src, "Only administrators may use this command.")
return
var/isbn = input("ISBN number?", "Delete Book") as num | null
if(!isbn)
return
if(BOOKS_USE_SQL && CONFIG_GET(flag/sql_enabled))
var/DBConnection/dbcon = new()
dbcon.Connect("dbi:mysql:[sqldb]:[sqladdress]:[sqlport]","[sqllogin]","[sqlpass]")
if(!SSdbcore.Connect())
alert("Connection to Archive has been severed. Aborting.")
else
var/datum/db_query/query = dbcon.NewQuery("DELETE FROM library WHERE id=[isbn]")
if(!query.Execute())
usr << query.ErrorMsg()
dbcon.Disconnect()
else
book_mgr.remove(isbn)
log_admin("[usr.key] has deleted the book [isbn]")
// delete a book
datum/book_manager/proc/remove(var/id)
fdel(path(id))
datum/archived_book
var/author // Who wrote the thing, can be changed by pen or PC. It is not automatically assigned
var/title // The real name of the book.
var/category // The category/genre of the book
var/id // the id of the book (like an isbn number)
var/dat // Actual page content
var/author_real // author's real_name
var/author_key // author's byond key
var/list/icon/photos // in-game photos used
// loads the book corresponding by the specified id
datum/archived_book/New(var/path)
if(isnull(path))
return
var/savefile/F = new(path)
var/version
F["version"] >> version
if (isnull(version) || version < BOOK_VERSION_MIN || version > BOOK_VERSION_MAX)
fdel(path)
to_chat(usr, "What book?")
return 0
F["author"] >> author
F["title"] >> title
F["category"] >> category
F["id"] >> id
F["dat"] >> dat
F["author_real"] >> author_real
F["author_key"] >> author_key
F["photos"] >> photos
if(!photos)
photos = new()
// let's sanitize it here too!
for(var/tag in paper_blacklist)
if(findtext(dat,"<"+tag))
dat = ""
return
datum/archived_book/proc/save()
var/savefile/F = new(book_mgr.path(id))
F["version"] << BOOK_VERSION_MAX
F["author"] << author
F["title"] << title
F["category"] << category
F["id"] << id
F["dat"] << dat
F["author_real"] << author_real
F["author_key"] << author_key
F["photos"] << photos
#undef BOOK_VERSION_MIN
#undef BOOK_VERSION_MAX
#undef BOOK_PATH