You are not logged in.

#1 15 Jan 2008 4:35 am

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

BF2Rank on PHP5

Here are some problems I ran into when setting up a version of MadHatter's script on a server running PHP5.

  • Every instance of 'PRIVATE' (note: only the variable itself) in globals.php needs to be changed to something else, as PHP5 does not accept it as a valid variable name (since it is a function?).

  • Don't know if this is because of PHP5, but I got index-out-of-bounds errors when I tried to calculate the progress in percent for players with the highest rank.
    I noticed that the script here works fine, but for some reason it did not on mine.

    The workaround is like this:

    //Workaround for index-out-of-bounds error
    $player_rank_text = $rank_text_table[$rank];
    if ($rank == 21) {
        $next_rank_text = "No more ranks! You're the best!";
    }
    else {
        $next_rank_text = $rank_text_table[$rank+1];
    }
           
    //Calculating progress in percent
    $progress = 0;
           
    if($global_score != 0) {
        if ($rank >= 20) {
            $progress = (($global_score / $rank_table[$rank]) * PERCENT);
                    }
    else {
        $progress = ((($global_score - $rank_table[$rank]) / ($rank_table[$rank + 1] - $rank_table[$rank])) * PERCENT);
    }
            }

    //This part remains unchanged       
    if($progress > 100 || $progress < 0) {
        $progress = 100;
    }


  • Hope this was helpful!

    Regards,
    Ove Andersen

    Last edited by azzlack (15 Jan 2008 4:41 am)


    Web Developer and Designer.
    Currently studying for Bachelor of Computer Science degree ...

    Offline

     

    #2 15 Jan 2008 10:44 am

    MadHatter
    Administrator
    From: Dallas TX
    Registered: Jun 2006
    Posts: 529
    Website

    Re: BF2Rank on PHP5

    Thanks for the heads up on the reserved PRIVATE define.  I'll have to change that in the original script (and see why PHP5 uses it internally).

    I think I have php5 at home, but don't know that I've ever tried to run the rank scripts on my local machine (I usually just dev off this machine).  I don't do much php5 development as you can probably tell big_smile (since this machine only has 4.x) Looks like they implemented bounds checking & throw an exception if the index is out of range in PHP5, V4 just returns null if you attempt to access an element who's index is out of range.  Thanks for the fix on that too.

    Offline

     

    #3 15 Jan 2008 1:44 pm

    Butcher
    Moderator
    From: Norway
    Registered: Jul 2006
    Posts: 308

    Re: BF2Rank on PHP5

    Well what do you know, its a guy from Norway! Fra Bergen til og med.


    http://bamboocommandos.com/butcher_img/butchersig7.jpg

    Offline

     

    #4 17 Jan 2008 12:17 am

    azzlack
    Senior Member
    From: Bergen, Norway
    Registered: Jan 2008
    Posts: 26
    Website

    Re: BF2Rank on PHP5

    Hvor er du fra Butcher?
    Trivelig å se at andre nordmenn også liker programmering og battlefield 2... smile


    Web Developer and Designer.
    Currently studying for Bachelor of Computer Science degree ...

    Offline

     

    #5 17 Jan 2008 8:47 am

    Butcher
    Moderator
    From: Norway
    Registered: Jul 2006
    Posts: 308

    Re: BF2Rank on PHP5

    Tromsø, Madhatter har hjulpet meg mye med PHP og lagde BF2 stat scriptet til BF2 som jeg bruker.


    http://bamboocommandos.com/butcher_img/butchersig7.jpg

    Offline

     

    #6 22 Jan 2008 2:28 am

    azzlack
    Senior Member
    From: Bergen, Norway
    Registered: Jan 2008
    Posts: 26
    Website

    Re: BF2Rank on PHP5

    Yep. I am happy I found this site. MadHatter seems to me like a very nice guy with quite a lot of knowledge about programming. I am using his code at http://bobforum.eyecatch.no also.

    BTW. What programming languages do you have experience in? (Butcher and MadHatter)

    (Keeping the language in english since this forum is english.)


    Web Developer and Designer.
    Currently studying for Bachelor of Computer Science degree ...

    Offline

     

    #7 22 Jan 2008 8:32 am

    MadHatter
    Administrator
    From: Dallas TX
    Registered: Jun 2006
    Posts: 529
    Website

    Re: BF2Rank on PHP5

    the language I know the best is C#.  I've worked with PHP now for a number of years, and it's probably the language I know second best.  I own and run a game development company, and we develop in both C++ and C#, but my C++ is pretty sad.  I can program in it, but it takes me longer to use it than .net or php.  I can read VB and C++ much better than I can write it.  I've also used Java quite a bit, I can code faster in it than I can C++ but I don't use it much (and what you don't use you loose).  I've also used MySql and Sql Server quite a bit in the past and am familiar w/ their flavors of SQL.

    Offline

     

    #8 22 Jan 2008 11:33 pm

    azzlack
    Senior Member
    From: Bergen, Norway
    Registered: Jan 2008
    Posts: 26
    Website

    Re: BF2Rank on PHP5

    Cool!
    I am learning Java here at my school at the moment. Just started though - we are currently learning about algorithm effectiveness and arrays...


    Web Developer and Designer.
    Currently studying for Bachelor of Computer Science degree ...

    Offline

     

    #9 23 Jan 2008 1:15 pm

    MadHatter
    Administrator
    From: Dallas TX
    Registered: Jun 2006
    Posts: 529
    Website

    Re: BF2Rank on PHP5

    I was just having a conversation with our intern the other day about how universities are now teaching computer science courses with java.  On the one hand it makes sense, since most likely students will be using Java over assembler / C  / smalltalk in the work force.  On the other hand, you can't really get a good grasp of some of the data structures (like implementing a true linked list) are really impossible to do correctly in java or any other managed language.

    Offline

     

    #10 15 Apr 2008 11:09 am

    dgrillo
    New Member
    Registered: Apr 2008
    Posts: 4
    Website

    Re: BF2Rank on PHP5

    I am trying to get the Bf2rank to work on my site... i read this post and replaced PRIVATE with something else. It fixed the error i was getting for line 49. But now I am getting a new error

    http://www.sourceofevil.com/bf2rank/?pid=45647367 <---- click to see error.

    We are running Php 5 so i am sure that is the problem. I want to run this on my server cause i want to use a larger rank image.

    I will be using this on our main portal page. Beside each player I have a 16x16 rank icon, when you click on it.. I am using lightbox to display a larger image. By using the bf2rank script i would be able to not only show the rank icon but the progress and score to go along with it..

    Any ideas on how I can fix this?

    if you wanna see a sample of what i am working on, go to..$m[1]www.sourceofevil.com and click on the rank icon beside my name "=SoE= dgrillo"

    Last edited by dgrillo (15 Apr 2008 11:11 am)


    http://www.bf2player.com/sig/846623.png

    Offline

     

    #11 15 Apr 2008 2:35 pm

    MadHatter
    Administrator
    From: Dallas TX
    Registered: Jun 2006
    Posts: 529
    Website

    Re: BF2Rank on PHP5

    ok, there are several problems.

    first, remove the copyright (yes you have permission.  the copyright character is a 2 byte character and cant be saved in ascii format).  second, you have to change the file encoding; for some reason, PHP5 doesn't like UTF-8 encoding (http://bugs.php.net/bug.php?id=22108).  so open the file in notepad, file->save as->(index.php, All Files, ANSI)

    that will fix your first error that is being displayed now.  after you do this, it will break when we actually send the header.

    adding

    ob_start();

    to the beginning of the script, and

    ob_end_flush();

    in theory should stop the error message from happening, but its not.  I'll have to look into where / why this is happening with the script.  I have a hunch that there are still some characters that are killing the script.

    I'll keep playing with it.




    UPDATE:

    Found it!

    search & replace flush();  with //flush(); (comment out the flush calls.  there are 4 of them I think)

    Offline

     

    #12 15 Apr 2008 2:50 pm

    dgrillo
    New Member
    Registered: Apr 2008
    Posts: 4
    Website

    Re: BF2Rank on PHP5

    MadHatter :

    ok, there are several problems.

    first, remove the copyright (yes you have permission.  the copyright character is a 2 byte character and cant be saved in ascii format).  second, you have to change the file encoding; for some reason, PHP5 doesn't like UTF-8 encoding (http://bugs.php.net/bug.php?id=22108).  so open the file in notepad, file->save as->(index.php, All Files, ANSI)

    that will fix your first error that is being displayed now.  after you do this, it will break when we actually send the header.

    adding

    ob_start();

    to the beginning of the script, and

    ob_end_flush();

    in theory should stop the error message from happening, but its not.  I'll have to look into where / why this is happening with the script.  I have a hunch that there are still some characters that are killing the script.

    I'll keep playing with it.

    it actually seems to be working now.. http://www.sourceofevil.com/bf2rank/?pid=45647367

    Now I need to move the text down

    Last edited by dgrillo (15 Apr 2008 2:52 pm)


    http://www.bf2player.com/sig/846623.png

    Offline

     

    #13 15 Apr 2008 3:16 pm

    MadHatter
    Administrator
    From: Dallas TX
    Registered: Jun 2006
    Posts: 529
    Website

    Re: BF2Rank on PHP5

    I updated the download too.

    looks like you're still messing w/ it.  yea the progress bar looks a little off wink

    I actually have a newer version of the script somewhere that is about 75% less code, and the drawing bits are easier too.  If I dig it up tonight I'll post it.

    I have one for bf2142 too.  Don't think I ever published the code for that though.

    if you're interested I'll bundle it up too.

    looks like this:

    http://sanity-free.org/bf2142/81246737/avatar2.pnghttp://sanity-free.org/bf2142/99365280/avatar2.png

    or this:

    http://sanity-free.org/bf2142/81246737/avatar.pnghttp://sanity-free.org/bf2142/99365280/avatar.png

    Last edited by MadHatter (15 Apr 2008 4:03 pm)

    Offline

     

    #14 15 Apr 2008 3:51 pm

    dgrillo
    New Member
    Registered: Apr 2008
    Posts: 4
    Website

    Re: BF2Rank on PHP5

    yeah i would be very interested.

    Thank you for everything.


    http://www.bf2player.com/sig/846623.png

    Offline

     

    #15 15 Apr 2008 10:24 pm

    MadHatter
    Administrator
    From: Dallas TX
    Registered: Jun 2006
    Posts: 529
    Website

    Re: BF2Rank on PHP5

    k, here's the 2142 script:  http://sanity-free.org/binary/2142avatar.zip

    Code:

    http://yoursite.com/2142rank/index.php?pid=81246737
    http://yoursite.com/2142rank/index2.php?pid=81246737

    is how you reference the two images. 

    index.php displays this image: http://nullfx.com/2142avatar/index.php?pid=81246737

    index2.php displays this image: http://nullfx.com/2142avatar/index2.php?pid=81246737

    you can add mod_rewrite rules to your .htaccess file in order to refer to them like an image.  if you need help w/ that let me know.

    I'll see if I can't dig up the other bf2rank script thats less bloated codewise.

    WARNING: gamespy 2142 stats servers will ban your server's IP address if you try to pull players (pid's) that don't exist.  The class I wrote should help mitigate that issue (happens as a result of the pid in the auth token being invalid), but you can never be too careful.  play with it carefully! while we were trying to figure out the auth token I got my work's IP address banned, which means that I couldn't get in game stats if I tried to play 2142 @ work.  stats still got updated if I played there, but I couldn't access them in game or on my dev pc.

    Offline

     

    #16 16 Apr 2008 6:00 am

    dgrillo
    New Member
    Registered: Apr 2008
    Posts: 4
    Website

    Re: BF2Rank on PHP5

    Works perfect.. I got one working for now, just need to find the time to do it with all of the members.


    http://www.bf2player.com/sig/846623.png

    Offline

     



    © 2003 - 2024 NullFX
    Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License