mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-29 16:10:02 +01:00
Merge pull request #228 from skull132/webinterface-integration
Webinterface integration
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
if (!ckey || !address || !computer_id || !ban_id)
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
|
||||
if (!dbcon.IsConnected())
|
||||
error("Ban database connection failure while attempting to mirror. Key passed for mirror handling: [ckey].")
|
||||
|
||||
@@ -4,7 +4,7 @@ datum/admins/proc/DB_ban_record(var/bantype, var/mob/banned_mob, var/duration =
|
||||
|
||||
if(!check_rights(R_MOD,0) && !check_rights(R_BAN)) return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
@@ -122,7 +122,7 @@ datum/admins/proc/DB_ban_unban(var/ckey, var/bantype, var/job = "")
|
||||
if(job)
|
||||
sql += " AND job = '[job]'"
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
@@ -217,7 +217,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
|
||||
|
||||
var/sql = "SELECT ckey FROM ss13_ban WHERE id = [id]"
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
@@ -269,7 +269,7 @@ datum/admins/proc/DB_ban_unban_by_id(var/id)
|
||||
|
||||
if(!check_rights(R_BAN)) return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
usr << "\red Failed to establish database connection"
|
||||
return
|
||||
|
||||
@@ -34,7 +34,7 @@ world/IsBanned(key,address,computer_id)
|
||||
|
||||
var/ckeytext = ckey(key)
|
||||
|
||||
if(!establish_db_connection())
|
||||
if(!establish_db_connection(dbcon))
|
||||
error("Ban database connection failure. Key [ckeytext] not checked")
|
||||
log_misc("Ban database connection failure. Key [ckeytext] not checked")
|
||||
return
|
||||
|
||||
@@ -102,7 +102,7 @@ var/list/admin_ranks = list() //list of all ranks with associated rights
|
||||
else
|
||||
//The current admin system uses SQL
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
error("Failed to connect to database in load_admins(). Reverting to legacy system.")
|
||||
log_misc("Failed to connect to database in load_admins(). Reverting to legacy system.")
|
||||
|
||||
@@ -65,7 +65,7 @@ DEBUG
|
||||
jobban_keylist=list()
|
||||
log_admin("jobban_keylist was empty")
|
||||
else
|
||||
if(!establish_db_connection())
|
||||
if(!establish_db_connection(dbcon))
|
||||
error("Database connection failed. Reverting to the legacy ban system.")
|
||||
log_misc("Database connection failed. Reverting to the legacy ban system.")
|
||||
config.ban_legacy_system = 1
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
usr << "\red You do not have permission to do this!"
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
|
||||
if(!dbcon.IsConnected())
|
||||
usr << "\red Failed to establish database connection"
|
||||
@@ -104,7 +104,7 @@
|
||||
usr << "\red You do not have permission to do this!"
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
usr << "\red Failed to establish database connection"
|
||||
return
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
else
|
||||
query_details[":a_ckey"] = user.ckey
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
alert("SQL connection failed while trying to add a note!")
|
||||
return
|
||||
@@ -36,7 +36,7 @@
|
||||
if (!note_id || !note_edit)
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
error("SQL connection failed while attempting to delete a note!")
|
||||
return
|
||||
@@ -93,7 +93,7 @@
|
||||
player_ckey = ckey(player_ckey)
|
||||
admin_ckey = ckey(admin_ckey)
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
error("SQL connection failed while attempting to view a player's notes!")
|
||||
return
|
||||
@@ -187,7 +187,7 @@
|
||||
if (!ckey)
|
||||
return "No ckey given!"
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
|
||||
if (!dbcon.IsConnected())
|
||||
return "Unable to establish database connection! Aborting!"
|
||||
@@ -231,7 +231,7 @@
|
||||
note_list >> note_keys
|
||||
|
||||
msg_scopes("Establishing DB connection!")
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
msg_scopes("No DB connection!")
|
||||
return
|
||||
|
||||
@@ -29,7 +29,7 @@ var/inactive_keys = "None<br>"
|
||||
if(checked_for_inactives)
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
if (!warned_ckey || !istext(warned_ckey))
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
usr << "<font color='red'>Error: warn(): Database Connection failed, reverting to legacy systems.</font>"
|
||||
usr.client.warn_legacy(warned_ckey)
|
||||
@@ -110,7 +110,7 @@
|
||||
var/dcolor = "#ffaaaa" //dark colour, severity = 1
|
||||
var/ecolor = "#e3e3e3" //gray colour, expired = 1
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
alert("Connection to the SQL database lost. Aborting. Please alert an Administrator or a member of staff.")
|
||||
return
|
||||
@@ -172,7 +172,7 @@
|
||||
if (!warning_id)
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
alert("Connection to SQL database failed while attempting to update your warning's status!")
|
||||
return
|
||||
@@ -191,7 +191,7 @@
|
||||
var/count = 0
|
||||
var/count_expire = 0
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
var/dcolor = "#ffdddd" //dark colour, severity = 1
|
||||
var/ecolor = "#e3e3e3" //gray colour, expired = 1
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
alert("Connection to the SQL database lost. Aborting. Please alert the database admin!")
|
||||
return
|
||||
@@ -342,7 +342,7 @@
|
||||
if(!warning_id || !warning_edit)
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
alert("Connection to the SQL database lost. Aborting. Please alert the database admin!")
|
||||
return
|
||||
|
||||
@@ -74,7 +74,68 @@
|
||||
if(href_list["warnview"])
|
||||
warnings_check()
|
||||
|
||||
..() //redirect to hsrc.Topic()
|
||||
if(href_list["linkingrequest"])
|
||||
if (!config.webint_url)
|
||||
return
|
||||
|
||||
if (!href_list["linkingaction"])
|
||||
return
|
||||
|
||||
var/request_id = text2num(href_list["linkingrequest"])
|
||||
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
src << "\red Action failed! Database link could not be established!"
|
||||
return
|
||||
|
||||
|
||||
var/DBQuery/check_query = dbcon.NewQuery("SELECT player_ckey, status FROM ss13_player_linking WHERE id = :id")
|
||||
check_query.Execute(list(":id" = request_id))
|
||||
|
||||
if (!check_query.NextRow())
|
||||
src << "\red No request found!"
|
||||
return
|
||||
|
||||
if (ckey(check_query.item[1]) != ckey || check_query.item[2] != "new")
|
||||
src << "\red Request authentication failed!"
|
||||
return
|
||||
|
||||
var/query_contents = ""
|
||||
var/list/query_details = list(":new_status", ":id")
|
||||
var/feedback_message = ""
|
||||
switch (href_list["linkingaction"])
|
||||
if ("accept")
|
||||
query_contents = "UPDATE ss13_player_linking SET status = :new_status, updated_at = NOW() WHERE id = :id"
|
||||
query_details[":new_status"] = "confirmed"
|
||||
query_details[":id"] = request_id
|
||||
|
||||
feedback_message = "<font color='green'><b>Account successfully linked!</b></font>"
|
||||
if ("deny")
|
||||
query_contents = "UPDATE ss13_player_linking SET status = :new_status, deleted_at = NOW() WHERE id = :id"
|
||||
query_details[":new_status"] = "rejected"
|
||||
query_details[":id"] = request_id
|
||||
|
||||
feedback_message = "<font color='red'><b>Link request rejected!</b></font>"
|
||||
else
|
||||
src << "\red Invalid command sent."
|
||||
return
|
||||
|
||||
var/DBQuery/update_query = dbcon.NewQuery(query_contents)
|
||||
update_query.Execute(query_details)
|
||||
|
||||
if (href_list["linkingaction"] == "accept" && alert("To complete the process, you have to visit the website. Do you want to do so now?",,"Yes","No") == "Yes")
|
||||
process_webint_link("interface/user/link")
|
||||
|
||||
src << feedback_message
|
||||
check_linking_requests()
|
||||
return
|
||||
|
||||
if (href_list["routeWebInt"])
|
||||
process_webint_link(href_list["routeWebInt"], href_list["routeAttributes"])
|
||||
|
||||
return
|
||||
|
||||
..() //redirect to hsrc.()
|
||||
|
||||
/client/proc/handle_spam_prevention(var/message, var/mute_type)
|
||||
if(config.automute_on && !holder && src.last_message == message)
|
||||
@@ -175,6 +236,8 @@
|
||||
|
||||
log_client_to_db()
|
||||
|
||||
check_linking_requests()
|
||||
|
||||
send_resources()
|
||||
nanomanager.send_resources(src)
|
||||
|
||||
@@ -203,7 +266,7 @@
|
||||
// Returns null if no DB connection can be established, or -1 if the requested key was not found in the database
|
||||
|
||||
/proc/get_player_age(key)
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return null
|
||||
|
||||
@@ -223,7 +286,7 @@
|
||||
if ( IsGuestKey(src.key) )
|
||||
return
|
||||
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
@@ -344,12 +407,101 @@
|
||||
)
|
||||
|
||||
|
||||
mob/proc/MayRespawn()
|
||||
/mob/proc/MayRespawn()
|
||||
return 0
|
||||
|
||||
client/proc/MayRespawn()
|
||||
/client/proc/MayRespawn()
|
||||
if(mob)
|
||||
return mob.MayRespawn()
|
||||
|
||||
// Something went wrong, client is usually kicked or transfered to a new mob at this point
|
||||
return 0
|
||||
|
||||
//I honestly can't find a good place for this atm.
|
||||
//If the webint interaction gets more features, I'll move it. - Skull132
|
||||
/client/verb/view_linking_requests()
|
||||
set name = "View Linking Requests"
|
||||
set category = "OOC"
|
||||
|
||||
check_linking_requests()
|
||||
|
||||
/client/proc/check_linking_requests()
|
||||
if (!config.webint_url || !config.sql_enabled)
|
||||
return
|
||||
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
return
|
||||
|
||||
var/list/requests = list()
|
||||
var/list/query_details = list(":ckey" = ckey)
|
||||
|
||||
var/DBQuery/select_query = dbcon.NewQuery("SELECT id, forum_id, forum_username, datediff(Now(), created_at) as request_age FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey AND deleted_at IS NULL")
|
||||
select_query.Execute(query_details)
|
||||
|
||||
while (select_query.NextRow())
|
||||
requests.Add(list(list("id" = text2num(select_query.item[1]), "forum_id" = text2num(select_query.item[2]), "forum_username" = select_query.item[3], "request_age" = select_query.item[4])))
|
||||
|
||||
if (!requests.len)
|
||||
return
|
||||
|
||||
var/dat = "<center><b>You have active requests to check!</b></center>"
|
||||
var/i = 0
|
||||
for (var/list/request in requests)
|
||||
i++
|
||||
|
||||
var/linked_forum_name = null
|
||||
if (config.forumurl)
|
||||
var/route_attributes = list2params(list("mode" = "viewprofile", "u" = request["forum_id"]))
|
||||
linked_forum_name = "<a href='byond://?src=\ref[src];routeWebInt=forums/members;routeAttributes=[route_attributes]'>[request["forum_username"]]</a>"
|
||||
|
||||
dat += "<hr>"
|
||||
dat += "#[i] - Request to link your current key ([key]) to a forum account with the username of: <b>[linked_forum_name ? linked_forum_name : request["forum_username"]]</b>.<br>"
|
||||
dat += "The request is [request["request_age"]] days old.<br>"
|
||||
dat += "OPTIONS: <a href='byond://?src=\ref[src];linkingrequest=[request["id"]];linkingaction=accept'>Accept Request</a> | <a href='byond://?src=\ref[src];linkingrequest=[request["id"]];linkingaction=deny'>Deny Request</a>"
|
||||
|
||||
src << browse(dat, "window=LinkingRequests")
|
||||
return
|
||||
|
||||
/client/proc/process_webint_link(var/route, var/attributes)
|
||||
if (!route)
|
||||
return
|
||||
|
||||
var/linkURL = ""
|
||||
|
||||
switch (route)
|
||||
if ("forums/members")
|
||||
if (!webint_validate_attributes(list("mode", "u"), attributes_text = attributes))
|
||||
return
|
||||
|
||||
if (!config.forumurl)
|
||||
return
|
||||
|
||||
linkURL = "[config.forumurl]memberlist.php?"
|
||||
|
||||
linkURL += attributes
|
||||
|
||||
if ("interface/user/link")
|
||||
if (!config.webint_url)
|
||||
return
|
||||
|
||||
linkURL = "[config.webint_url]user/link"
|
||||
|
||||
if ("interface/login/sso_server")
|
||||
//This also validates the attributes as it runs
|
||||
var/new_attributes = webint_start_singlesignon(src, attributes)
|
||||
if (!new_attributes)
|
||||
return
|
||||
|
||||
if (!config.webint_url)
|
||||
return
|
||||
|
||||
linkURL = "[config.webint_url]login/sso_server?"
|
||||
linkURL += new_attributes
|
||||
|
||||
else
|
||||
log_debug("Unrecognized process_webint_link() call used. Route sent: '[route]'.")
|
||||
return
|
||||
|
||||
src << link(linkURL)
|
||||
return
|
||||
|
||||
@@ -43,7 +43,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
|
||||
<A href='?src=\ref[src];setauthor=1'>Filter by Author: [author]</A><BR>
|
||||
<A href='?src=\ref[src];search=1'>\[Start Search\]</A><BR>"}
|
||||
if(1)
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>"
|
||||
else if(!SQLquery)
|
||||
@@ -189,7 +189,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
|
||||
<A href='?src=\ref[src];switchscreen=0'>(Return to main menu)</A><BR>"}
|
||||
if(4)
|
||||
dat += "<h3>External Archive</h3>"
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font>"
|
||||
else
|
||||
@@ -332,7 +332,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
|
||||
if(scanner.cache.unique)
|
||||
alert("This book has been rejected from the database. Aborting!")
|
||||
else
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
alert("Connection to Archive has been severed. Aborting.")
|
||||
else
|
||||
@@ -355,7 +355,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
|
||||
|
||||
if(href_list["targetid"])
|
||||
var/sqlid = sanitizeSQL(href_list["targetid"])
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
alert("Connection to Archive has been severed. Aborting.")
|
||||
if(bibledelay)
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
output += "<p><a href='byond://?src=\ref[src];observe=1'>Observe</A></p>"
|
||||
|
||||
if(!IsGuestKey(src.key))
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
|
||||
if(dbcon.IsConnected())
|
||||
var/isadmin = 0
|
||||
@@ -181,7 +181,7 @@
|
||||
return
|
||||
|
||||
if(href_list["privacy_poll"])
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
var/voted = 0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
/mob/new_player/proc/handle_privacy_poll()
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected())
|
||||
return
|
||||
var/voted = 0
|
||||
@@ -47,7 +47,7 @@
|
||||
var/optiontext
|
||||
|
||||
/mob/new_player/proc/handle_player_polling()
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(dbcon.IsConnected())
|
||||
var/isadmin = 0
|
||||
if(src.client && src.client.holder)
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
/mob/new_player/proc/poll_player(var/pollid = -1)
|
||||
if(pollid == -1) return
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(dbcon.IsConnected())
|
||||
|
||||
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM ss13_poll_question WHERE id = [pollid]")
|
||||
@@ -342,7 +342,7 @@
|
||||
|
||||
if(!isnum(pollid) || !isnum(optionid))
|
||||
return
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(dbcon.IsConnected())
|
||||
|
||||
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM ss13_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
|
||||
@@ -412,7 +412,7 @@
|
||||
|
||||
if(!isnum(pollid) || !istext(replytext))
|
||||
return
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(dbcon.IsConnected())
|
||||
|
||||
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype FROM ss13_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
|
||||
@@ -470,7 +470,7 @@
|
||||
|
||||
if(!isnum(pollid) || !isnum(optionid))
|
||||
return
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(dbcon.IsConnected())
|
||||
|
||||
var/DBQuery/select_query = dbcon.NewQuery("SELECT starttime, endtime, question, polltype FROM ss13_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
|
||||
|
||||
@@ -297,7 +297,7 @@ var/obj/machinery/blackbox_recorder/blackbox
|
||||
if(!feedback) return
|
||||
|
||||
round_end_data_gathering() //round_end time logging and some other data processing
|
||||
establish_db_connection()
|
||||
establish_db_connection(dbcon)
|
||||
if(!dbcon.IsConnected()) return
|
||||
var/round_id
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Contains general purpose procs used with Aurora's web interface and related functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* /proc/validate_webint_attributes()
|
||||
* Used to validate parametres sent to procs that are meant to communicate with the web interface.
|
||||
* Most commonly in Topic() calls, so that href tomfoolery is negated.
|
||||
*
|
||||
* Arguments:
|
||||
* - var/list/required_attributes - A list of required attributes. This is what the other arguments will be tested against. Cannot be null.
|
||||
* - var/list/attributes_list - The attributes to be validated, passed in a list form. Can be null.
|
||||
* - var/attributes_text - The attributes to be validated, passed in a text form. (Formatted according to list2params() convention.)
|
||||
* This overrides attributes_list if both are present. Can be null.
|
||||
*
|
||||
* Returns:
|
||||
* 1 - if all required attributes are present, and no erronious ones exist.
|
||||
* 0 - if certain required attributes are missing, or there are extras.
|
||||
*/
|
||||
|
||||
/proc/webint_validate_attributes(var/list/required_attributes, var/list/attributes_list, var/attributes_text)
|
||||
if (!required_attributes || !istype(required_attributes) || !required_attributes.len)
|
||||
return 0
|
||||
|
||||
if (attributes_text)
|
||||
attributes_list = params2list(attributes_text)
|
||||
|
||||
if (!attributes_list || !attributes_list.len)
|
||||
return 0
|
||||
|
||||
for (var/attribute in attributes_list)
|
||||
if (!(attribute in required_attributes))
|
||||
return 0
|
||||
|
||||
if (attributes_list[attribute] && required_attributes[attribute])
|
||||
if (istype(required_attributes, /list))
|
||||
if (!(attributes_list[attribute] in required_attributes[attribute]))
|
||||
return 0
|
||||
|
||||
else
|
||||
if (attributes_list[attribute] != required_attributes[attribute])
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
/*
|
||||
* /proc/webint_start_singlesignon()
|
||||
* Used to insert a token into the web_sso database and to enable a user to navigate to a page on the website and be automatically logged in. Hashes the user's save file for a unique token. Additional security managed on the website's end.
|
||||
*
|
||||
* Arguments:
|
||||
* - var/user - Must be a mob or a client. The player object that's going to be using the request.
|
||||
* - var/list/attributes - The attributes to which we route the URL as we call user.process_webint_link().
|
||||
* Validated here with webint_validate_attributes().
|
||||
* Must contain the 'location' key.
|
||||
*
|
||||
* Returns:
|
||||
* 0 - if one of the checks is failed and the operation cancelled.
|
||||
* string - if everything works, it will return the attributes with the added token and ckey value.
|
||||
*/
|
||||
|
||||
/proc/webint_start_singlesignon(var/client/user, var/attributes)
|
||||
if (!istype(user))
|
||||
return 0
|
||||
|
||||
var/list/permitted_locations = list("user_dashboard", "contract_overview", "contract_details")
|
||||
|
||||
if (!webint_validate_attributes(list("location" = permitted_locations, "contract"), attributes_text = attributes))
|
||||
return 0
|
||||
|
||||
var/token = ""
|
||||
var/list/alphabet = alphabet_uppercase
|
||||
alphabet.Add(list("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"))
|
||||
alphabet.Add(list("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"))
|
||||
|
||||
for (var/i = 0, i <= 24, i++)
|
||||
token += alphabet[rand(1, alphabet.len)]
|
||||
|
||||
attributes += "&"
|
||||
attributes += list2params(list("ckey" = user.ckey, "token" = token))
|
||||
|
||||
establish_db_connection(dbcon)
|
||||
if (!dbcon.IsConnected())
|
||||
alert("An error occured while attempting to connect to the database!")
|
||||
return 0
|
||||
|
||||
var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO ss13_web_sso (ckey, token, ip, created_at) VALUES (:ckey, :token, :ip, NOW())")
|
||||
insert_query.Execute(list(":ckey" = user.ckey, ":token" = token, ":ip" = user.address))
|
||||
|
||||
if (insert_query.ErrorMsg())
|
||||
alert("An error occured while trying to upload the session data!")
|
||||
return 0
|
||||
|
||||
if (alert("This will take you to the webpage and log you in. Do you wish to proceed?",,"Yes","No") == "No")
|
||||
return 0
|
||||
|
||||
return attributes
|
||||
Reference in New Issue
Block a user