What's new? | Help | Directory | Sign in
Google
                
Search
for
Updated May 22, 2007 by janko.itm
Labels: Highscore, Example, Server
ExampleHighScoresList  

#Example of simple high score list.

Introduction

This 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.php

This 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.php

This 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