Current threads on this forum has motivated me to work on a highscore system. Fortunately, the user system was already in place for an older project I started years ago.
Register your username/company/publisher here:
http://gamespace.zimnox.com/register.php
Once you've activated your user account through the confirmation email, you can log in and select your profile by clicking on your name in the top right corner of the site.
From your profile page, you can add new games. Each game provides you with a private key. You'll need this key to submit scores from AppGameKit using POST data, so keep it out of public source code!
Currently, the system limits you to only 10 scores per game. It will automatically bump the lowest score from the table when a higher score is submitted.
Here's an example of submitting your score through AGK. Spacebar to submit a score, ENTER to retrieve the scores in a CSV format. The first token in the response string is the number of score entries being returned. I've left an example key code in the demo for you to play with.
setVirtualResolution(800,600)
#CONSTANT GAME_KEY = "c4d423cb7f2f4492ed48079ba76ef59d08cd144b"
Type ScoreUDT
name as string
score as integer
EndType
scoreObject = 0
submitObject = 0
repeat
// Press SPACE key
if getRawKeyPressed(32)
score = 3579
submitObject = submitScore("Jeffrey", str(score), GAME_KEY)
endif
// Press ENTER key
if getRawKeyPressed(13)
scoreObject = getScore(GAME_KEY)
endif
if submitObject > 0
res = getSubmissionResponse(submitObject)
if res = 1 then submitObject = 0
endif
if scoreObject > 0
scores$ = getScoreResponse(scoreObject)
if scores$ <> ""
scoreObject = 0
count = countStringTokens(scores$, ",")
size = val(getStringToken(scores$, ",", 1))
dim scoreboard[size] as ScoreUDT
j = 1
for i = 2 to count step 2
player$ = getStringToken(scores$, ",", i)
score = val(getStringToken(scores$, ",", i+1))
scoreboard[j].name = player$
scoreboard[j].score = score
inc j
next i
endif
endif
if res = 1 then print("Submission Successful")
for i = 1 to size
print(scoreboard[i].name+" - "+str(scoreboard[i].score))
next i
sync()
until getRawKeyPressed(27) = 1
end
function getScore(gameKey$)
http = createHTTPConnection()
r = setHTTPHost(http, "zimnox.com", 0, "", "")
vars$ = "gamekey="+gameKey$
sendHTTPRequestASync(http, "gamespace/test.php", vars$)
endfunction http
function getScoreResponse(scoreObject)
res = getHTTPResponseReady(scoreObject)
scores$ = ""
if res = -1
// Error
elseif res = 1
scores$ = GetHTTPResponse(scoreObject)
endif
if res <> 0
closeHTTPConnection(scoreObject)
deleteHTTPConnection(scoreObject)
endif
endfunction scores$
function getSubmissionResponse(scoreObject)
res = getHTTPResponseReady(scoreObject)
if res = -1
// Error
elseif res = 1
res = val(GetHTTPResponse(scoreObject))
endif
if res <> 0
closeHTTPConnection(scoreObject)
deleteHTTPConnection(scoreObject)
endif
endfunction res
function submitScore(player$, score$, gameKey$)
http = createHTTPConnection()
r = setHTTPHost(http, "zimnox.com", 0, "", "")
vars$ = "player="+player$+"&score="+score$+"&gamekey="+gameKey$
sendHTTPRequestASync(http, "gamespace/test.php", vars$)
endfunction http
thing:
MainLoop()
end
function MainLoop()
Response$=GetFromWeb("zimnox.com","gamespace/test.php")
repeat
Print(Response$)
if getpointerpressed()=1 then exit
Sync()
until getRawKeyPressed(27) = 1
exit
endfunction
function GetFromWeb(Host$,URLPath$)
Response$=""
if GetInternetState()=1
iHTTP=CreateHTTPConnection()
iSecure=0
szUser$=""
szPass$=""
if SetHTTPHost( iHTTP, Host$, iSecure, szUser$, szPass$ )=1
if SendHTTPRequestASync( iHTTP, URLPath$ )=1
do
ret=GetHTTPResponseReady( iHTTP )
if ret=-1 then exit //Cancel
if ret=1 then exit //Ready
print("wait ...")
sync()
loop
if ret=1
Response$=GetHTTPResponse( iHTTP )
endif
endif //Get
CloseHTTPConnection( iHTTP )
endif //Host
DeleteHTTPConnection( iHTTP )
endif //Internet
endfunction Response$