/* * Library Computer */ /obj/machinery/computer/library/checkout name = "Check-In/Out Computer" icon = 'icons/obj/library.dmi' icon_state = "computer" anchored = 1 density = 1 var/arcanecheckout = 0 //var/screenstate = 0 // 0 - Main Menu, 1 - Inventory, 2 - Checked Out, 3 - Check Out a Book var/buffer_book var/buffer_mob var/upload_category = "Fiction" var/list/checkouts = list() var/list/inventory = list() var/checkoutperiod = 5 // In minutes var/obj/machinery/libraryscanner/scanner // Book scanner that will be used when uploading books to the Archive var/bibledelay = 0 // LOL NO SPAM (1 minute delay) -- Doohl var/booklist machine_flags = EMAGGABLE /obj/machinery/computer/library/checkout/attack_hand(var/mob/user as mob) if(..()) return interact(user) /obj/machinery/computer/library/checkout/interact(var/mob/user) if(interact_check(user)) return var/dat="" switch(screenstate) if(0) // Main Menu dat += {"
  1. View General Inventory
  2. View Checked Out Inventory
  3. Check out a Book
  4. Connect to External Archive
  5. Upload New Title to Archive
  6. Print a Bible
  7. Print a Manual
  8. "} if(src.emagged) dat += "
  9. Access the Forbidden Lore Vault
  10. " dat += "
" if(src.arcanecheckout) new /obj/item/weapon/tome(src.loc) to_chat(user, "Your sanity barely endures the seconds spent in the vault's browsing window. The only thing to remind you of this when you stop browsing is a dusty old tome sitting on the desk. You don't really remember printing it.") user.visible_message("[user] stares at the blank screen for a few moments, his expression frozen in fear. When he finally awakens from it, he looks a lot older.", 2) src.arcanecheckout = 0 if(1) // Inventory dat += "

Inventory

" for(var/obj/item/weapon/book/b in inventory) dat += "[b.name] (Delete)
" dat += "(Return to main menu)
" if(2) // Checked Out dat += "

Checked Out Books


" for(var/datum/borrowbook/b in checkouts) var/timetaken = world.time - b.getdate //timetaken *= 10 timetaken /= 600 timetaken = round(timetaken) var/timedue = b.duedate - world.time //timedue *= 10 timedue /= 600 if(timedue <= 0) timedue = "(OVERDUE) [timedue]" else timedue = round(timedue) dat += {"\"[b.bookname]\", Checked out to: [b.mobname]
--- Taken: [timetaken] minutes ago, Due: in [timedue] minutes
(Check In)

"} dat += "(Return to main menu)
" if(3) // Check Out a Book dat += {"

Check Out a Book


Book: [src.buffer_book] \[Edit\]
Recipient: [src.buffer_mob] \[Edit\]
Checkout Date : [world.time/600]
Due Date: [(world.time + checkoutperiod)/600]
(Checkout Period: [checkoutperiod] minutes) (+/-) (Commit Entry)
(Return to main menu)
"} if(4) dat += "

External Archive

" if(!dbcon_old.IsConnected()) dat += "ERROR: Unable to contact External Archive. Please contact your system administrator for assistance." else num_results = src.get_num_results() num_pages = Ceiling(num_results/LIBRARY_BOOKS_PER_PAGE) dat += {""} var/pagelist = get_pagelist() dat += {"

Search Settings


Filter by Title: [query.title]
Filter by Category: [query.category]
Filter by Author: [query.author]
\[Start Search\]
"} dat += pagelist dat += {"
"} dat += {""} for(var/datum/cachedbook/CB in get_page(page_num)) var/author = CB.author var/controls = "\[Order\]" if(user.check_rights(R_ADMIN)) controls += " \[Delete\]" author += " ([ckey(CB.ckey)]))" dat += {""} dat += "
Author Title Category Controls
[author] [CB.title] [CB.category] [controls]

[pagelist]" dat += "
(Return to main menu)
" if(5) dat += "

Upload a New Title

" if(!scanner) for(var/obj/machinery/libraryscanner/S in range(9)) scanner = S break if(!scanner) dat += "No scanner found within wireless network range.
" else if(!scanner.cache) dat += "No data found in scanner memory.
" else dat += {"Data marked for upload...
Title: [scanner.cache.name]
"} if(!scanner.cache.author) scanner.cache.author = "Anonymous" dat += {"Author: [scanner.cache.author]
Category: [upload_category]
\[Upload\]
"} dat += "(Return to main menu)
" if(7) dat += "

Print a Manual

" dat += "" var/list/forbidden = list( /obj/item/weapon/book/manual ) if(!emagged) forbidden |= /obj/item/weapon/book/manual/nuclear var/manualcount = 1 var/obj/item/weapon/book/manual/M = null for(var/manual_type in typesof(/obj/item/weapon/book/manual)) if (!(manual_type in forbidden)) M = new manual_type() dat += "" qdel(M) M = null manualcount++ dat += "
[M.title]
" dat += "
(Return to main menu)
" if(8) dat += {"

Accessing Forbidden Lore Vault v 1.3

Are you absolutely sure you want to proceed? EldritchTomes Inc. takes no responsibilities for loss of sanity resulting from this action.

Yes.
No.
"} var/datum/browser/B = new /datum/browser/clean(user, "library", "Book Inventory Management") B.set_content(dat) B.open() /obj/machinery/computer/library/checkout/emag(mob/user) if(!emagged) src.emagged = 1 if(user) to_chat(user, "You override the library computer's printing restrictions.") return 1 return /obj/machinery/computer/library/checkout/attackby(obj/item/weapon/W as obj, mob/user as mob) if(istype(W, /obj/item/weapon/barcodescanner)) var/obj/item/weapon/barcodescanner/scanner = W scanner.computer = src to_chat(user, "[scanner]'s associated machine has been set to [src].") for (var/mob/V in hearers(src)) V.show_message("[src] lets out a low, short blip.", 2) else return ..() /obj/machinery/computer/library/checkout/Topic(href, href_list) if(..()) usr << browse(null, "window=library") onclose(usr, "library") return 1 if(href_list["pagenum"]) if(!num_pages) page_num = 0 else var/pn = text2num(href_list["pagenum"]) if(!isnull(pn)) page_num = Clamp(pn, 0, num_pages) if(href_list["page"]) if(num_pages == 0) page_num = 0 else page_num = Clamp(text2num(href_list["page"]), 0, num_pages) if(href_list["settitle"]) var/newtitle = input("Enter a title to search for:") as text|null if(newtitle) query.title = sanitize(newtitle) else query.title = null if(href_list["setcategory"]) var/newcategory = input("Choose a category to search for:") in (list("Any") + library_section_names) if(newcategory == "Any") query.category = null else query.category = sanitize(newcategory) if(href_list["setauthor"]) var/newauthor = input("Enter an author to search for:") as text|null if(newauthor) query.author = sanitize(newauthor) else query.author = null if(href_list["search"]) num_results = src.get_num_results() num_pages = Ceiling(num_results/LIBRARY_BOOKS_PER_PAGE) page_num = 0 screenstate = 4 if(href_list["del"]) if(!usr.check_rights(R_ADMIN)) to_chat(usr, "You aren't an admin, piss off.") return var/datum/cachedbook/target = getBookByID(href_list["del"]) // Sanitized in getBookByID var/ans = alert(usr, "Are you sure you wish to delete \"[target.title]\", by [target.author]? This cannot be undone.", "Library System", "Yes", "No") if(ans=="Yes") var/DBQuery/query = dbcon_old.NewQuery("DELETE FROM library WHERE id=[target.id]") var/response = query.Execute() if(!response) to_chat(usr, query.ErrorMsg()) return log_admin("LIBRARY: [usr.name]/[usr.key] has deleted \"[target.title]\", by [target.author] ([target.ckey])!") message_admins("[key_name_admin(usr)] has deleted \"[target.title]\", by [target.author] ([target.ckey])!") src.updateUsrDialog() return if(href_list["delbyckey"]) if(!usr.check_rights(R_ADMIN)) to_chat(usr, "You aren't an admin, piss off.") return var/tckey = ckey(href_list["delbyckey"]) var/ans = alert(usr,"Are you sure you wish to delete all books by [tckey]? This cannot be undone.", "Library System", "Yes", "No") if(ans=="Yes") var/DBQuery/query = dbcon_old.NewQuery("DELETE FROM library WHERE ckey='[sanitizeSQL(tckey)]'") var/response = query.Execute() if(!response) to_chat(usr, query.ErrorMsg()) return var/affected=query.RowsAffected() if(affected==0) to_chat(usr, "Unable to find any matching rows.") return log_admin("LIBRARY: [usr.name]/[usr.key] has deleted [affected] books written by [tckey]!") message_admins("[key_name_admin(usr)] has deleted [affected] books written by [tckey]!") src.updateUsrDialog() return if(href_list["switchscreen"]) switch(href_list["switchscreen"]) if("0") screenstate = 0 if("1") screenstate = 1 if("2") screenstate = 2 if("3") screenstate = 3 if("4") screenstate = 4 if("5") screenstate = 5 if("6") if(!bibledelay) bibledelay = 1 var/obj/item/weapon/storage/bible/B = new B = new(src.loc) if (usr.mind && usr.mind.faith) // The user has a faith var/datum/religion/R = usr.mind.faith var/obj/item/weapon/storage/bible/HB = R.holy_book if (!HB) B = chooseBible(R, usr) else B.icon_state = HB.icon_state B.item_state = HB.item_state B.name = R.bible_name B.my_rel = R else if (ticker.religions.len) // No faith var/datum/religion/R = input(usr, "Which holy book?") as anything in ticker.religions if(!R.holy_book) return B.icon_state = R.holy_book.icon_state B.item_state = R.holy_book.item_state B.name = R.bible_name B.my_rel = R B.forceMove(src.loc) spawn(60) bibledelay = 0 else visible_message("[src]'s monitor flashes, \"Bible printer currently unavailable, please wait a moment.\"") if("7") screenstate = 7 if("8") screenstate = 8 if(href_list["arccheckout"]) if(src.emagged) src.arcanecheckout = 1 src.screenstate = 0 if(href_list["increasetime"]) checkoutperiod += 1 if(href_list["decreasetime"]) checkoutperiod -= 1 if(checkoutperiod < 1) checkoutperiod = 1 if(href_list["editbook"]) buffer_book = copytext(sanitize(input("Enter the book's title:") as text|null),1,MAX_MESSAGE_LEN) if(href_list["editmob"]) buffer_mob = copytext(sanitize(input("Enter the recipient's name:") as text|null),1,MAX_NAME_LEN) if(href_list["checkout"]) var/datum/borrowbook/b = new /datum/borrowbook b.bookname = sanitize(buffer_book) b.mobname = sanitize(buffer_mob) b.getdate = world.time b.duedate = world.time + (checkoutperiod * 600) checkouts.Add(b) if(href_list["checkin"]) var/datum/borrowbook/b = locate(href_list["checkin"]) checkouts.Remove(b) if(href_list["delbook"]) var/obj/item/weapon/book/b = locate(href_list["delbook"]) inventory.Remove(b) if(href_list["uploadauthor"]) var/newauthor = copytext(sanitize(input("Enter the author's name: ") as text|null),1,MAX_MESSAGE_LEN) if(newauthor && scanner) scanner.cache.author = newauthor if(href_list["uploadcategory"]) var/newcategory = input("Choose a category: ") in library_section_names if(newcategory) upload_category = newcategory if(href_list["upload"]) if(scanner) if(scanner.cache) var/choice = input("Are you certain you wish to upload this title to the Archive?") in list("Confirm", "Abort") if(choice == "Confirm") establish_old_db_connection() if(!dbcon_old.IsConnected()) alert("Connection to Archive has been severed. Aborting.") else var/sqltitle = sanitizeSQL(scanner.cache.name) var/sqlauthor = sanitizeSQL(scanner.cache.author) var/sqlcontent = sanitizeSQL(scanner.cache.dat) var/sqlcategory = sanitizeSQL(upload_category) var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO library (author, title, content, category, ckey) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]', '[ckey(usr.key)]')") var/response = query.Execute() if(!response) to_chat(usr, query.ErrorMsg()) else world.log << response log_admin("[usr.name]/[usr.key] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] characters in length") message_admins("[key_name_admin(usr)] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] characters in length") if(href_list["id"]) if(href_list["id"]=="-1") href_list["id"] = input("Enter your order:") as null|num if(!href_list["id"]) return if(!dbcon_old.IsConnected()) alert("Connection to Archive has been severed. Aborting.") return var/datum/cachedbook/newbook = getBookByID(href_list["id"]) // Sanitized in getBookByID if(!newbook) alert("No book found") return if((newbook.forbidden == 2 && !emagged) || newbook.forbidden == 1) alert("This book is forbidden and cannot be printed.") return if(bibledelay) for (var/mob/V in hearers(src)) V.show_message("[src]'s monitor flashes, \"Printer unavailable. Please allow a short time before attempting to print.\"") else bibledelay = 1 spawn(60) bibledelay = 0 make_external_book(newbook) if(href_list["manual"]) if(!href_list["manual"]) return var/bookid = href_list["manual"] if(!dbcon_old.IsConnected()) alert("Connection to Archive has been severed. Aborting.") return var/datum/cachedbook/newbook = getBookByID("M[bookid]") if(!newbook) alert("No book found") return if((newbook.forbidden == 2 && !emagged) || newbook.forbidden == 1) alert("This book is forbidden and cannot be printed.") return if(bibledelay) for (var/mob/V in hearers(src)) V.show_message("[src]'s monitor flashes, \"Printer unavailable. Please allow a short time before attempting to print.\"") else bibledelay = 1 spawn(60) bibledelay = 0 make_external_book(newbook) src.add_fingerprint(usr) src.updateUsrDialog() return /* * Library Scanner */ /obj/machinery/computer/library/checkout/proc/make_external_book(var/datum/cachedbook/newbook) if(!newbook || !newbook.id) return var/obj/item/weapon/book/B = new newbook.path(src.loc) if (!newbook.programmatic) var/list/_http = world.Export("http://ss13.moe/index.php/book?id=[newbook.id]") if(!_http || !_http["CONTENT"]) return var/http = file2text(_http["CONTENT"]) if(!http) return B.name = "Book: [newbook.title]" B.title = newbook.title B.author = newbook.author B.dat = http B.icon_state = "book[rand(1,9)]" B.item_state = B.icon_state src.visible_message("[src]'s printer hums as it produces a completely bound book. How did it do that?")