high score table for slot machine game

They have: 6 posts

Joined: Aug 2000

Hi,
I wonder if anyone can help me with this tricky prob...

I maintain the website: http://www.slot-machine.co.uk

The site features online slot machine games that I programmed in the Java language. I was using a third party class to record high scores in the Geocities guestbook.

Unfortunately Geocities changed the cgi of their Guestbook, and the class to record the high scores in the games no longer works.

I am looking for a *really* simple Perl cgi script that I can install and a Java class with a simple Constructor accepting arguments such as 'GameName', 'Name', 'Score'.

The Java Class should then pass these arguments to the cgi script and then record the results in a file according to the arguement GameName.

Then on a weekly basis I can download the files from the server containing the scores and update the scores on-line.

At least that's how I used to do it before Smiling

Any help would be gratefully recieved.

Cheers
Matt

They have: 56 posts

Joined: Jun 2000

Someone reply to this before it vanishes into thin air! Please, thank you.

EDIT:(P.S. I was not trying to be rude, it's just that I sent matt here for help from another BB! Wink ) Thanks.

[Edited by Nutrocker on 08-15-2000 at 11:08 AM]

Don

Nutties bit o the web!
I can type much quicker if I put my Pint down first.
Nutzboard

They have: 193 posts

Joined: Feb 2000

Hello Matt, welcome to the Webmaster Forums.

Please specify the name of the variables you want recorded, and I will write the code for you. Smiling

Richard
richjb::381

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 6 posts

Joined: Aug 2000

richjb and nutrocker - thanks for the replies!

richjb - the variables i want recorded are name, wisecrack and score.

The Java Class should pass these variables to a cgi script. A friend of mine has already written a cgi script that does the job perfectly, but I don't know how to write the Java applet to pass the variables to the script.

I have attached a copy of the working cgi script if this helps, but to be honest i don't know if it would be easier for you to write the java applet class and re-write the cgi script too Smiling

Anyway, thank you once again for your help Smiling I will credit you in full on the site if you supply me with the details you would like displayed.

Cheers
Matt

------------
Script follows:

#!/usr/bin/perl
#
# hiscore program. Manages multiple games and sorts the highscores into order
#
#

# First, get the CGI variables into a list of strings

%cgivars= &getcgivars ;

# Get the lines of the score file into an array

open (SCORES, "<$cgivars{GAME}.dat");
@scores = ;
close (SCORES);

# Arrays to hold names, wisecracks and scores

@name = ();
@wisecrack = ();
@score = ();

# Put the names, wisecracks and scores into arrays

$count = 0;

foreach $line (@scores)
{
chop ($line);
($name[$count], $wisecrack[$count], $score[$count]) = split /&/, $line;
$count++;
}

# If there is a new hiscore add it to the array.

if ($cgivars{SCORE} != "")
{
$name[$count] = $cgivars{NAME};
$wisecrack[$count] = $cgivars{WISECRACK};
$score[$count] = $cgivars{SCORE};
$count++;

# Sort hiscores
$i = $count-1;
while( ($score[$i] > $score[$i-1]) && ($i != 0) )
{
$tempscore = $score[$i];
$tempname = $name[$i];
$tempwisecrack = $wisecrack[$i];
$score[$i] = $score[$i-1];
$name[$i] = $name[$i-1];
$wisecrack[$i] = $wisecrack[$i-1];
$score[$i-1] = $tempscore;
$name[$i-1] = $tempname;
$wisecrack[$i-1] = $tempwisecrack;
$i--;
}

# Rewrite score file

open (SCORES, ">$cgivars{GAME}.dat");

for($i=0 ; $i < $count ; $i++)
{
print SCORES "$name[$i]&$wisecrack[$i]&$score[$i]\n";
}

close (SCORES);

}

# Print the response header

print "Content-type: text/html\n\n";

# Print the rest of the page

print <

Highscore Table for $cgivars{GAME}

Highscore Table for $cgivars{GAME}

Rank
Name
Wisecrack
Score

EOF

# Write Hiscores

for($i=0 ; $i < $count ; $i++)
{
$rank = $i+1;
print "\n";
print " $rank\n";
print " $name[$i]\n";
print " $wisecrack[$i]\n";
print " $score[$i]\n";
print "\n\n";
}

print "\n";
print "\n";
print "\n";

exit;

#----------------- start of &getcgivars() module ----------------------

# Read all CGI vars into an associative array.
# If multiple input fields have the same name, they are concatenated into
# one array element and delimited with the \0 character (which fails if
# the input has any \0 characters, very unlikely but conceivably possible).
# Currently only supports Content-Type of application/x-www-form-urlencoded.
sub getcgivars {
local($in, %in) ;
local($name, $value) ;

# First, read entire string of CGI vars into $in
if ( ($ENV{'REQUEST_METHOD'} eq 'GET') ||
($ENV{'REQUEST_METHOD'} eq 'HEAD') ) {
$in= $ENV{'QUERY_STRING'} ;

} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
if ($ENV{'CONTENT_TYPE'}=~ m#^application/x-www-form-urlencoded$#i) {
$ENV{'CONTENT_LENGTH'}
|| &HTMLdie("No Content-Length sent with the POST request.") ;
read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ;

} else {
&HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}") ;
}

} else {
&HTMLdie("Script was called with unsupported REQUEST_METHOD.") ;
}

# Resolve and unencode name/value pairs into %in
foreach (split('&', $in)) {
s/\+/ /g ;
($name, $value)= split('=', $_, 2) ;
$name=~ s/%(..)/chr(hex($1))/ge ;
$value=~ s/%(..)/chr(hex($1))/ge ;
$in{$name}.= "\0" if defined($in{$name}) ; # concatenate multiple vars
$in{$name}.= $value ;
}

return %in ;

}

# Die, outputting HTML error page
# If no $title, use a default title
sub HTMLdie {
local($msg,$title)= @_ ;
$title || ($title= "CGI Error") ;
print <

$title

$title
$msg

EOF

exit ;
}

[Edited by mfdale on 08-15-2000 at 03:40 PM]

They have: 193 posts

Joined: Feb 2000

Matt,

I have the slightest idea on how to programm Java. However, if the Java was already submitting to a script, and the script changed, I thought I could just recreate the script it used to submit to. But, does the Java program submit to a specific URL? Because if it does...then I'm not sure I can do anything.

Hopefully this works out. Smiling

Richard

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 6 posts

Joined: Aug 2000

The old cgi script was part of a geocities guestbook - I don't know how to get a copy of the old or new version of that script unfortunately.

The high score program was a java applet class written to interface with the cgi of the guestbook.

Here is the Java code that interfaced with the old cgi script:

Is there anyway that you or anybody else could alter the code so that it interfaces with the cgi script in my previous post?

Thanks
Matt

Code follows:
---------

import java.applet.Applet;
import java.io.*;
import java.net.*;
import java.util.*;

/**
* A simple class that implements a hiscore manager through the
* GuestBook CGI of GeoCities.
*
* @version 1.0 beta - 26 September 1997
* @author Leonardo Boselli
*[email protected]
*/
public class Hiscore {
String name;
Applet applet;
/**
* This Constructor needs the calling applet and a string that contains
* the name of the game (providing support for multiple games).
* @param applet the applet.
* @param name the name of the game.
*/
public Hiscore(Applet applet, String name) {
this.applet = applet;
this.name = name;
}
/**
* This method returns a Vector containing String Arrays.
* Every element in a String[3]: the first String is the player's name, the
* second the player's wisecrack and the last is the score.
* @return the hiscores.
*/
public Vector getHiscores() throws IOException {
Vector v = new Vector();
URL url = new URL(applet.getCodeBase(),"geobook.html");
URLConnection uc = url.openConnection();
DataInputStream d = new DataInputStream(uc.getInputStream());
String line = "";
while((line = d.readLine()) != null) {
if(line.endsWith("Comments:")) {
int idx = 0;
if(
((idx = (line = d.readLine()).indexOf(' ',idx)) != -1) &&
(line.substring(0,idx).equals("";
URL url = new URL(
"http://www.geocities.com/"+"cgi-bin/geoplus_apps/ans_entry"
);
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
PrintStream ps = new PrintStream(uc.getOutputStream());
ps.print(post);
ps.flush();
ps.close();
DataInputStream dis = new DataInputStream(uc.getInputStream());
while(dis.readLine() != null);
dis.close();
}
}

They have: 193 posts

Joined: Feb 2000

Ok, I see where it outputs to the CGI script...and I think I should be able to get that to work. But, what I don't get is that it seems to be reading from the questbook pages? I didn't get the impression it did that from your earilier post.

Anyways, I should be able to help you...I'll try to get something posted soon.

Richard
richjb::392

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 6 posts

Joined: Aug 2000

richjb

The java applet class (2nd listing) used to record scores in the Geocities guestbook. The Geocities guestbook cgi changed though, so I was no longer able to record scores in it by using the class.

Someone else has since written me a cgi script (1st listing) that works perfectly. However, I don't know how to alter the java applet to work with this new script.

Sorry If I wasn't clearer in the first place Smiling

Cheers
Matt

They have: 193 posts

Joined: Feb 2000

Ok, then if the script your friend wrote will take the fields as already named, which I think it will (but I'm not used to his writing style), then all you need to do is edit the below line in the Java class:

      URL url = new URL(
         "http://www.geocities.com/"+"cgi-bin/geoplus_apps/ans_entry"
      );
'

Change that code to redirect to the location of his script...which should then work, once again going on the fact that his variables are named accordingly. Smiling

Richard
richjb::398

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 6 posts

Joined: Aug 2000

I don't think that solution is going to work, because the java class was written specifically to interface with a guestbook file.

It has lines of code that watch out for spaces in the guestbook, then appends the information as one long string (I think)..

e.g.

code
--
if(line.endsWith("Comments:"))
--

I think the class needs changing so that it POSTs name, wisecrack and score to the cgi script.

Cheers
Matt

They have: 193 posts

Joined: Feb 2000

Then you would need to figure out what the following variables do, as I assume that this line specifies what is sent to the script:

post = "final="+account+"&state=1&style=1&comments=<!--+"+post+"+-->";
'

Richard
richjb::411

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 6 posts

Joined: Aug 2000

Sorry, too complicated for me Sad

I Give up! Thanks for you help anyway tho.

Matt

P.S. If anyone else can write a simple java applet that submits to the cgi script in my previous post, then please add to this thread. Thanks Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.