Page 1 of 1

Script Help plz

Posted: Tue Nov 05, 2002 8:17 pm
by Legacy
I have this ladder script that I purchased and the Creator will not support or help me with a major bug in it.

What is happening is a team CHALLENGES another team to a battle on the Ladder. Then the Other Team RESPONDS to the challenge. Now if the ORIGINAL Team who made the challenge DOES NOT Finalize the match withing 48 hrs then the script executes a FORFEIT..but the problem is the script is creating the FORFEIT to the team that was challenged even tho they responded to the original challenge..it should give the fofeit to the Orginal Team because they didnt FINALIZE the match. I have found the section of code in the script that creates the forfeits..any help would be appreciated.

The Script is Running here:
http://www.squadgames.com/ladder_network

here is a URL with screenshots of what is happening
http://www.squadgames.com/legacy/ladderscript2_bug.php

I think it needs more code added to work properly..but i dont know about this stuff

I really could use some help with this..It Gives a forfeit to the wrong team and after paying $400.00 for this script the creator wont help me and the script is Useless.
also if you need more files e-mail me at admin@squadgames.com I'll provide anything you might need
------------------------------------------------------------------------------

Code: Select all

//NEXT 2 FUNCTIONS DELETES AND AWARDS WINS FOR UNRESPONDED OR UNFINALIZED CHALLENGES 


function check_unrespondedchallenges(){ 

$challengeladders=mysql_query("SELECT id,respondhours,finalizehours FROM ladders WHERE challenge='1'"); 
while(list($id,$respondhours,$finalizehours)=mysql_fetch_row($challengeladders)){ 

$laterespond=date("Y-m-d H:i:s",time()-60*60*$respondhours); 
$latefinalize=date("Y-m-d H:i:s",time()-60*60*$finalizehours); 

$challengeinfo=mysql_query("SELECT challid,challenger,challenged,ladderid,challengerrank,challengedrank,respondedby,finalizedby FROM challenges WHERE 
ladderid='$id' AND respondedby='0' AND finalizedby='0' AND challengedtime < '$laterespond' OR 
ladderid='$id' AND respondedby > '0' AND finalizedby='0' AND respondedtime < '$latefinalize'"); 
 while(list($challid,$challenger,$challenged,$ladderid,$challengerrank,$challengedrank,$respondedby,$finalizedby)=mysql_fetch_row($challengeinfo)){ 

//DIDNT RESPOND IN TIME or DIDNT FINALIZE IN TIME 
if(($respondedby=="0") && ($finalizedby=="0") || ($respondedby > 0) && ($finalizedby=="0")){ 
create_forfeit($challid,$id,$challenger,$challenged,$challengerrank,$challengedrank); 
} 

} 

} 

} 



function create_forfeit($challid,$ladderid,$winnerid,$loserid,$winrank,$loserank){ 
global $dir, $file, $url, $out, $plyr; 

$loserteaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$loserid'"); 
$lteam=mysql_fetch_array($loserteaminfo); 

$winnerteaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$winnerid'"); 
$wteam=mysql_fetch_array($winnerteaminfo); 

$ladderinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$ladderid'"); 
$linfo=mysql_fetch_array($ladderinfo); 

$ip=getenv("REMOTE_ADDR"); 
$tday=date("Y-m-d H:i:s"); 

if(!$wteamїteamname]){ 
$wteamїteamname]="їDELETED]"; 
} 

if(!$lteamїteamname]){ 
$lteamїteamname]="їDELETED]"; 
} 

/* 
//REPORT MATCH TO MATCH DATABASE 
mysql_query("INSERT INTO matchdb VALUES ( 
'$challid', 
'$winnerid', 
'$loserid', 
'$wteamїteamname]', 
'$lteamїteamname]', 
'$ladderid', 
'$linfoїladdername]', 
'$winrank', 
'$loserank', 
'0', 
'0', 
'', 
'', 
'', 
'', 
'Win by forfeit.', 
'Loss by forfeit.', 
'0', 
'0', 
'$plryїid]', 
'$tday', 
'0.0.0.0', 
'$plryїid]', 
'$tday', 
'$ip');"); 
*/

Posted: Tue Nov 05, 2002 11:56 pm
by qads
it is a little hard to fix this script cos i/we have no idea what's in the database and what cloumn goes to what team....

1 thing i would like to know is why won't the scripter fix it?..that's just idiotic, you paid alot of money for this script....sue him :twisted:

Posted: Wed Nov 06, 2002 7:52 pm
by Legacy
I have asked them for a fix 5 weeks ago..I send e-mails to try to find out whats going on with fix..i dont get any clear answers...now they wont reply anylonger until they have a fix...which tells me there probably wont be a fix for it

Posted: Thu Nov 07, 2002 8:01 pm
by volka
I'm not sure, but

Code: Select all

if(($respondedby=="0") && ($finalizedby=="0") || ($respondedby > 0) && ($finalizedby=="0"))
	create_forfeit($challid,$id,$challenger,$challenged,$challengerrank,$challengedrank);
doesn't care about wether the record was in the result set because of not responding or not finalizing the challenge.

Code: Select all

function create_forfeit($challid,$ladderid,$winnerid,$loserid,$winrank,$loserank)
parameter 3: winnerid, 4: loserid, 5: winrank, 6: loserank.
Maybe (and that's really only a guess)

Code: Select all

//DIDNT RESPOND IN TIME or DIDNT FINALIZE IN TIME
if($respondedby=='0' && $finalizedby=='0')
	// no response in time, challenged team lose
	create_forfeit($challid,$id,$challenger,$challenged,$challengerrank,$challengedrank); 
else if ($respondedby > 0 && $finalizedby=='0')
	// response but not finalized in time, challenger lose
	create_forfeit($challid,$id,$challenged,$challenger, $challengedrank, $challengerrank);
will fix it.....

happy fragging !?

Posted: Fri Nov 08, 2002 6:20 pm
by Legacy
Yes...That is working but coded this way:

Code: Select all

if(($respondedby=="0") && ($finalizedby=="0")){ 
  create_forfeit($challid,$id,$challenger,$challenged,$challengerrank,$challengedrank); 
} else if (($respondedby > 0) && ($finalizedby=="0")) {
  create_forfeit($challid,$id,$challenged,$challenger,$challengedrank,$challengerrank); 
}
....BUT...it wont automatically proceed with the forfeits....if you click on the link to finalize it after the 48hr period it will insert the forfeits correctly..
but it wont automatically do the forfeits after the 48 hrs has passed...


did I explain that somewwhat correctly to you?



But I do appreciate the fix you added

Posted: Fri Nov 08, 2002 7:33 pm
by volka
But it did update the forfeits automatically before?
If not check where check_unrespondedchallenges() is called. On every page request or only if an action takes place on a challenge.


Just a minor change (ok, shouldn't play too much with the existing script, but I like it simple ;) )
  • SELECT challid,challenger,challenged,ladderid,challengerrank,challengedrank,respondedby,finalizedby
    FROM challenges WHERE
    ladderid='$id' AND respondedby='0' AND finalizedby='0' AND challengedtime < '$laterespond' OR
    ladderid='$id' AND respondedby>'0' AND finalizedby='0' AND respondedtime < '$latefinalize'
is unnecessary complex. red code is a duplicate. Can respondedby be negative? If not it's useless in the WHERE-clause (ok, not really useless, but the same thing is tested in the php-script later on ;) ).

Code: Select all

SELECT challid,challenger,challenged,ladderid,challengerrank,challengedrank,respondedby,finalizedby
FROM challenges WHERE 
ladderid='$id' AND finalizedby='0' AND (challengedtime < '$laterespond' OR respondedtime  < '$latefinalize')

Yesterday I read this in the mysql-documentation(http://www.mysql.com/doc/en/MySQL_indexes.html)
Comments:
Michael Schröpl: One case when mySQL 3.23 does not use an index is if it has to implicitly convert types. Imagine you have a column of a VARCHAR type but query this in the form "SELECT * FROM tablename WHERE columnname = 123"; mySQL implicitly converts 123 to "123" but then does a full table scan.
Probably the same if having a numerical field and and use it in a WHERE-clause as string like '0'.
If the table-fields are numerical you may remove the quotes in the select string....