diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 838670221ad..86bfde3a3c5 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -109,135 +109,53 @@ if("shop") if(href_list["KarmaBuy"]) var/karma=verify_karma() - switch(href_list["KarmaBuy"]) - if("1") - if(karma <5) - to_chat(usr, "You do not have enough karma!") + if(!isnull(karma)) //Doesn't display anything if karma database is down. + switch(href_list["KarmaBuy"]) + if("1") + karma_purchase(karma,5,"job","Barber") return - else - if(alert("Are you sure you want to unlock Barber?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Barber",5) + if("2") + karma_purchase(karma,5,"job","Brig Physician") return - if("2") - if(karma <5) - to_chat(usr, "You do not have enough karma!") + if("3") + karma_purchase(karma,30,"job","Nanotrasen Representative") return - else - if(alert("Are you sure you want to unlock Brig Physician?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Brig Physician",5) + if("5") + karma_purchase(karma,30,"job","Blueshield") return - if("3") - if(karma <30) - to_chat(usr, "You do not have enough karma!") + if("6") + karma_purchase(karma,30,"job","Mechanic") return - else - if(alert("Are you sure you want to unlock Nanotrasen Representative?", "Confirmation", "No", "Yes") != "Yes") - return - DB_job_unlock("Nanotrasen Representative",30) + if("7") + karma_purchase(karma,45,"job","Magistrate") return - 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 - 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 - 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 - 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) + if("9") + karma_purchase(karma,30,"job","Security Pod Pilot") return if(href_list["KarmaBuy2"]) var/karma=verify_karma() - switch(href_list["KarmaBuy2"]) - if("1") - if(karma <15) - to_chat(usr, "You do not have enough karma!") + if(!isnull(karma)) //Doesn't display anything if karma database is down. + switch(href_list["KarmaBuy2"]) + if("1") + karma_purchase(karma,15,"species","Machine People","Machine") return - else - if(alert("Are you sure you want to unlock Machine People?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Machine",15) + if("2") + karma_purchase(karma,30,"species","Kidan") return - if("2") - if(karma <30) - to_chat(usr, "You do not have enough karma!") + if("3") + karma_purchase(karma,30,"species","Grey") return - else - if(alert("Are you sure you want to unlock Kidan?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Kidan",30) + if("4") + karma_purchase(karma,45,"species","Vox") return - if("3") - if(karma <30) - to_chat(usr, "You do not have enough karma!") + if("5") + karma_purchase(karma,45,"species","Slime People") return - else - if(alert("Are you sure you want to unlock Grey?", "Confirmation", "No", "Yes") != "Yes") - return - DB_species_unlock("Grey",30) + if("6") + karma_purchase(karma,100,"species","Plasmaman") return - 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 - 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 - 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 - 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) + if("7") + karma_purchase(karma,30,"species","Drask") return if(href_list["KarmaRefund"]) var/type = href_list["KarmaRefundType"] diff --git a/code/modules/karma/karma.dm b/code/modules/karma/karma.dm index 1f18edfae22..3879e11e1fc 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,15 @@ var/list/karma_spenders = list() if(config.disable_karma) to_chat(src, "Karma is disabled.") - return 0 + return FALSE - var/currentkarma=verify_karma() - to_chat(usr, {"
You have [currentkarma] available."}) + var/currentkarma = verify_karma() + if(!isnull(currentkarma)) + to_chat(usr, {"
You have [currentkarma] available."}) return /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,21 +179,17 @@ 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 FALSE karmashopmenu() return @@ -269,6 +270,23 @@ You've gained [totalkarma] total karma in your time here.
"} 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(!isnull(DBname)) //In case database uses another name for logging. (Machine, Machine People) + name = DBname + if(category == "job") + DB_job_unlock(name,price) + return + else if(category == "species") + DB_species_unlock(name,price) + return + return + /client/proc/DB_job_unlock(var/job,var/cost) var/DBQuery/query = dbcon.NewQuery("SELECT * FROM [format_table_name("whitelist")] WHERE ckey='[usr.ckey]'") query.Execute() @@ -281,9 +299,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") + queryErrorLogKey(query.ErrorMsg()) return else to_chat(usr, "You have unlocked [job].") @@ -297,9 +313,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") + queryErrorLogEntry(query.ErrorMsg()) return else to_chat(usr, "You have unlocked [job].") @@ -321,9 +335,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") + queryErrorLogKey(query.ErrorMsg()) return else to_chat(usr, "You have unlocked [species].") @@ -337,9 +349,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") + queryErrorLogEntry(query.ErrorMsg()) return else to_chat(usr, "You have unlocked [species].") @@ -349,7 +359,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 +371,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") + queryErrorLogEntry(query.ErrorMsg()) return else to_chat(usr, "You have been [refund ? "refunded" : "charged"] [cost] karma.") @@ -372,23 +380,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 +415,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") + queryErrorLogEntry(query.ErrorMsg()) return else to_chat(usr, "You have been refunded [cost] karma for [type] [name].") @@ -436,6 +427,14 @@ You've gained [totalkarma] total karma in your time here.
"} else to_chat(usr, "Your ckey ([dbckey]) was not found.") +/client/proc/queryErrorLogEntry(var/err = null) + 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") + +/client/proc/queryErrorLogKey(var/err = null) + 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") + /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 +453,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