This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-03-25 18:14:54

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

online high-score system

Hey guys,

I'm currently working on an online high score system using Panther, php and a MySQL table.

Panther sends off a page request that contains all the information like so:

(contents of file at URL:[(page link) [.php?username=](username)[&password=](password)[&score=](score))

so that the webpage can then read that out and use the $_GET command to pull the information from the URL and process it.

I have two problems that I need help with. Firstly, How can I compare the username to a table of registered users to see if they are registered and set the result to a variable? (I need to compare the password too)

Secondly, This seems a slightly unsafe way of doing it. There's nothing stopping someone from realising that the score is in the URL and sending off a very high score to the page. Can anyone think of a safer method of sending the information? Thanks!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-03-25 19:01:09

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

I don't know much about Squeak / Smalltalk and the libraries that are available, but is there one that can directly access a SQL database? Like in Java there is the JDBC where you can directly run SQL commands without the need of using PHP files. This seems a safer method as a person couldn't intervene. And for checking the username/password (if still using PHP) you could compare the what you need and then 'echo' out the results and just have Panther read the output stream (ie. echo '0' if they're both correct or '1' if one of them is not the same).

Offline

 

#3 2011-03-25 19:05:00

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

Your echo suggestion is what I am currently doing! Maybe there is some sort of SQL command hidden in smalltalk but I'm not sure, it's never struck me as especially designed to link to the internet.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#4 2011-03-25 19:08:55

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

Is smalltalk able to use external libraries? If it is there might be one that you could use.

Offline

 

#5 2011-03-25 20:21:15

Taneb
Scratcher
Registered: 2009-07-07
Posts: 100+

Re: online high-score system

PHP code:
<?php
$con = mysql_connect("dbhostname","username","password");
mysql_select_db("highscore",$con);
$loggedin=("SELECT PASSWORD FROM users_and_passwords WHERE username = '" . $_GET["username"] . "'" == $_GET["password"]);
if($loggedin){
//code to add highscore to database
echo("highscore added");
}
else
{
echo("incorrect username/password");
}
?>


Something like that should work. If you want security, I would use posts rather than gets, but Panther doesn't support them.

Offline

 

#6 2011-03-25 20:24:11

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

Alright I found a MySQL driver for Squeak, I'm going to test it on a local mysql server and I'll post back if it worked or not

Offline

 

#7 2011-03-25 21:41:10

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

Got it to work  big_smile  Now to transfer to Scratch (might be a challenge because of dependency issues :\)

Offline

 

#8 2011-03-25 21:53:08

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: online high-score system

wcfs96 wrote:

Got it to work  big_smile  Now to transfer to Scratch (might be a challenge because of dependency issues :\)

I don't think dependency issues are a problem. If you're able to get it into Panther, then it will work (theoretically). The problem is, it won't be in everyone's copy of Panther, so it would be hard to distribute the project.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#9 2011-03-25 22:03:22

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

ScratchReallyROCKS wrote:

wcfs96 wrote:

Got it to work  big_smile  Now to transfer to Scratch (might be a challenge because of dependency issues :\)

I don't think dependency issues are a problem. If you're able to get it into Panther, then it will work (theoretically). The problem is, it won't be in everyone's copy of Panther, so it would be hard to distribute the project.

Actually I am running into dependency issues (Scratch really takes a lot out from Squeak) The Mysql library would be in the .image so within an update everyone should have it. I'm wondering if I could put Scratch onto the newest version of Squeak and keep all the core libraries so it would be much easier to add things to it. I'll try it on Panther as well but I'm sure I'll run into the same problems I was having with Scratch.

Offline

 

#10 2011-03-26 03:29:12

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

This all looks very promising! Don't worry about distribution issues, I'm distributing this game along with it's own edited version of Panther anyway.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#11 2011-03-26 06:14:36

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: online high-score system

Taneb wrote:

PHP code:
<?php
$con = mysql_connect("dbhostname","username","password");
mysql_select_db("highscore",$con);
$loggedin=("SELECT PASSWORD FROM users_and_passwords WHERE username = '" . $_GET["username"] . "'" == $_GET["password"]);
if($loggedin){
//code to add highscore to database
echo("highscore added");
}
else
{
echo("incorrect username/password");
}
?>

That has a HUGE security flaw. I used a similar script for my website once, and I found it wasn't secure in the slightest.

What you do is just provide a non-existant username with no password and it will let you in. Because there is no entry in the table with the provided username from which to select the password, when you try to access the password variable it will be blank. When compared to the empty password provided, it matches and logs you in.

A better script is as follows:

Code:

<?php
$con = mysql_connect("dbhostname","username","password");
mysql_select_db("highscores",$con);
$user = mysql_real_escape_string($_GET["username"]);
$pass = mysql_real_escape_string($_GET["password"]);
$result = mysql_query("SELECT password FROM users_and_passwords WHERE username = '" . $user . "' AND password = '" . $pass . "'");
if(mysql_num_rows($result) == 1){
//code to add highscore to database
echo("highscore added");
}
else
{
echo("incorrect username/password");
}
?>

Last edited by TheSuccessor (2011-03-26 06:16:31)


/* No comment */

Offline

 

#12 2011-03-26 09:42:06

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

Not sure if I can do this, the differences between the two is just too great, can't get anything to work. Do you know that version of Squeak Scratch is running? Also could you post a link to the Panther thread so I could download it.

Offline

 

#13 2011-03-26 14:26:01

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

wcfs96, the Panther website which has a download page on it is heresmile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#14 2011-03-26 19:12:05

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

Thanks, I'm still trying to port over the Mysql library and still having trouble... But I am getting closer  smile

Offline

 

#15 2011-03-26 21:32:17

jamalaron
Scratcher
Registered: 2010-08-16
Posts: 37

Re: online high-score system

what


>enter forum
it is dark and the forum is lively you are likely to be eaten by a philistine

Offline

 

#16 2011-03-27 14:45:59

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

From what I can tell then, sending the info in the "GET link" is the only method. It shouldn't be too unsafe as the link is only sent quickly to that one place, it shouldn't be too insecure.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#17 2011-03-27 17:40:53

wcfs96
New Scratcher
Registered: 2011-03-10
Posts: 37

Re: online high-score system

sparks wrote:

From what I can tell then, sending the info in the "GET link" is the only method. It shouldn't be too unsafe as the link is only sent quickly to that one place, it shouldn't be too insecure.

I'm determined to get this to work  smile  I'm on their IRC right now trying to figure it out, I think I know what I have to do now to get it to work.

Offline

 

#18 2011-03-27 19:00:28

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

Thanks for your time, wcfs96, this is a pretty exciting idea you have!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#19 2011-03-28 11:34:52

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: online high-score system

sparks wrote:

From what I can tell then, sending the info in the "GET link" is the only method. It shouldn't be too unsafe as the link is only sent quickly to that one place, it shouldn't be too insecure.

It is definitely possible to get POST to work with Squeak. Look at the upload dialog source for Scratch projects. It is definitely using HTTP POST. We only have to adjust it...


/* No comment */

Offline

 

#20 2011-03-28 12:57:01

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

hmm, you have a point. How does the page read it though? If the information isn't being sent in the link, where is it put?

Also, you know when you import a sound into scratch, it says down-sampling and converting to mono? What's with that? Can I get rid of it and keep high quality stereo sound or is it physically not possible for squeak to play stereo sound?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#21 2011-03-28 13:05:32

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: online high-score system

sparks wrote:

hmm, you have a point. How does the page read it though? If the information isn't being sent in the link, where is it put?

Also, you know when you import a sound into scratch, it says down-sampling and converting to mono? What's with that? Can I get rid of it and keep high quality stereo sound or is it physically not possible for squeak to play stereo sound?

Possibly.
It might be Squeak's problem, or maybe the Scratch Developers implemented it so the project size wouldn't be too impossible when sound was added.

Offline

 

#22 2011-03-28 13:24:52

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: online high-score system

I really really really really need to get rid of it!  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer