TheMasterGeneral Posted June 21, 2015 Posted June 21, 2015 Hey guys, I've asked around for a fix on the battletent. (It simply won't input the completed challenge into the table! Probably a logic bomb in the code somewhere) The NPC code is: if ($r['user_level'] == 0) { $q = $db->query( "SELECT `cb_money` FROM `challengebots` WHERE `cb_npcid` = {$r['userid']}"); if ($db->num_rows($q) > 0) { $cb = $db->fetch_row($q); $qk = $db->query( "SELECT COUNT(`npcid`) FROM `challengesbeaten` WHERE `userid` = $userid AND `npcid` = {$r['userid']}"); if ($db->fetch_single($qk) > 0) { $m = $cb['cb_money']; $db->query( "UPDATE `users` SET `money` = `money` + $m WHERE `userid` = $userid"); echo "<br /> You gained " . money_formatter($m) . " for beating the challenge bot {$r['username']}"; $db->query( "INSERT INTO `challengesbeaten` VALUES($userid, {$r['userid']})"); } $db->free_result($qk); } $db->free_result($q); } (Its the stock MCCV2 attack beat/lost/take pages.) The queries executed: SELECT * FROM `users` WHERE `userid` = 9 UPDATE `users` SET `exp` = `exp` + 0, `money` = `money` + 3127 WHERE `userid` = 1 UPDATE `users` SET `hp` = 1, `money` = `money` - 3127, `hospital` = 31, `hospreason` = 'Mugged by CID Admin' WHERE `userid` = 9 INSERT INTO `events` VALUES(NULL, 9, 1434921252, 0, 'CID Admin mugged you and stole 3,127 Copper Coins.') UPDATE `users` SET `new_events` = `new_events` + 1 WHERE `userid` = 9 INSERT INTO `attacklogs` VALUES(NULL, 1, 9, 'won', 1434921252, 3127, '1. Using her Soul Stealer CID Admin hit Trainee Guard doing 6728 damage (-6178) \n') UPDATE `users` SET `kills` = `kills` + 1 WHERE userid=1 UPDATE `users` SET `hp` = `maxhp`, `hospital` = 0 WHERE `userid` = 9 SELECT `gangRESPECT`, `gangID` FROM `gangs` WHERE `gangID` = 5 SELECT COUNT(`warDECLARER`) FROM `gangwars` WHERE (`warDECLARER` = 1 AND `warDECLARED` = 5) OR (`warDECLARED` = 1 AND `warDECLARER` = 5) SELECT `cb_money` FROM `challengebots` WHERE `cb_npcid` = 9 SELECT COUNT(`npcid`) FROM `challengesbeaten` WHERE `userid` = 1 AND `npcid` = 9 I know the userid 9 IS an NPC, so this baffles me. Anyone care to share something about it? =/ Quote
NonStopCoding Posted June 21, 2015 Posted June 21, 2015 (edited) mess up lol Edited June 21, 2015 by NonStopCoding Quote
NonStopCoding Posted June 21, 2015 Posted June 21, 2015 Hey guys, I've asked around for a fix on the battletent. (It simply won't input the completed challenge into the table! Probably a logic bomb in the code somewhere) The NPC code is: if ($r['user_level'] == 0) { $q = $db->query( "SELECT `cb_money` FROM `challengebots` WHERE `cb_npcid` = {$r['userid']}"); if ($db->num_rows($q) > 0) { $cb = $db->fetch_row($q); $qk = $db->query( "SELECT COUNT(`npcid`) FROM `challengesbeaten` WHERE `userid` = $userid AND `npcid` = {$r['userid']}"); if ($db->fetch_single($qk) > 0) { $m = $cb['cb_money']; $db->query( "UPDATE `users` SET `money` = `money` + $m WHERE `userid` = $userid"); echo "<br /> You gained " . money_formatter($m) . " for beating the challenge bot {$r['username']}"; $db->query( "INSERT INTO `challengesbeaten` VALUES($userid, {$r['userid']})"); } $db->free_result($qk); } $db->free_result($q); } (Its the stock MCCV2 attack beat/lost/take pages.) The queries executed: SELECT * FROM `users` WHERE `userid` = 9 UPDATE `users` SET `exp` = `exp` + 0, `money` = `money` + 3127 WHERE `userid` = 1 UPDATE `users` SET `hp` = 1, `money` = `money` - 3127, `hospital` = 31, `hospreason` = 'Mugged by CID Admin' WHERE `userid` = 9 INSERT INTO `events` VALUES(NULL, 9, 1434921252, 0, 'CID Admin mugged you and stole 3,127 Copper Coins.') UPDATE `users` SET `new_events` = `new_events` + 1 WHERE `userid` = 9 INSERT INTO `attacklogs` VALUES(NULL, 1, 9, 'won', 1434921252, 3127, '1. Using her Soul Stealer CID Admin hit Trainee Guard doing 6728 damage (-6178) \n') UPDATE `users` SET `kills` = `kills` + 1 WHERE userid=1 UPDATE `users` SET `hp` = `maxhp`, `hospital` = 0 WHERE `userid` = 9 SELECT `gangRESPECT`, `gangID` FROM `gangs` WHERE `gangID` = 5 SELECT COUNT(`warDECLARER`) FROM `gangwars` WHERE (`warDECLARER` = 1 AND `warDECLARED` = 5) OR (`warDECLARED` = 1 AND `warDECLARER` = 5) SELECT `cb_money` FROM `challengebots` WHERE `cb_npcid` = 9 SELECT COUNT(`npcid`) FROM `challengesbeaten` WHERE `userid` = 1 AND `npcid` = 9 I know the userid 9 IS an NPC, so this baffles me. Anyone care to share something about it? =/ $db->query("INSERT INTO `challengesbeaten` VALUES($userid, {$r['userid']})"); if the challengebeaten has a auto increment this will not work you could do something like $db->query("INSERT INTO `challengesbeaten` VALUES(NULL,$userid, {$r['userid']})"); or $db->query("INSERT INTO `challengesbeaten` (`whateveruseridis`,`whatevernpcidis`) VALUES($userid, {$r['userid']})"); Quote
KyleMassacre Posted June 21, 2015 Posted June 21, 2015 (edited) Probably because $db->fetch_single($qk) > 0. Let's break it down shall we? $qk = select count(npcid) from challenges beaten where userid = 1 and npcid = 9 $qk should return an integer. Now I assume you haven't beaten this bot before so it should return 0. So we have established in this that $qk = 0, now, if(0 > 0) { //execute this block } See, your logic has failed because 0 is not greater than 0. It is equal to 0. Now what I would suggest is to say if($qk == 0) or if(0 >= $qk) You got to remember that the alligator mouth wants to eat the bigger source of food $db->query("INSERT INTO `challengesbeaten` VALUES($userid, {$r['userid']})"); if the challengebeaten has a auto increment this will not work you could do something like $db->query("INSERT INTO `challengesbeaten` VALUES(NULL,$userid, {$r['userid']})"); or $db->query("INSERT INTO `challengesbeaten` (`whateveruseridis`,`whatevernpcidis`) VALUES($userid, {$r['userid']})"); Then he would receive an error for a column miscount but his queries are not even being reached because of his logic Edited June 21, 2015 by KyleMassacre More data Quote
NonStopCoding Posted June 21, 2015 Posted June 21, 2015 Probably because $db->fetch_single($qk) > 0. Let's break it down shall we? $qk = select count(npcid) from challenges beaten where userid = 1 and npcid = 9 $qk should return an integer. Now I assume you haven't beaten this bot before so it should return 0. So we have established in this that $qk = 0, now, if(0 > 0) { //execute this block } See, your logic has failed because 0 is not greater than 0. It is equal to 0. Now what I would suggest is to say if($qk == 0) or if(0 >= $qk) You got to remember that the alligator mouth wants to eat the bigger source of food Then he would receive an error for a column miscount but his queries are not even being reached because of his logic yea i see what ya mean lol i did not read full code hehe Quote
TheMasterGeneral Posted June 21, 2015 Author Posted June 21, 2015 Oh lordy, Kyle's fix worked wonderfully. Thanks to each both of you! :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.