REM ***********************************************
REM Title: Gamespace
REM Author: Phaelax
REM Downloaded from: http://dbcc.zimnox.com/
REM ***********************************************
 
setVirtualResolution(800,600)
 
 
#CONSTANT GAME_KEY = "<your game key>"
playerName$        = "Prince"
score              = 3579
 
 
Type ScoreUDT
    name  as string
    score as integer
EndType
 
scoreObject = 0
submitObject = 0
 
 
 
repeat
    // Press SPACE key to submit a score
    if getRawKeyPressed(32)
        score = random(999, 9999)
        submitObject = submitScore(playerName$, str(score), GAME_KEY)
    endif
 
    // Press ENTER key to retrieve scores
    if getRawKeyPressed(13)
        scoreObject = getScore(GAME_KEY)
    endif
 
 
    // Score is being submitted, wait for response
    if submitObject > 0
        res = getSubmissionResponse(submitObject)
        if res = 1 then submitObject = 0
    endif
 
 
    // Retrieving scores, wait for response
    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
 
 
    // Score submitted successfully
    if res = 1 then print("Submission Successful")
 
 
    // Display scores
    for i = 1 to size
        print(scoreboard[i].name+" - "+str(scoreboard[i].score))
    next i
 
    sync()
until getRawKeyPressed(27) = 1
end
 
 
 
 
// Initiate the connection to get list of scores
function getScore(gameKey$)
    http = createHTTPConnection()
    r = setHTTPHost(http, "purpletoken.com", 1, "", "")
 
    vars$ = "gamekey="+gameKey$
    sendHTTPRequestASync(http, "update/index.php", vars$)
 
endfunction http
 
 
 
// Initiate the connection to submit a score
function submitScore(player$, score$, gameKey$)
    http = createHTTPConnection()
    r = setHTTPHost(http, "purpletoken.com", 1, "", "")
 
    vars$ = "player="+player$+"&score="+score$+"&gamekey="+gameKey$
 
    sendHTTPRequestASync(http, "update/index.php", vars$)
endfunction http
 
 
 
// Waits for response containing score data
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$
 
 
 
// Waits for response after submitting score
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