forked from craftyjs/Crafty
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on server side of saving game to server.
- Loading branch information
MPetrovic
committed
Nov 2, 2011
1 parent
3f62706
commit a144d60
Showing
3 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
require_once('db.auth.inc'); | ||
require_once('db.'.$dbType.'.inc'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
<?php | ||
include('db.mysql.inc'); | ||
$db = mysql_real_escape_string($_POST['game']); | ||
include('db.main.inc'); | ||
|
||
$table = 'save'; | ||
$fields = array( | ||
'key' => array( | ||
'type' => 'string', | ||
'length' => 255, | ||
'index' => 'primary key', | ||
), | ||
'player' => array( | ||
'type' => 'int', | ||
'length' => 11, | ||
), | ||
'ts' => array( | ||
'type' => 'timestamp', | ||
), | ||
'data' => array( | ||
'type' => 'text', | ||
), | ||
); | ||
|
||
createTable($table, $fields); | ||
|
||
$output = array(); | ||
switch ($_POST['mode']) { | ||
case 'timestamps': | ||
$s = s("SELECT key, ts AS timestamp FROM %s", $table); | ||
$q = q($s); | ||
while ($r = f($q)) { | ||
$output[] = (object)$r; | ||
} | ||
break; | ||
case 'save': | ||
$r = f(q(s("SELECT COUNT(key) AS c FROM %s WHERE key = '%s'", $table, $_POST['key']))); | ||
if ($r['c']) { | ||
// update | ||
q(s("UPDATE %s SET data = '%s', ts = %d WHERE key = '%s'", $table, serialize($_POST['data']), $_POST['timestamp'])); | ||
} | ||
else { | ||
// insert | ||
q(s("INSERT INTO %s VALUE('%s', 0, %d, '%s')", $table, $_POST['key'], $_POST['timestamp'], serialize($_POST['data']))); | ||
} | ||
break; | ||
case 'load': | ||
break; | ||
} | ||
|
||
echo json_encode($output); | ||
?> |