Karma Cleanup

This commit is contained in:
Tails2091
2018-09-08 14:25:42 -04:00
parent 8bff93c963
commit f63db004f8
2 changed files with 99 additions and 182 deletions
+32 -114
View File
@@ -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"]
+67 -68
View File
@@ -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, "<span class='warning'>You can't award karma without being connected.</span>")
return FALSE
if(config.disable_karma)
to_chat(src, "<span class='warning'>Karma is disabled.</span>")
return 0
return FALSE
if(!ticker || !player_list.len || (ticker.current_state == GAME_STATE_PREGAME))
to_chat(src, "<span class='warning'>You can't award karma until the game has started.</span>")
return 0
return FALSE
if(client.karma_spent || (ckey in karma_spenders))
to_chat(src, "<span class='warning'>You've already spent your karma for the round.</span>")
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, "<span class='warning'>That's not a mob.</span>")
return 0
return FALSE
if(!M.client)
to_chat(src, "<span class='warning'>That mob has no client connected at the moment.</span>")
return 0
if(ckey == M.ckey)
return FALSE
if(M.ckey == ckey)
to_chat(src, "<span class='warning'>You can't spend karma on yourself!</span>")
return 0
return FALSE
if(client.address == M.client.address)
message_admins("<span class='warning'>Illegal karma spending attempt detected from [key] to [M.key]. Using the same IP!</span>")
log_game("Illegal karma spending attempt detected from [key] to [M.key]. Using the same IP!")
to_chat(src, "<span class='warning'>You can't spend karma on someone connected from the same IP.</span>")
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, "<span class='warning'>Karma is disabled.</span>")
return 0
return FALSE
var/currentkarma=verify_karma()
to_chat(usr, {"<br>You have <b>[currentkarma]</b> available."})
var/currentkarma = verify_karma()
if(!isnull(currentkarma))
to_chat(usr, {"<br>You have <b>[currentkarma]</b> available."})
return
/client/proc/verify_karma()
var/currentkarma=0
var/currentkarma = 0
if(!dbcon.IsConnected())
to_chat(usr, "<span class='warning'>Unable to connect to karma database. Please try again later.<br></span>")
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, {"<br>You have <b>[currentkarma]</b> available.<br>)
You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
else
to_chat(usr, "<b>Your total karma is:</b> 0<br>")*/
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, "<span class='warning'>Karma is disabled.</span>")
return 0
return FALSE
karmashopmenu()
return
@@ -269,6 +270,23 @@ You've gained <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
/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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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 <b>[totalkarma]</b> total karma in your time here.<br>"}
else
to_chat(usr, "<span class='warning'>Your ckey ([dbckey]) was not found.</span>")
/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 <b>[totalkarma]</b> total karma in your time here.<br>"}
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