This is from an old project, the php should work off the bat
db install sql (I think this was the right one
CREATE TABLE Scores(
id INT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
name VARCHAR(10) NOT NULL DEFAULT 'Anonymous',
game VARCHAR(10) NOT NULL DEFAULT 'Normal',
score INT(5) UNSIGNED NOT NULL DEFAULT '0'
)
ENGINE=InnoDB;
config.php
<?php
$SQL_Host = "127.0.0.1";
$SQL_DB = "gamename";
$SQL_User = "root";
$SQL_Pass = "";
?>
add_score.php
<?php
include "config.php";
$db = mysqli_connect($SQL_Host, $SQL_User, $SQL_Pass, $SQL_DB) or die('Failed to connect: ' . mysqli_connect_error());
//mysql_select_db($SQL_DB) or die('Failed to access database');
$name = mysqli_real_escape_string($db, $_POST['name']);
$game = mysqli_real_escape_string($db, $_POST['game']);
$score = mysqli_real_escape_string($db, $_POST['score']);
$hash = $_POST['hash'];
$privateKey="ptc_tmm_key"; // << set your key
$expected_hash = hash('sha512', $privateKey . $game);
if($expected_hash == $hash) {
$query = "INSERT INTO Scores SET name = '$name' , score = '$score', game = '$game'";
$result = mysqli_query($db, $query) or die('Query failed: ' . mysqli_error($db));
echo $result ;
}else{
echo "hash fail";
}
mysqli_close($db);
?>
get_score.php
<?php
include "config.php";
$db = mysqli_connect($SQL_Host, $SQL_User, $SQL_Pass, $SQL_DB) or die('Failed to connect: ' . mysqli_connect_error());
$game = mysqli_real_escape_string($db, $_POST['game']);
$hash = $_POST['hash'];
$privateKey="ptc_tmm_key";
$expected_hash = hash('sha512', $privateKey . $game);
if($expected_hash == $hash) {
$query = "SELECT * FROM Scores WHERE game='$game' ORDER BY score LIMIT 15";
$result = mysqli_query($db, $query) or die('Query failed: ' . mysqli_error($db));
$output = "";
while($row = mysqli_fetch_assoc($result)) {
$output = $output . $row["name"] . ":" . $row["score"] . "|";
}
//echo json_encode($rows);
//echo rtrim($output, "|");
echo $output;
}else{
echo "hash fail";
}
mysqli_close($db);
?>
And the AppGameKit functions,, these will not work off the bat you will need to create your own but this should give you some starter points
Function GetHighScores(game)
HideAllScores()
if GetDeviceBaseName()="html5"
http_host="localhost"
else
http_host="parttimecoder.000webhostapp.com"
endif
http_key="ptc_tmm_key"
http_get = CreateHTTPConnection()
SetHTTPHost( http_get, http_host, 0 )
//AddHTTPHeader( http_get, "User-Agent", "AGK2" )
if game = 0 : game=GAME_NORMAL : endif
//result = false
wait_response=true
SendHTTPRequestASync( http_get, "php/get_score.php", "game="+GetGameTypeString(game)+"&hash="+Sha512( http_key+GetGameTypeString(game)))
/*
while GetHTTPResponseReady(http_get) = 0
response$ = GetHTTPResponse(http_get)
score_count = CountStringTokens2(response$, "|")
for score_index = 1 to score_count-1
score_item$ = GetStringToken2(response$, "|", score_index)
score_name$ = GetStringToken2(score_item$, ":", 1)
score_value$ = GetStringToken2(score_item$, ":",2)
SetTextString(Highscores_arr_names[score_index-1], score_name$)
SetTextVisible(Highscores_arr_names[score_index-1], true)
SetTextString(Highscores_arr_scores[score_index-1], score_value$)
SetTextVisible(Highscores_arr_scores[score_index-1], true)
SetTextVisible(Highscores_arr_sep[score_index-1], true)
next
endwhile
CloseHTTPConnection(http_get)
DeleteHTTPConnection(http_get)
*/
EndFunction
Function AddHighScore(name as string, game as string, score)
result = false
if GetDeviceBaseName()="html5"
http_host="localhost"
else
http_host="parttimecoder.000webhostapp.com"
endif
http_key="ptc_tmm_key"
http_send = CreateHTTPConnection()
SetHTTPHost( http_send, http_host, 0 )
SendHTTPRequestASync( http_send, "php/add_score.php", "name="+name+"&game="+game+"&score="+str(score)+"&hash="+Sha512( http_key+game ))
EndFunction result