Panther and many other mods have blocks to get data from web pages. However, they are not currently able to send data to a server using HTTP_POST. Could this be implemented into a mod? How?
Offline
actually there is no real need to use a post request. A GET request can also be used to send data. You could do something like domain.com/scratchpage.php?msg=MyMessage
If you want to fill in form requests, I guess you'll need another block...
Offline
sendRequest
| t1 t2 t3 t4 t5 t6 |
t1 _ Smalltalk platformName = 'Win32'.
t2 _ Time millisecondClockValue.
t3 _ 1.
[t3 <= request size]
whileTrue:
[socket isConnected ifFalse: [^ self abort: 'broken connection during upload'].
t4 _ socket sendDataNoWait: request startIndex: t3.
t3 _ t3 + t4.
t5 _ t3 asFloat / request size.
t1
ifTrue:
[t6 _ 10.0 * (Time millisecondClockValue - t2).
t5 _ (t5 min: t6 / request size)
min: 1.0].
self percentDone: 10.0 + (85.0 * t5).
self sleepAWhile]This is how the upload dialog does http post, if anyone could explain I would be grateful.
Offline
Bump
Offline
That's what I'm doing while HTTP_POST isn't working. It's called GET (which you probably know from PHP's $_GET array).
Offline
Bump
DOWN WITH 60 SECOND RULE
Last edited by TheSuccessor (2010-09-20 11:16:16)
Offline
Is this for my thread, but I dont know.
Offline
johnnydean1 wrote:
Is this for my thread, but I dont know.
It could be, but it was going to be useful anyway. I might CYOB it when it's sorted out, because then I can do something fun...
Offline
Bump
Offline
lol it may help to stop bumping youre still at the top...
Offline
blackeyedpeasrule98 wrote:
lol it may help to stop bumping youre still at the top...
I am now I've bumped.
Offline
bumped?
Offline
TheSuccessor wrote:
Code:
sendRequest | t1 t2 t3 t4 t5 t6 | t1 _ Smalltalk platformName = 'Win32'. t2 _ Time millisecondClockValue. t3 _ 1. [t3 <= request size] whileTrue: [socket isConnected ifFalse: [^ self abort: 'broken connection during upload']. t4 _ socket sendDataNoWait: request startIndex: t3. t3 _ t3 + t4. t5 _ t3 asFloat / request size. t1 ifTrue: [t6 _ 10.0 * (Time millisecondClockValue - t2). t5 _ (t5 min: t6 / request size) min: 1.0]. self percentDone: 10.0 + (85.0 * t5). self sleepAWhile]This is how the upload dialog does http post, if anyone could explain I would be grateful.
BUMPITY BUMPITY BUMP
Offline
Oh. Now I see how you can store high scores online and download them back into the game.
Basicly.
Scratch --> (Update high score) http://example.com/scratch.php?score=200&name=what-the
Webserver runs scratch.php
<?php
$score = $_GET['score'];
$user = $_GET['user'];
$connection = mysql_connect("localhost", "Username", "Password") or die (mysql_error());
@mysql_select_db("Scratchdatabase");
//Then get highscore from the database
if($score > $highscore){
//Update database
} else {
//Do what ever if not a high score
}
Print"$highscore";
?>
Scratch. Get high score from webserver
Last edited by what-the (2010-09-26 08:43:57)
My site Offline
what-the wrote:
Oh. Now I see how you can store high scores online and download them back into the game.
Basicly.
Scratch --> (Update high score) http://example.com/scratch.php?score=200&name=what-the
Webserver runs scratch.php
<?php
$score = $_GET['score'];
$user = $_GET['user'];
$connection = mysql_connect("localhost", "Username", "Password") or die (mysql_error());
@mysql_select_db("Scratchdatabase");
//Then get highscore from the database
if($score > $highscore){
//Update database
} else {
//Do what ever if not a high score
}
Print"$highscore";
?>
Scratch. Get high score from webserver
[/block]
An extremely smart idea What-The! This would allow you to save scores, but problem is... People could change the project and have 999999 points, and change their name to something like "I AM THE WINNER!"
I'll go work on something like this...
Last edited by Magnie (2010-09-27 14:02:11)
Offline
( I hope me bumping this isn't a problem. )
Okay, I have gotten it to work ( finally )
Link to Viewing the Scores: http://playfultest.x10.mx/magnie/test/scratch-score.php
- Pretty basic, just displaying how many scores, and then displaying the scores. However, it is not ordered, so that will have to be added.
<?php
$con = mysql_connect("localhost","table","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
$page = "Connection Successful<BR><BR>";
}
mysql_select_db("table", $con);
$result = mysql_query("SELECT * FROM scratch_scores", $con);
$num_rows = mysql_num_rows($result);
$page .= "Scores: ".$num_rows."<BR>
<table border='1'>
<tr>
<td> ID </td><td> Name </td><td> Score </td>
</tr>";
while ($row = mysql_fetch_assoc($result)) {
$page .= "<tr><td>".$row['id']."</td><td>".$row['name']."</td><td>".$row['score']."</td></tr>";
}
$page .= "</tr>
</table>";
mysql_free_result($result);
// Display Page
echo $page;
mysql_close($con);
?>Pretty sloppy, could be better.
Link to Adding a Score: http://playfultest.x10.mx/magnie/test/scratch-score-add.php
- Pretty basic too, adds a score. You will need to add ?name=[name]&score=[score] and replace the items in "[ ]"'s ( also taing away the "[ ]"'s ) for it to add a score. ( Example: http://playfultest.x10.mx/magnie/test/scratch-score.php?name=Test&score=0 ) Then go to the viewer, and it should show at the bottom.
<?php
$con = mysql_connect("localhost","table","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
$page = "Connection Successful<BR><BR>";
}
$name = $_GET['name'];
$score = $_GET['score'];
$result = mysql_query("SELECT * FROM table.scratch_scores", $con);
$num_rows = mysql_num_rows($result);
if ($name)
{
$add_score = mysql_query("INSERT INTO table.scratch_scores (`id`,`name`,`score`)
VALUES ('$num_rows', '$name', '$score')");
echo $name." ( with ID#".$num_rows." ) has been added with score ".$score.".";
}
?>And just as sloppy. That should also give a clue on how to make a web-server act as a game server.
The entire thing is "raw" so anyone could connect to the add.php page and add a random score. ( BIGGEST_SCORE with 9999999999 score ) Also the code is free to use. ^.^
Edit: I forgot to add the Panther code...
[When Flag Clicked]
[ask "What's your Scratch Username?" and wait]
[set Score to (pick random from [1] to [1000])]
[set Name to (answer)]
[set Add to ( contents at file URL ( join ( join ( join 'http://playfultest.x10.mx/magnie/test/scratch-score.php?name=' ) [Name] ) '&score=' ) [Score] )]
Display all three variables and you should see the Add variable change to the web page content.
Last edited by Magnie (2010-09-29 23:06:37)
Offline
Magnie wrote:
( I hope me bumping this isn't a problem. )
Okay, I have gotten it to work ( finally )
Link to Viewing the Scores: http://playfultest.x10.mx/magnie/test/scratch-score.php
- Pretty basic, j....
...
...
Display all three variables and you should see the Add variable change to the web page content.
Very nice
Have you got scratch to download the highscores yet? This could go quite far. We could work on encrypting the URL so that people can't just add a score which they didn't actually get.
You could use a swaping algorithm.
$link = $_GET['link'];
$string= $link;
$string = (explode('w', $string)); //where the w is you can put anything
$score = 0 ; //set score to zero every score will show a zero at the start but we can fix that later
foreach ($string as $element) {
if ($element = #Random letters that you want#){ //The random letters cannot be the same as the exploded character (w in this case)
$score .= 0;
}else {
if ($element = #Random letters that you want#){
$score .= 1;
}else {
if ($element = #Random letters that you want#){
$score .= 2;
}else {
if ($element = #Random letters that you want#){
$score .= 3;
}else {
if ($element = #Random letters that you want#){
$score .= 4;
}else {
if ($element = #Random letters that you want#){
$score .= 5;
}else {
if ($element = #Random letters that you want#){
$score .= 6;
}else {
if ($element = #Random letters that you want#){
$score .= 7;
}else {
if ($element = #Random letters that you want#){
$score .= 8;
}else {
if ($element = #Random letters that you want#){
$score .= 9;
}else {
//There was an error in the score the score remains at zero
}
}
}
}
}
}
}
}
}
}
}
//Take off first zero if score is valid
//Check score with database
//Print out score and congratulate if highscore
Last edited by what-the (2010-10-01 04:04:19)
My site Offline
If else If else If else... Try switch{ case case case }. It's much faster and easier to read. Anyway, BUMP 3RD POST.
Offline
TheSuccessor wrote:
If else If else If else... Try switch{ case case case }. It's much faster and easier to read. Anyway, BUMP 3RD POST.
Yeah it is but I love using if's.
$link = $_GET['link'];
$string= $link;
$string = (explode('w', $string)); //where the w is you can put anything
$score = 0;
foreach ($string as $element) {
switch($element){
case #Random letters that you want#: //The random letters cannot be the same as the exploded character (w in this case)
$score .= 0;
case #Random letters that you want#:
$score .= 1;
case #Random letters that you want#:
$score .= 2;
case #Random letters that you want#:
$score .= 3;
case #Random letters that you want#:
$score .= 4;
case #Random letters that you want#:
$score .= 5;
case #Random letters that you want#:
$score .= 6;
case #Random letters that you want#:
$score .= 7;
case #Random letters that you want#:
$score .= 8;
case #Random letters that you want#:
$score .= 9;
default:
$score = 0;
die ("Score is invalid");
}
}
//Take off first zero if score is valid
//Check score with database
//Print out score and congratulate if highscore
Last edited by what-the (2010-10-01 04:39:33)
My site Offline
TheSuccessor wrote:
BUMP 3RD POST.
Offline
what-the wrote:
TheSuccessor wrote:
If else If else If else... Try switch{ case case case }. It's much faster and easier to read. Anyway, BUMP 3RD POST.
Yeah it is but I love using if's.
I might use an associative array in this case, something like:
$link = $_GET['link'];
$string= $link;
$string = (explode(':', $string)); //where the : is you can put anything
$scoreIncrements = array(
'sXe' => 1,
'iJc' => 5,
'YiA' => 10,
's6Q' => 50,
'iUA' => 100,
'pAj' => 500,
'zYI' => 1000,
'kRx' => 5000,
);
$score = 0;
foreach ($string as $elem) {
if (isset($scoreIncrements[$elem])) {
$score += $scoreIncrements[$elem];
} else {
die ("Score code is invalid: " . $elem);
}
}For example, I might send it the code "kRx:iUA:iUA:s6Q:YiA:sXe" which would be 5261.
EDIT: Wow I forgot a lot of semicolons.
Last edited by nXIII (2010-10-01 14:46:40)
Offline
Displaying the scores in Panther... hmm... Let me whip something up. Maybe I should take out the formatting code in the display page... Then I could have it read the lines and add it to a List. I'll get that made one sec.
Edit: So, it reads the page from the source, and all the scores are on a single line.
Connection Successful<BR><BR>Scores: 10<BR> ID - Name - Score0 - Magnie - 645<BR>1 - Magnie - 18<BR>2 - Magnie - 230<BR>3 - MAgnie - 137<BR>4 - Magnie - 385<BR>5 - Magnie - 503<BR>6 - Magnie - 438<BR>7 - Magnie - 437<BR>8 - Magnie - 765<BR>9 - what-the is testing this - 1337<BR>
I'm going to see if I can make back around for it.
Okay, I have found one.
<?php
$con = mysql_connect("localhost","table","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
$page = "Connection Successful<BR><BR>";
}
mysql_select_db("table", $con);
$result = mysql_query("SELECT * FROM scratch_scores", $con);
$num_rows = mysql_num_rows($result);
$page .= "Scores: ".$num_rows."<BR>
ID - Name - Score <BR>";
while ($row = mysql_fetch_assoc($result)) {
$page .= "
".$row['id']." - ".$row['name']." - ".$row['score']."<BR>";
}
mysql_free_result($result);
// Display Page
echo $page;
mysql_close($con);
?>So I've taken out the formatting and if you look closely at
while ($row = mysql_fetch_assoc($result)) {
$page .= "
".$row['id']." - ".$row['name']." - ".$row['score']."<BR>";
}There is a space on the line below $page .= " and it has a space. That is extremely necessary, otherwise the View Source will display it all on one line. As for the <BR>'s. Those are required for the browser display. Unless we make separate web pages for Panther/Scratch and Browsers.
The Panther program:
[When Flag Clicked] [set Line to '1'] [set Max to (number of lines of file at URL [http://playfultest.x10.mx/magnie/test/scratch-score.php])] [repeat until <[Max<Line]>] [Add (line [Line] of file at URL [http://playfultest.x10.mx/magnie/test/scratch-score.php]) 'Score' list] [change Line by '1'] [end repeat]
Also guys, lets start out with the basics before we start encrypting the scores.
What I have right now is free to use, so you can create multiple Scores, but please, don't spam it.
So, lets get this part done first, then we'll move on to encrypting the scores.
Off topic: I may host scores for those who want it for their game, just send me a comment.
Last edited by Magnie (2010-10-01 23:36:46)
Offline
TheSuccessor wrote:
BUMP 3RD POST.
Offline
I can get to work making that into a block give me a minute.
Offline