It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

high score list

Moderator: Phate

high score list

Postby dakota on Tue Mar 27, 2007 10:10 pm

hello,

How do you make a high scrore list for a flash game? Is it more secure to view the high score list in a swf file or in html? thanks
dakota
 
Posts: 10
Joined: Tue Feb 20, 2007 6:16 am

Postby flabbyrabbit on Wed Mar 28, 2007 10:25 am

Ive made highscore lists which are displayed in either html or swf, but both are relatively easy to hack (as my friend demonstrated). It passes the values to a php file which then adds the value to a SQL. I believe it is more secure to display them in flash because there is no addresses to give them a hint to where they are stored. I will dig the code out for you if you want?

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby dakota on Wed Mar 28, 2007 10:44 am

that would be cool eh, as long as its easy coz ive tried other ones and failed. cheers
dakota
 
Posts: 10
Joined: Tue Feb 20, 2007 6:16 am

Postby flabbyrabbit on Wed Mar 28, 2007 10:57 am

Yeah i had that problem so i mixed to gether loads of tutorials. Do you have a SQL host?? If not i have another version that just runs on php, but you can only have a certain number of records.

Flabby Rabbit
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby dakota on Thu Mar 29, 2007 5:35 am

yeah ive got that mssql manager
dakota
 
Posts: 10
Joined: Tue Feb 20, 2007 6:16 am

Postby flabbyrabbit on Thu Mar 29, 2007 4:29 pm

I will first show you the pure php one as the SQL takes longer to set up.

I cant remember where i got this code from or i would thank them, sorry :(.

You will first need a php file called scores.php, with the code:
Code: Select all
<?php

   $winscore - (int)$winscore

   // Create a Blank File if it doesn't already exist
   if (!file_exists($filename))
   {
      $file=fopen($filename, "w");
      fclose ($file);
   }

   // Read the file in
   $oscores = file ($filename);
   $numreadin = count($oscores);

   // Break out the data into a new 2-d array called $tscores
   for ($i = 0; $i < $numreadin; $i++)
   {
      $g = unserialize($oscores[$i]);
      $tscores[$i][0] = $g[0];
      $tscores[$i][1] = $g[1];
   }

   // Fill in any missing data with none/0
   for ($i = $numreadin; $i < $scoresize; $i++)
   {
      $tscores[$i][0] = 0;
      $tscores[$i][1] = "AAA";
   }

   // Process the actions   

   // Insert a score/name
   if ($action == "INSERT")
   {

      // Add name to end of list, and sort
      $tscores[$scoresize + 1][0] = $winscore;
      $tscores[$scoresize + 1][1] = $winname;
      rsort ($tscores);

      $file=fopen($filename, "w");

      // Write them out
      for ($i = 0; $i < $scoresize; $i++)
      {
         $st = serialize($tscores[$i]) . "\n";
         fputs($file, $st);
      }

      fclose($file);
   }

   // Clear the list   
   if ($action == "CLEAR")
   {

      $k[0] = 0;
      $k[1] = "none";
      $ser = serialize($k);

      $file=fopen($filename, "w");

      for ($i = 0; $i < $scoresize; $i++)
      {
         $st = $ser . "\n";
         fputs($file, $st);
      }

      fclose($file);
   }

   // Process the OUTPUT options
   if ($viewtype == "HTML")
   {
     // HTML PAGE CREATED HERE
     ?>


      <table cellpadding=2 cellspacing=2 border=0 width="152">
      <tr align=center>
      <th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">#</font></th>
      <th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Name</font></th>
      <th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Score</font></th>
      </tr>

        <?
   
      for ($i = 0; $i < $scoresize; $i++)
      {
         echo ("<tr bgcolor='#666666' align='center'><td><font size='2' face='Arial, Helvetica, sans-serif'>");
         echo ($i + 1);
         echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
         echo ($tscores[$i][1]);
         echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
         echo ($tscores[$i][0]);
         echo ("</font></td></tr>");
      }

       ?>
      </table>
     <?

   }

   // FLASH DATA CREATED HERE
   if ($viewtype == "FLASH")
   {
      for ($i = 0; $i < $scoresize; $i++)
      {
         echo ("NAME" . $i . "=");
         echo ($tscores[$i][1]);
         echo ("&SCORE" . $i . "=");
         echo ($tscores[$i][0]);
         echo ("&");
      }
   }

?>


this will then need to be uploaded to your server along with a file called scores.sco, which is just a .txt with the extension changed to .sco:
Code: Select all
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}




Flash time:
When the user submits a score they will click a button, with the code:
Code: Select all
on (release) {
   _root.scoretable.filename = "scores.sco";
   _root.scoretable.scoresize = 10;
   _root.scoretable.action = "INSERT";
   _root.scoretable.viewtype = "FLASH";
   _root.scoretable.winname = _root.name;
   _root.scoretable.winscore = _root.score;
   _root.scoretable.loadVariables("scores.php", "GET");
                gotoAndStop("scores", 1);
}


Change the GotoAndStop to where your highscores will be, then where you want the highscores to be viewed you have to create a movieClip with the variable name 'scoretable'. This movieClip must include 20 variable text boxes name 'NAME0' upto 'NAME9' and 'SCORE0' upto 'SCORE9'. This is abit time consuming, sorry. The last thing in flash is to put some code on that frame:
Code: Select all
stop();
_root.scoretable._visible = "true";


This should now work as long as everything is uploaded to the same directory on your server. Hope this works, dont hesitate to ask any questions if you dont understand somthingl. I check posts most days so should be fairly quick response.

Flabby Rabbit
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby dakota on Fri Mar 30, 2007 7:01 am

doesnt seem to be working yet. should there be some information in scores.sco if its to work?
dakota
 
Posts: 10
Joined: Tue Feb 20, 2007 6:16 am

Postby flabbyrabbit on Fri Mar 30, 2007 11:10 am

.sco should have:

a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}

which is the default scores.
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby flabbyrabbit on Fri Mar 30, 2007 7:47 pm

Also are you sure that the your scores and names are in the variables '_root.name' and '_root.score'? The second thing to try is to run the code and then check the .sco and see if nything has changed, if it has but isnt displaying in flash then there is somthing wrong with thte scoretable movie clip. If it hasnt changed then there is somthing wrong in the code. Check that then get back to me.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby dakota on Fri Mar 30, 2007 9:07 pm

my variables are defintely _root.name and _root.score

i opened the score.sco and it was
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
a:2:{i:0;i:0;i:1;s:3:"AAA";}
dakota
 
Posts: 10
Joined: Tue Feb 20, 2007 6:16 am

Next

Who is online

Users browsing this forum: No registered users and 1 guest