// To use this code, simply call:
// world.Export("http://www.YourHost.com/ScoreBoard.dmb?submit=true&key=[key]&scor[score]&hash=[md5("[score*3+2]")]")
#define DEBUG
world
version=2
// Define a Score datum to easily manage
Score
var
Owner=""
Score=0
// Keep a list of the Score datums
var
list
Scores=list()
CGI/Topic(href,href_list)
// If the game is actually submitting a score...
if(href_list["submit"])
// First make some variables that are easier to deal with
var/Score=text2num(href_list["score"])
var/Key=href_list["key"]
var/hash=href_list["hash"]
// Load up a savefile and import its Scores list.
var/savefile/F=new("Scores.sav")
F["Scores"]>>Scores
// Just in case there was no savefile
if(!Scores)
Scores=list()
// Compare the hash value that was sent to what it should be.
// If it's right...
if((hash)==(md5("[Score+3*2]"))) // Change this!
// Make a variable so a new datum isn't added if they do have a score
var/Found=0
// Loop to see if they have a score in the list
for(var/Score/S in Scores)
// If they have a score...
if(S.Owner==Key)
// Check to see if it is bigger
if(S.Score<Score)
//If it is bigger, set the score datum in the list to their new score
S.Score=Score
// Set that variable to true, so a new datum isn't added to the list
Found=1
// Break the loop; we already found their Score datum
break
// If we didn't find a score datum...
if(!Found)
// Make a new one, set the appropriate variables, and add it to the list
var/Score/S = new
S.Owner=Key
S.Score=Score
Scores+=S
// Save the scores list
F["Scores"]<<Scores
// You must output something, or the DMCGI app will generate an Internal Server Error.
usr << "<a href=?ranks>Return Code: 5023543</a>"
// If the hash is wrong, it means someone tried to fake their score. We still return something \
to avoid an Internal Server Error. You may want to add some sort of mean message here, because \
this person is probably a cheater.
else
usr<<"Improper Hashing. <a href=?ranks>Return</a>"
// If the game isn't submitting a score, and someone is just viewing the scoreboard...
else
// Make a content variable to hold the start of the scoreboard. We do this so we can start the \
table here, then loop through the list and add all the scores in table cells, and then close off \
the table.
var/content={"
<html>
<head>
<title>Bleach: A Vaizards Destiny by Seteden: High Scores Table</title>
</head>
<body bgcolor=#999999>
<table align=center border=1 bordercolor=#cccccc width=50%>
<tr><td colspan=2><font size=5><center>A Vaizards Destiny High Scores</center></font></td></tr>
<tr><td width=50%><center>Key:</center></td><td width=50%><center>Score:</center></td></tr>
"}
// Open up the savefile to load the scores list
var/savefile/F=new("Scores.sav")
F["Scores"]>>Scores
// If there's anything inside...
if(Scores)
// Sort the list.
BubbleSort(Scores)
// Loop through the list...
for(var/i=1,i<=Scores.len,i++)
// Access the Score datum at this position in the list
var/Score/S = Scores[i]
// And add a table row with the Score's owner and score values.
content+="<tr><td><center>[S.Owner]</center></td><td><center>[S.Score]</center></td></tr>"
// Close off the table
content+="</table><br><br><br>Copyright© Seteden 2009</body></html>"
// And output the scoreboard!
usr<<browse(content)
// A simple bubblesort. Replace it if you want. Keep in mind, though, that the list is not full of \
numbers, but instead filled with datums with a number variable.
proc/BubbleSort(list/L)
for(var/i = L.len; i >= 1; i--)
for(var/j = 1; j < i; j++)
var/Score/S1=L[j]
var/Score/S2=L[j+1]
if(S1.Score<S2.Score)
L.Swap(j, j+1)
ID:158721
Jul 10 2009, 2:37 am
|
|
ok so this is going to sound really stupid but I don't understand what to do to get the scoreboard into a verb here..I'm using a library and its just a bit confusing to me.
|
Jul 10 2009, 5:46 am
|
|
The first two lines might give you a hint man...
|
In response to SSJ Radditz
|
|
how so?
|
In response to Seteden
|
|
Here's a strange idea: tried reading the comments in the first two lines?
Hint: world.Export() is a procedure. |
In response to GhostAnime
|
|
by doing that tho, turning that into a procedure and wiping out the // infront of it, i get the error Scoreboard.dm:4:error: bad argument definition
|
In response to Seteden
|
|
LMAO
|