Jump to content
xisto Community
Sign in to follow this  
sonesay

Integrity Checks Failing During Multiple Ajax Request somehow the checks fail due to lag.

Recommended Posts

Heres my merit system at its current stage. http://forums.xisto.com/no_longer_exists/
note: select a character from the drop down list to see output.

I've been working on this locally on my mac and because of little or no delay I did not see the problem until I decided to upload to the WWW. The problem lies in the adding of merits to each category. Although there are integrity checks on the PHP side before executing the update to mysql database it somehow fails because of the lag.
i.e multiple 'add' buttons can be pressed before the section gets reloaded. so if your modifying the 'Combat Skill' category and its 19/20 you should only be able to add one more merit. But because of page reloading delay you are able to hit more buttons before it finishes reloading.

my function to modify merits.

	
if ($mm_mode == "remove") {
// check if merit is equal or above 1 before lowering by 1
// get users merits
$q1 = "SELECT ".$mm_merit." FROM ".$mm_table." WHERE c_id = ".$mm_c_id;
$r1 = mysql_query($q1, $link);
while ($m = mysql_fetch_array($r1)) {
$mm_new_level = $m[$mm_merit];
}
if($mm_new_level > 0) {
$mm_new_level--;
// update hp level
$q2 = "UPDATE ".$mm_table." SET ".$mm_merit." = ".$mm_new_level . " WHERE c_id = " . $mm_c_id;
mysql_query($q2, $link);
}
}
if ($mm_mode == "add") {
$q1 = "SELECT ".$mm_merit." FROM ".$mm_table." WHERE c_id = ".$mm_c_id;
$r1 = mysql_query($q1, $link);
while ($m = mysql_fetch_array($r1)) {
$mm_new_level = $m[$mm_merit];
}
// check if under max combo and item limit before adding.
if($mm_new_level < $mm_item_limit && $mm_new_level < $mm_combo_limit) {
$mm_new_level++;
// update hp level
$q2 = "UPDATE ".$mm_table." SET ".$mm_merit." = ".$mm_new_level . " WHERE c_id = " . $mm_c_id;
mysql_query($q2, $link);
}
}
} linenums:0'>function modify_merit($mm_c_id, $mm_mode, $mm_merit, $mm_combo_limit, $mm_item_limit, $mm_table) { include('../db.php'); if ($mm_mode == "remove") { // check if merit is equal or above 1 before lowering by 1 // get users merits $q1 = "SELECT ".$mm_merit." FROM ".$mm_table." WHERE c_id = ".$mm_c_id; $r1 = mysql_query($q1, $link); while ($m = mysql_fetch_array($r1)) { $mm_new_level = $m[$mm_merit]; } if($mm_new_level > 0) { $mm_new_level--; // update hp level $q2 = "UPDATE ".$mm_table." SET ".$mm_merit." = ".$mm_new_level . " WHERE c_id = " . $mm_c_id; mysql_query($q2, $link); } } if ($mm_mode == "add") { $q1 = "SELECT ".$mm_merit." FROM ".$mm_table." WHERE c_id = ".$mm_c_id; $r1 = mysql_query($q1, $link); while ($m = mysql_fetch_array($r1)) { $mm_new_level = $m[$mm_merit]; } // check if under max combo and item limit before adding. if($mm_new_level < $mm_item_limit && $mm_new_level < $mm_combo_limit) { $mm_new_level++; // update hp level $q2 = "UPDATE ".$mm_table." SET ".$mm_merit." = ".$mm_new_level . " WHERE c_id = " . $mm_c_id; mysql_query($q2, $link); } }}
each button pressed is added like this
	} linenums:0'>if($merit == "sword_level") {		modify_merit($c_id, $mode, $merit, 20, 8, 'combat_skill');	}

I know I cant blame lag being the cause of my problem its my code. There are two options at this stage I can think of

1. Redo all the sections and reload all Div's in the same category all at once so there is no way to press more then 2 buttons. e.g if HP merit is incresed the whole HPMP div reloads at once so there is no chance to hit the add MP button causing 8 max combo constraint to fail.

2. Use java script to disable all add buttons in the category being modified until its fully reloaded(not sure this will work).

What do you think would be the best way to fix this?
Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.