home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2966
Discussions: 188,378, Posts: 2,243,454, Members: 232,606
Old November 5th, 2002, 10:32 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Nov 2002
Posts: 3
Script Help PhP

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
------------------------------------------------------------------------------

PHP Code:
//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');"); 
*/ 

Legacy is offline   Reply With Quote
Old November 6th, 2002, 11:57 AM     #2 (permalink)
Member
 
gothic's Avatar
 
Join Date: Oct 2001
Location: Palatine, IL
Posts: 375
Is there more code to the 'create_forfeit' function that is not being displayed?

gothic is offline   Reply With Quote
Old November 6th, 2002, 10:57 PM     #3 (permalink)
Junior Member
 
Join Date: Nov 2002
Posts: 3
The Complete

challengeforfeit.php file posted below

other files belonging to the challenge-respond-finalize part of the sscript are

challenge.php
challengerespond.php
challengefinalize.php
If anyone needs to see these files let me know


PHP Code:
<?

function challenge_forfeit($challid){
global 
$dir$file$url$out$plyr;

if(!
$challid){
include(
"$dir[func]/error.php");
display_error("Invalid Challenge ID.<br>");
}

$challengeinfo=mysql_query("SELECT * FROM challenges WHERE challid='$challid'");
$chall=mysql_fetch_array($challengeinfo);

if(!
$chall[challenger]){
include(
"$dir[func]/error.php");
display_error("Unknown Challenge ID.<br>");
}

if(
$chall[finalizedby] > 0){
include(
"$dir[func]/error.php");
display_error("This match has already been finalized.<br>");
}


$teamembers=mysql_query("SELECT teamid FROM teammembers WHERE teamid='$chall[challenger]' AND playerid='$plyr[id]' AND status <= '3' OR teamid='$chall[challenged]' AND playerid='$plyr[id]' AND status <= '3'");
$tmem=mysql_fetch_array($teamembers);

if(
$tmem[teamid]=="$chall[challenger]"){
//CHALLENGER FORFEIT
$winnerid="$chall[challenged]";
$winrank="$chall[challengedrank]";
$loserid="$chall[challenger]";
$loserank="$chall[challengerrank]";
$ladderid="$chall[ladderid]";
}
else if(
$tmem[teamid]=="$chall[challenged]"){
//CHALLENGED FORFEIT
$winnerid="$chall[challenger]";
$winrank="$chall[challengerrank]";
$loserid="$chall[challenged]";
$loserank="$chall[challengedrank]";
$ladderid="$chall[ladderid]";
}
else{
include(
"$dir[func]/error.php");
display_error("You cannot forfeit challenges for this team.<br>");
}

create_forfeit($challid,$ladderid,$winnerid,$loserid,$winrank,$loserank);

$out[body]=$out[body]."
<table width='100%' border='1' bordercolor='#000000' cellspacing='1' cellpadding='1'>
<tr class='altcolor'>
<td width='100%' valign='top' align='center'>
<strong>Forfeited</strong><br>
</td>
</tr>
<tr>
<td width='100%' valign='center' align='left'>
<br><ul>
The challenge was forfeited.</ul></td>
</tr>
<tr class='altcolor'>
<td width='100%' valign='top' align='center'>
&nbsp;</td>
</tr>
</table>"
;

include(
"$dir[curtheme]");
}














//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');");
*/


//GET WINNERS LADDER STATS
$winnerladder=mysql_query("SELECT * FROM ladder_$ladderid WHERE id='$winnerid'");
$wlinfo=mysql_fetch_array($winnerladder);

//GET LOSERS LADDER STATS
$loserladder=mysql_query("SELECT * FROM ladder_$ladderid WHERE id='$loserid'");
$llinfo=mysql_fetch_array($loserladder);


include(
"$dir[func]/rankadjust.php");

if((
$loserank) && ($winrank)){
 if((
$loserank $winrank) && ($loserank $wlinfo[rank])){ 
 
update_teamranks($ladderid,$winnerid,$loserank);
 }
}


$tommorrow=date("Y-m-d H:i:s",time()+60*60*24*1);


//UPDATE WINNERS LADDER STATS

if($winrank $loserank){
$newlastrank="$wlinfo[rank]";

 if((
$winrank $wlinfo[bestrank]) || ($wlinfo[bestrank] < 1)){
 
$newbestrank="$loserank";
 }else{
 
$newbestrank="$wlinfo[bestrank]";
 }

}else{
$newlastrank="$wlinfo[lastrank]";
$newbestrank="$wlinfo[bestrank]";
}

$newwins=($wlinfo[wins] + 1);
$newgames=($newwins $wlinfo[losses]);
$newpercent=round($newwins $newgames 100);
$newstreak=($wlinfo[streak] + 1);

if(
$newstreak=="0"){
$newstreak="1";
}

if(
$newstreak $wlinfo[beststreak]){
$newbeststreak="$newstreak";
}else{
$newbeststreak="$wlinfo[beststreak]";
}


mysql_query("UPDATE ladder_$ladderid SET 
lastmatch='$tday', 
lastplayed='$loserid', 
status='20', 
statusdate='$tommorrow', 
statusdisplay='Win by forfeit', 
lastrank='$newlastrank', 
bestrank='$newbestrank', 
wins='$newwins', 
games='$newgames', 
percent='$newpercent', 
streak='$newstreak', 
beststreak='$newbeststreak' 
WHERE id='$winnerid'"
);



//UPDATE LOSERS LADDER STATS

if($llinfo[rank] < $llinfo[bestrank]){
$newbestrank="$llinfo[rank]";
}else{
$newbestrank="$llinfo[bestrank]";
}

if(
$llinfo[rank] > $llinfo[worstrank]){
$newworstrank="$llinfo[rank]";
}else{
$newworstrank="$llinfo[worstrank]";
}

$newlosses=($llinfo[losses] + 1);
$newgames=($newlosses $llinfo[wins]);
$newpercent=round($llinfo[wins] / $newgames 100);
$newstreak=($llinfo[streak] - 1);

if(
$newstreak=="0"){
$newstreak="-1";
}

if(
$newstreak $llinfo[worststreak]){
$newworststreak="$newstreak";
}else{
$newworststreak="$llinfo[worststreak]";
}


mysql_query("UPDATE ladder_$ladderid SET 
lastmatch='$tday', 
status='6', 
statusdate='$tommorrow', 
statusdisplay='Loss by forfeit', 
lastplayed='$winnerid', 
bestrank='$newbestrank', 
worstrank='$newworstrank', 
losses='$newlosses', 
games='$newgames', 
percent='$newpercent', 
streak='$newstreak', 
worststreak='$newworststreak' 
WHERE id='$loserid'"
);

mysql_query("DELETE FROM challenges WHERE challid='$challid'");

//CHECK FOR DUPLICATE RANKS AND ADJUST RANKS
rank_checkadjust($ladderid);

}



?>

Legacy is offline   Reply With Quote
Old November 8th, 2002, 11:47 PM     #4 (permalink)
Member
 
gothic's Avatar
 
Join Date: Oct 2001
Location: Palatine, IL
Posts: 375
Okay, I have a headache now.. =]

It's hard to only look at such little code without any runtime debugging and not seeing where some functions are called from... But here's my assessment... I could be wrong:

The function 'challenge_forfeit' appears to do the correct things. It *think* it checks if the match was finalized, and if it was, it swaps the winner from the challenger to the challenged.

On the other hand, it appears function 'check_unrespondedchallenges' just assumes the Challenger is the winner.
This may be the correct behavior, depending on how it's called, but I can't be sure without having the entire program to run.
That function may need to swap the winner/loser around like the 'challenge_forfeit' function, but I can't say for sure.

If you feel so inclined, and don't mind - email me the origional tarfile of this program, and I'll try to debug it further for you. Unless of course, someone else can see what I'm missing.. =]
gothic is offline   Reply With Quote
Old November 9th, 2002, 01:10 AM     #5 (permalink)
Ultimate Member
 
ChoaticWhisper's Avatar
 
Join Date: Oct 2001
Location: Alabama
Posts: 1,309
Send a message via AIM to ChoaticWhisper
I seen on another forum legacy posted the same question, It seems he got some help.
Heres what a person posted
PHP Code:
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); 

ChoaticWhisper is offline   Reply With Quote
Old November 9th, 2002, 12:58 PM     #6 (permalink)
Junior Member
 
Join Date: Nov 2002
Posts: 3
Yes..I did get some help and thank EVERYONE that helped out.

There are ALOT more bugs in this crappy $400.00 rip-off script that I am trying to get fixed.

Thanks again to all that helped me out
Legacy is offline   Reply With Quote
Old November 9th, 2002, 09:53 PM     #7 (permalink)
Member
 
gothic's Avatar
 
Join Date: Oct 2001
Location: Palatine, IL
Posts: 375
You mean someone stole my thunder? dern.. *shakes his fist* ..

=]
gothic is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2883)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Help with an Ati Radeon HD 4850.. (23)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Building first computer, will t.. (2)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:22 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28