diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 838670221ad..99f7fa69746 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -109,136 +109,42 @@ if("shop") if(href_list["KarmaBuy"]) var/karma=verify_karma() + if(isnull(karma)) //Doesn't display anything if karma database is down. + return switch(href_list["KarmaBuy"]) if("1") - if(karma <5) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Barber?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Barber",5) - return + karma_purchase(karma,5,"job","Barber") if("2") - if(karma <5) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Brig Physician?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Brig Physician",5) - return + karma_purchase(karma,5,"job","Brig Physician") if("3") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Nanotrasen Representative?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Nanotrasen Representative",30) - return + karma_purchase(karma,30,"job","Nanotrasen Representative") if("5") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Blueshield?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Blueshield",30) - return + karma_purchase(karma,30,"job","Blueshield") if("6") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Mechanic?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Mechanic",30) - return + karma_purchase(karma,30,"job","Mechanic") if("7") - if(karma <45) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Magistrate?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Magistrate",45) - return + karma_purchase(karma,45,"job","Magistrate") if("9") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Security Pod Pilot?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Security Pod Pilot",30) - return + karma_purchase(karma,30,"job","Security Pod Pilot") if(href_list["KarmaBuy2"]) var/karma=verify_karma() + if(isnull(karma)) //Doesn't display anything if karma database is down. + return switch(href_list["KarmaBuy2"]) if("1") - if(karma <15) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Machine People?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Machine",15) - return + karma_purchase(karma,15,"species","Machine People","Machine") if("2") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Kidan?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Kidan",30) - return + karma_purchase(karma,30,"species","Kidan") if("3") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Grey?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Grey",30) - return + karma_purchase(karma,30,"species","Grey") if("4") - if(karma <45) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Vox?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Vox",45) - return + karma_purchase(karma,45,"species","Vox") if("5") - if(karma <45) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Slime People?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Slime People",45) - return + karma_purchase(karma,45,"species","Slime People") if("6") - if(karma <100) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Plasmaman?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Plasmaman",100) - return + karma_purchase(karma,100,"species","Plasmaman") if("7") - if(karma <30) - to_chat(usr, "You do not have enough karma!") - return - else - if(alert("Are you sure you want to unlock Drask?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Drask",30) - return + karma_purchase(karma,30,"species","Drask") if(href_list["KarmaRefund"]) var/type = href_list["KarmaRefundType"] var/job = href_list["KarmaRefund"] diff --git a/code/modules/karma/karma.dm b/code/modules/karma/karma.dm index 1f18edfae22..cfc44382d64 100644 --- a/code/modules/karma/karma.dm +++ b/code/modules/karma/karma.dm @@ -1,3 +1,7 @@ +/* KARMA + Everything karma related is here. + Part of karma purchase is handled in client_procs.dm */ + proc/sql_report_karma(var/mob/spender, var/mob/receiver) var/sqlspendername = sanitizeSQL(spender.name) var/sqlspenderkey = spender.ckey @@ -39,49 +43,49 @@ proc/sql_report_karma(var/mob/spender, var/mob/receiver) var/err = query.ErrorMsg() log_game("SQL ERROR during karmatotal logging (adding new key). Error : \[[err]\]\n") else - karma += 1 + karma++ query = dbcon.NewQuery("UPDATE [format_table_name("karmatotals")] SET karma=[karma] WHERE id=[id]") if(!query.Execute()) var/err = query.ErrorMsg() log_game("SQL ERROR during karmatotal logging (updating existing entry). Error : \[[err]\]\n") - var/list/karma_spenders = list() -// Returns 1 if mob can give karma at all; if not, tells them why +// Returns TRUE if mob can give karma at all; if not, tells them why /mob/proc/can_give_karma() if(!client) - return 0 + to_chat(src, "You can't award karma without being connected.") + return FALSE if(config.disable_karma) to_chat(src, "Karma is disabled.") - return 0 + return FALSE if(!ticker || !player_list.len || (ticker.current_state == GAME_STATE_PREGAME)) to_chat(src, "You can't award karma until the game has started.") - return 0 + return FALSE if(client.karma_spent || (ckey in karma_spenders)) to_chat(src, "You've already spent your karma for the round.") - return 0 - return 1 + return FALSE + return TRUE -// Returns 1 if mob can give karma to M; if not, tells them why +// Returns TRUE if mob can give karma to M; if not, tells them why /mob/proc/can_give_karma_to_mob(mob/M) if(!can_give_karma()) - return 0 + return FALSE if(!istype(M)) to_chat(src, "That's not a mob.") - return 0 + return FALSE if(!M.client) to_chat(src, "That mob has no client connected at the moment.") - return 0 - if(ckey == M.ckey) + return FALSE + if(M.ckey == ckey) to_chat(src, "You can't spend karma on yourself!") - return 0 + return FALSE if(client.address == M.client.address) message_admins("Illegal karma spending attempt detected from [key] to [M.key]. Using the same IP!") log_game("Illegal karma spending attempt detected from [key] to [M.key]. Using the same IP!") to_chat(src, "You can't spend karma on someone connected from the same IP.") - return 0 - return 1 + return FALSE + return TRUE /mob/verb/spend_karma_list() @@ -129,9 +133,9 @@ var/list/karma_spenders = list() if(!can_give_karma_to_mob(M)) return // Check again, just in case things changed while the alert box was up - M.client.karma += 1 + M.client.karma++ to_chat(usr, "Good karma spent on [M.name].") - client.karma_spent = 1 + client.karma_spent = TRUE karma_spenders += ckey var/special_role = "None" @@ -153,14 +157,14 @@ var/list/karma_spenders = list() if(config.disable_karma) to_chat(src, "Karma is disabled.") - return 0 + return - var/currentkarma=verify_karma() - to_chat(usr, {"
You have [currentkarma] available."}) - return + var/currentkarma = verify_karma() + if(!isnull(currentkarma)) + to_chat(usr, {"
You have [currentkarma] available."}) /client/proc/verify_karma() - var/currentkarma=0 + var/currentkarma = 0 if(!dbcon.IsConnected()) to_chat(usr, "Unable to connect to karma database. Please try again later.
") return @@ -174,24 +178,18 @@ var/list/karma_spenders = list() totalkarma = query.item[1] karmaspent = query.item[2] currentkarma = (text2num(totalkarma) - text2num(karmaspent)) -/* if(totalkarma) - to_chat(usr, {"
You have [currentkarma] available.
) -You've gained [totalkarma] total karma in your time here.
"} - else - to_chat(usr, "Your total karma is: 0
")*/ + return currentkarma /client/verb/karmashop() set name = "karmashop" set desc = "Spend your hard-earned karma here" - set hidden = 1 + set hidden = TRUE if(config.disable_karma) to_chat(src, "Karma is disabled.") - return 0 - + return karmashopmenu() - return /client/proc/karmashopmenu() var/dat = "
" @@ -267,7 +265,23 @@ You've gained [totalkarma] total karma in your time here.
"} var/datum/browser/popup = new(usr, "karmashop", "
Karma Shop
", 400, 400) popup.set_content(dat) popup.open(0) - return + +//Checks if can afford, what you're purchasing, then purchases. (used in client_procs.dm) +/client/proc/karma_purchase(var/karma = 0, var/price = 1, var/category, var/name, var/DBname = null) + if(karma < price) + to_chat(usr, "You do not have enough karma!") + return + if(alert("Are you sure you want to unlock [name]?", "Confirmation", "No", "Yes") != "Yes") + return + if(karma < price) //Check one more time. (definitely not repeated code) + to_chat(usr, "You do not have enough karma!") + return + if(!isnull(DBname)) //In case database uses another name for logging. (Machine, Machine People) + name = DBname + if(category == "job") + DB_job_unlock(name,price) + else if(category == "species") + DB_species_unlock(name,price) /client/proc/DB_job_unlock(var/job,var/cost) var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.ckey]'") @@ -281,9 +295,7 @@ You've gained [totalkarma] total karma in your time here.
"} if(!dbckey) query = dbcon.NewQuery("INSERT INTO [format_table_name("whitelist")] (ckey, job) VALUES ('[usr.ckey]','[job]')") if(!query.Execute()) - var/err = query.ErrorMsg() - log_game("SQL ERROR during whitelist logging (adding new key). Error: \[[err]\]\n") - message_admins("SQL ERROR during whitelist logging (adding new key). Error: \[[err]\]\n") + queryErrorLog(query.ErrorMsg(),"adding new key") return else to_chat(usr, "You have unlocked [job].") @@ -297,9 +309,7 @@ You've gained [totalkarma] total karma in your time here.
"} var/newjoblist = jointext(joblist,",") query = dbcon.NewQuery("UPDATE [format_table_name("whitelist")] SET job='[newjoblist]' WHERE ckey='[dbckey]'") if(!query.Execute()) - var/err = query.ErrorMsg() - log_game("SQL ERROR during whitelist logging (updating existing entry). Error : \[[err]\]\n") - message_admins("SQL ERROR during whitelist logging (updating existing entry). Error : \[[err]\]\n") + queryErrorLog(query.ErrorMsg(),"updating existing entry") return else to_chat(usr, "You have unlocked [job].") @@ -321,9 +331,7 @@ You've gained [totalkarma] total karma in your time here.
"} if(!dbckey) query = dbcon.NewQuery("INSERT INTO [format_table_name("whitelist")] (ckey, species) VALUES ('[usr.ckey]','[species]')") if(!query.Execute()) - var/err = query.ErrorMsg() - log_game("SQL ERROR during whitelist logging (adding new key). Error : \[[err]\]\n") - message_admins("SQL ERROR during whitelist logging (adding new key). Error : \[[err]\]\n") + queryErrorLog(query.ErrorMsg(),"adding new key") return else to_chat(usr, "You have unlocked [species].") @@ -337,9 +345,7 @@ You've gained [totalkarma] total karma in your time here.
"} var/newspecieslist = jointext(specieslist,",") query = dbcon.NewQuery("UPDATE [format_table_name("whitelist")] SET species='[newspecieslist]' WHERE ckey='[dbckey]'") if(!query.Execute()) - var/err = query.ErrorMsg() - log_game("SQL ERROR during whitelist logging (updating existing entry). Error: \[[err]\]\n") - message_admins("SQL ERROR during whitelist logging (updating existing entry). Error: \[[err]\]\n") + queryErrorLog(query.ErrorMsg(),"updating existing entry") return else to_chat(usr, "You have unlocked [species].") @@ -349,7 +355,7 @@ You've gained [totalkarma] total karma in your time here.
"} to_chat(usr, "You already have this species unlocked!") return -/client/proc/karmacharge(var/cost,var/refund = 0) +/client/proc/karmacharge(var/cost,var/refund = FALSE) var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("karmatotals")] WHERE byondkey='[usr.ckey]'") query.Execute() @@ -361,9 +367,7 @@ You've gained [totalkarma] total karma in your time here.
"} spent += cost query = dbcon.NewQuery("UPDATE [format_table_name("karmatotals")] SET karmaspent=[spent] WHERE byondkey='[usr.ckey]'") if(!query.Execute()) - var/err = query.ErrorMsg() - log_game("SQL ERROR during karmaspent updating (updating existing entry). Error: \[[err]\]\n") - message_admins("SQL ERROR during karmaspent updating (updating existing entry). Error: \[[err]\]\n") + queryErrorLog(query.ErrorMsg(),"updating existing entry") return else to_chat(usr, "You have been [refund ? "refunded" : "charged"] [cost] karma.") @@ -372,23 +376,8 @@ You've gained [totalkarma] total karma in your time here.
"} /client/proc/karmarefund(var/type,var/name,var/cost) switch(name) - if("Tajaran Ambassador") - cost = 30 - if("Unathi Ambassador") - cost = 30 - if("Skrell Ambassador") - cost = 30 - if("Diona Ambassador") - cost = 30 - if("Kidan Ambassador") - cost = 30 - if("Slime People Ambassador") - cost = 30 - if("Grey Ambassador") - cost = 30 - if("Vox Ambassador") - cost = 30 - if("Customs Officer") + if("Tajaran Ambassador","Unathi Ambassador","Skrell Ambassador","Diona Ambassador","Kidan Ambassador", + "Slime People Ambassador","Grey Ambassador","Vox Ambassador","Customs Officer") cost = 30 if("Nanotrasen Recruiter") cost = 10 @@ -422,9 +411,7 @@ You've gained [totalkarma] total karma in your time here.
"} var/newtypelist = jointext(typelist,",") query = dbcon.NewQuery("UPDATE [format_table_name("whitelist")] SET [type]='[newtypelist]' WHERE ckey='[dbckey]'") if(!query.Execute()) - var/err = query.ErrorMsg() - log_game("SQL ERROR during whitelist logging (updating existing entry). Error: \[[err]\]\n") - message_admins("SQL ERROR during whitelist logging (updating existing entry). Error: \[[err]\]\n") + queryErrorLog(query.ErrorMsg(),"updating existing entry") return else to_chat(usr, "You have been refunded [cost] karma for [type] [name].") @@ -436,6 +423,10 @@ You've gained [totalkarma] total karma in your time here.
"} else to_chat(usr, "Your ckey ([dbckey]) was not found.") +/client/proc/queryErrorLog(err = null, errType) + log_game("SQL ERROR during whitelist logging ([errType]]). Error : \[[err]\]\n") + message_admins("SQL ERROR during whitelist logging ([errType]]). Error : \[[err]\]\n") + /client/proc/checkpurchased(var/name = null) // If the first parameter is null, return a full list of purchases var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.ckey]'") query.Execute() @@ -454,10 +445,10 @@ You've gained [totalkarma] total karma in your time here.
"} var/list/combinedlist = joblist + specieslist if(name) if(name in combinedlist) - return 1 + return TRUE else - return 0 + return FALSE else return combinedlist else - return 0 + return FALSE \ No newline at end of file