From efc48c58d5a853e703b96f846a4fb762b43430e7 Mon Sep 17 00:00:00 2001 From: Kyep Date: Wed, 3 Aug 2016 03:43:32 -0700 Subject: [PATCH] Krausus Updates - Eliminates recursion in exptimer(), uses spawn() and sleep() instead - Reduces frequency of updates from once every minute, to once per 5 minutes - Makes each update sleep briefly in between each DB query so it cannot hammer the server even if >100 players are connected --- code/game/gamemodes/gameticker.dm | 7 +- code/game/jobs/job_exp.dm | 120 +++++++++++++++--------------- 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/code/game/gamemodes/gameticker.dm b/code/game/gamemodes/gameticker.dm index 0c4ded6e12d..254ea0cf321 100644 --- a/code/game/gamemodes/gameticker.dm +++ b/code/game/gamemodes/gameticker.dm @@ -68,9 +68,10 @@ var/round_start_time = 0 votetimer() /datum/controller/gameticker/proc/exptimer() - spawn(600) - update_exp(1,0) - exptimer() + spawn(0) + while(TRUE) + update_exp(5,0) + sleep(3000) /datum/controller/gameticker/proc/setup() //Create and announce mode diff --git a/code/game/jobs/job_exp.dm b/code/game/jobs/job_exp.dm index f6443ab157c..f789fcdb695 100644 --- a/code/game/jobs/job_exp.dm +++ b/code/game/jobs/job_exp.dm @@ -140,65 +140,67 @@ /proc/update_exp(var/minutes, var/announce_changes = 0) if(!establish_db_connection()) return -1 - for(var/client/C in clients) - if(C.inactivity < (10 MINUTES)) + spawn(0) + for(var/client/C in clients) + if(C.inactivity < (10 MINUTES)) - var/DBQuery/exp_read = dbcon.NewQuery("SELECT exp FROM [format_table_name("player")] WHERE ckey='[C.ckey]'") - exp_read.Execute() - var/list/play_records = list() - while(exp_read.NextRow()) - play_records = params2list(exp_read.item[1]) + var/DBQuery/exp_read = dbcon.NewQuery("SELECT exp FROM [format_table_name("player")] WHERE ckey='[C.ckey]'") + exp_read.Execute() + var/list/play_records = list() + while(exp_read.NextRow()) + play_records = params2list(exp_read.item[1]) - for(var/rtype in list("gen","com","sec","sci","eng","med","sup","sil","ant", "gho", "imm")) - if(!text2num(play_records[rtype])) - play_records[rtype] = 0 + for(var/rtype in list("gen","com","sec","sci","eng","med","sup","sil","ant", "gho", "imm")) + if(!text2num(play_records[rtype])) + play_records[rtype] = 0 + else + play_records[rtype] = text2num(play_records[rtype]) + + if(C.mob.stat == CONSCIOUS && C.mob.mind.assigned_role) + play_records["gen"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] General EXP!") + if(C.mob.mind.assigned_role in command_positions) + play_records["com"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Command EXP!") + if(C.mob.mind.assigned_role in security_positions) + play_records["sec"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Security EXP!") + if(C.mob.mind.assigned_role in science_positions) + play_records["sci"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Science EXP!") + if(C.mob.mind.assigned_role in engineering_positions) + play_records["eng"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Engineering EXP!") + if(C.mob.mind.assigned_role in medical_positions) + play_records["med"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Medical EXP!") + if(C.mob.mind.assigned_role in support_positions) + play_records["sup"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Support EXP!") + if(C.mob.mind.assigned_role in nonhuman_positions) + play_records["sil"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Silicon EXP!") + if(C.mob.mind.special_role) + play_records["ant"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Special EXP!") + else if(isobserver(C.mob)) + play_records["gho"] += minutes + if(announce_changes) + to_chat(C.mob,"You got: [minutes] Ghost EXP!") else - play_records[rtype] = text2num(play_records[rtype]) - - if(C.mob.stat == CONSCIOUS && C.mob.mind.assigned_role) - play_records["gen"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] General EXP!") - if(C.mob.mind.assigned_role in command_positions) - play_records["com"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Command EXP!") - if(C.mob.mind.assigned_role in security_positions) - play_records["sec"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Security EXP!") - if(C.mob.mind.assigned_role in science_positions) - play_records["sci"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Science EXP!") - if(C.mob.mind.assigned_role in engineering_positions) - play_records["eng"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Engineering EXP!") - if(C.mob.mind.assigned_role in medical_positions) - play_records["med"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Medical EXP!") - if(C.mob.mind.assigned_role in support_positions) - play_records["sup"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Support EXP!") - if(C.mob.mind.assigned_role in nonhuman_positions) - play_records["sil"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Silicon EXP!") - if(C.mob.mind.special_role) - play_records["ant"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Special EXP!") - else if(isobserver(C.mob)) - play_records["gho"] += minutes - if(announce_changes) - to_chat(C.mob,"You got: [minutes] Ghost EXP!") - else - return - var/new_exp = list2params(play_records) - C.prefs.exp = new_exp - new_exp = sanitizeSQL(new_exp) - var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("player")] SET exp = '[new_exp]' WHERE ckey='[C.ckey]'") - update_query.Execute() \ No newline at end of file + return + var/new_exp = list2params(play_records) + C.prefs.exp = new_exp + new_exp = sanitizeSQL(new_exp) + var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("player")] SET exp = '[new_exp]' WHERE ckey='[C.ckey]'") + update_query.Execute() + sleep(10) \ No newline at end of file