|
ExampleHighScoresList
#Example of simple high score list. IntroductionThis show how to build a STRPC server who accepts two methods. We have two files on the server to make it all nice and clear server.phpThis is the file that the client calls. $server = new ScoreServer($GLOBALS['dbc']);
$map = array(
array('server', 'storeScore',
array(
array('name', 'string'),
array('score', 'integer'),
array('level', 'integer'),
),
),
array('server', 'getScores',
array(
),
),
);
$rpc = new STRPC();
echo $rpc->serve($map);ScoreServer.phpThis is the backend file. As you see it has no RPC specific code and could be called and used by any other php file (such as the php files that make the highscore list web frontend). class ScoreServer
{
var $dbc;
function ScoreServer($dbc)
{
$this->dbc = $dbc;
}
function storeScore($name, $score, $level)
{
DBs::insertRow($this->dbc, 'scores', array($name, $score, $level);
}
function getScores()
{
return DBs::selectRows($this->dbc, 'scores');
}
}
|
Sign in to add a comment
