Jump to content




Saving scores on a website.


7 replies to this topic

#1 Kustus

  • New Members
  • 19 posts

Posted 27 July 2012 - 06:07 AM

Hi,

So me and my gang are making a custom map with lots of room with different challenges.
after some half-assed ideas, we thought of a scoring program that gives the players a score in each room, based on time spent on that challenge.
now that we got that setup, we wanted to be able to post the result to a website. and also beeing able to show the top-5 scores from everyone by downloading it from a webpage.
Now getting the data from the webpage and showing it on a monitor isn't that hard.

But posting scores to a webpage? no idea where to start and how.

All the scores are saved in a single string, but how does one use the http.post()?
and what kind of website whould support posting that particular format etc?

if anyone has a clue or a similar program/setup made, please let me know.

#2 Pinkishu

  • Members
  • 484 posts

Posted 27 July 2012 - 09:57 AM

Well youd likely need some script on your website to handle the data (so something like PHP for example) atleast

#3 Kustus

  • New Members
  • 19 posts

Posted 27 July 2012 - 04:22 PM

Yeah I figured it was php. I searched the forums and saw a few guys having done it. But not mutch explained on the those posts.

What Im wondering is more what can a string sendt trough cc contain and how does php handle that code? Im no wiz on php. To be honest I've never coded php. Though I think I could understand a script if I saw one.

#4 Kustus

  • New Members
  • 19 posts

Posted 28 July 2012 - 12:33 AM

ok I got myself a php website with a mysql database connected to it.

I want to send this info to the page:<nick>, <score>.

so id write something like http.post("<host>", nick , score)

is it possible to send 2 variables in 1 http.post? and does anyone know enough php to tell me how to extract those 2 variables?

the rest I can figure out myself. but I cannot get a response from the website, not for lack of trying but simply becouse I dont know if I'm calling the right variables from the post.


dont know if this is making any sense to any of you. But if you know just a teeny bit about this or have made an actual webpage update from a CC post then please share some info with me.

#5 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 28 July 2012 - 01:14 AM

Quick example that should work,

CC Code:
local function postScore(nick, score)
	http.post(
		"http://YourWebsite.whatever/scorepost.php",
		"nick="..textutils.urlEncode(tostring(nick)).."&"..
		"score="..textutils.urlEncode(tostring(score))
	)
end
postScore("TestName", 5982)

PHP, scorepost.php
<?php
if(isset($_POST['nick']) && isset($_POST['score'])){
	$nick = urldecode($_POST['nick']);
	$score = intval(urldecode($_POST['score']));
	//Do stuff with the nick and score here
}
?>


#6 Kustus

  • New Members
  • 19 posts

Posted 28 July 2012 - 01:26 AM

THANK YOU!!!!

will try this and let u know the result!



ok it's not working.

could this be becouse of the way php codes the ""? or is the "" part left out when sending it to the php script?

i made a form on the same page and was able to store new data in the table. any ideas?


the nick parte show as a "nil/"



You are a genius! thanks alot.. 2 days of trying and failing and you fixed it in a jiffy!

at least now I know a bit more php. :)/>

will post the complete code when done.

Edited by Kustus, 28 July 2012 - 01:58 AM.


#7 Pinkishu

  • Members
  • 484 posts

Posted 28 July 2012 - 10:34 AM

View Posttomass1996, on 28 July 2012 - 01:14 AM, said:

Quick example that should work,

CC Code:
local function postScore(nick, score)
	http.post(
		"http://YourWebsite.whatever/scorepost.php",
		"nick="..textutils.urlEncode(tostring(nick)).."&"..
		"score="..textutils.urlEncode(tostring(score))
	)
end
postScore("TestName", 5982)

PHP, scorepost.php
<?php
if(isset($_POST['nick']) && isset($_POST['score'])){
	$nick = urldecode($_POST['nick']);
	$score = intval(urldecode($_POST['score']));
	//Do stuff with the nick and score here
}
?>

Oh yes - all these 99999999999999999999 scores I can see :)/>

#8 xuma202

  • Members
  • 288 posts
  • LocationBonn Germany

Posted 28 July 2012 - 11:17 AM

View PostPinkishu, on 28 July 2012 - 10:34 AM, said:

View Posttomass1996, on 28 July 2012 - 01:14 AM, said:

Quick example that should work,

CC Code:
local function postScore(nick, score)
	http.post(
		"http://YourWebsite.whatever/scorepost.php",
		"nick="..textutils.urlEncode(tostring(nick)).."&"..
		"score="..textutils.urlEncode(tostring(score))
	)
end
postScore("TestName", 5982)

PHP, scorepost.php
<?php
if(isset($_POST['nick']) && isset($_POST['score'])){
	$nick = urldecode($_POST['nick']);
	$score = intval(urldecode($_POST['score']));
	//Do stuff with the nick and score here
}
?>

Oh yes - all these 99999999999999999999 scores I can see :)/>

Making this save against hacking would require a login system. Only a simple MySQL table matching usernames and MD5 hashes of the passwords. Would all work best with e-mail verification. But doing it "the poor way" it could be enough sending a 3rd verification parameter. You would only have to take care that noone ever sees the ComputerCraft code.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users