API and HTML Examples

For discussion of the Poker Mavens server module and other administration topics
Post Reply
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

API and HTML Examples

Post by Kent Briggs »

I've created an official page for my various PHP API examples here:

http://www.briggsoft.com/docs/pmavens/API_Examples.htm

and another one for custom HTML (e.g., banner ads, etc.) here:

http://www.briggsoft.com/docs/pmavens/HTML_Examples.htm
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: API and HTML Examples

Post by Kent Briggs »

Just added to the API page is this PHP routine that allows anyone to search if a player is logged in and gives a list of the tables where they are currently seated:

Code: Select all

<html>
<body>

  <?php
    if (isset($_REQUEST["Search"]))   // page load via search button
    {
      include "API.php";  // include file has $pw, $url, Poker_API()
  
      // get player name submitted by form

      $player = $_REQUEST["Player"];        
      if ($player == "")
      {
        echo "<b>No player name entered. Click the back button.</b><br/>";
        exit;
      } 

      // get list of connections 

      echo "<b>Searching logins ...</b><br/>";
      $params = "Password=$pw&Command=ConnectionsList&Fields=Player";
      $api = Poker_API($url,$params);
      if ($api["Result"] == "Error")
      {
        echo "Error: " . $api["Error"] . "<br/>";
        exit;
      }

      // loop thru connections list looking for player

      $found = false; 
      $connections = $api["Connections"];
      for ($i = 1; $i <= $connections; $i++)        {
        if (strcasecmp($player,$api["Player" . $i])==0)
        {
          $found = true;
          break;
        }
      }
      if ($found == true) echo $player . " is logged in<br/>"; else 
      {
        echo $player . " is not logged in<br/>";
        echo "<br/><b>Click the back button for another search</b><br/>";
        exit;
      }

      // get list of ring games

      echo "<br/><b>Searching ring game tables ...</b><br/>";
      $params = "Password=$pw&Command=RingGamesList&Fields=Name";
      $api = Poker_API($url,$params);
      if ($api["Result"] == "Error")
      {
        echo "Error: " . $api["Error"] . "<br/>";
        exit;
      }

      // loop thru ring games list looking for player

      $found = 0;
      $rcount = $api["RingGames"];
      for ($i = 1; $i <= $rcount; $i++)
      {
        $r = $api["Name" . $i];
        $params = "Password=$pw&Command=RingGamesPlaying&Name=" . urlencode($r);
        $api2 = Poker_API($url,$params);
        $pcount = $api2["Count"];

        // loop thru players list

        for ($j = 1; $j <= $pcount; $j++)
        {
          if (strcasecmp($player,$api2["Player" . $j])==0)
          {
            $found++;
            echo $player . " is seated at " . $r . "<br/>";
            break;
          }
        }
      }
      if ($found == 0) echo $player . " is not seated at any ring game tables<br/>";

      // get list of tournaments

      echo "<br/><b>Searching tournament tables ...</b><br/>";
      $params = "Password=$pw&Command=TournamentsList&Fields=Name";
      $api = Poker_API($url,$params);
      if ($api["Result"] == "Error")
      {
        echo "Error: " . $api["Error"] . "<br/>";
        exit;
      }

      // loop thru tournaments list looking for player

      $found = 0;
      $tcount = $api["Tournaments"];
      for ($i = 1; $i <= $tcount; $i++)
      {
        $t = $api["Name" . $i];
        $params = "Password=$pw&Command=TournamentsPlaying&Name=" . urlencode($t);
        $api2 = Poker_API($url,$params);
        $pcount = $api2["Count"];

        // loop thru players list

        for ($j = 1; $j <= $pcount; $j++)
        {
          if (strcasecmp($player,$api2["Player" . $j])==0)
          {
            $found++;
            echo $player . " is seated at " . $t . " - Table " . $api2["Table" . $j] . "<br/>";
            break;
          }
        }
      }
      if ($found == 0) echo $player . " is not seated at any tournaments<br/>";
      echo "<br/><b>Click the back button for another search</b><br/>";
      exit;
    }
  ?>

  <!-- display input form on first load  -->
  <!-- post results back to same page -->

  <h3>Search for Player</h3>
  <form method="post">
    Screen name:<br/>
    <input type="text" name="Player" />
    <input type="submit" name="Search" value="Search" />
  </form>

</body>
</html>
rjones33
Posts: 98
Joined: Tue Jun 24, 2008 6:51 pm
Location: Warrenville, SC
Contact:

Re: API and HTML Examples

Post by rjones33 »

Great examples...I have implemented all of them except for the account export example. I currently store all my user data in a SQL database so I'm not sure if I am gonna implement that one or not. One project I am working on though is a points system for league tournament play where the players receive points based on their finishing postion rather than chips. Any plans to implement something like this in future releases? Thanks Kent.
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: API and HTML Examples

Post by Kent Briggs »

rjones33 wrote:One project I am working on though is a points system for league tournament play where the players receive points based on their finishing postion rather than chips. Any plans to implement something like this in future releases?
That would be very difficult to implement because everyone would have their own idea of how the point system should work for their particular site, who would qualify, how it would be reported, how often, yada yada. You would be better off just pulling the tournament results via the API and making your own system.
rjones33
Posts: 98
Joined: Tue Jun 24, 2008 6:51 pm
Location: Warrenville, SC
Contact:

Re: API and HTML Examples

Post by rjones33 »

I agree..That's what I'm planning on implementing. Thanks.
lp69
Posts: 9
Joined: Sat Sep 20, 2008 2:49 am

Re: API and HTML Examples

Post by lp69 »

rjones33 wrote: I currently store all my user data in a SQL database.
Hi Ricky,

How do you do that ? I thought it wasn't possible, I didn't figure out how to have the poker server retrieve the data from the SQL database.
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: API and HTML Examples

Post by Kent Briggs »

lp69 wrote:I didn't figure out how to have the poker server retrieve the data from the SQL database.
Most likely he's just moving data back and forth as needed from the poker server to his own database via the API. Typically this would get triggered by the user logging into a web interface and that interface would then launch the flash client. The poker server has no importing abilities on its own.
rjones33
Posts: 98
Joined: Tue Jun 24, 2008 6:51 pm
Location: Warrenville, SC
Contact:

Re: API and HTML Examples

Post by rjones33 »

lp69 wrote:How do you do that ? I thought it wasn't possible, I didn't figure out how to have the poker server retrieve the data from the SQL database.
Kent is correct. It is really very simple. The way I have my workflow setup, everything runs through the website. For example, when a user goes to my site and creates a user account, I create the the account via the api and also write the information to a table in a SQL database. I also use this data as the user's membership data to access the website so everything stays in sync and one set of credentials get the user into everthing: website, forums, poker server, etc. Go by the site and check it out at http://www.pokersharkz.net
lp69
Posts: 9
Joined: Sat Sep 20, 2008 2:49 am

Re: API and HTML Examples

Post by lp69 »

OK I see, thanks.
But since the whole process still uses 1 file per account, it is still well under the expected performance of using a database only.
As a suggestion ,PM should propose a real database mode.
This would be quite easy: e.g. the server would propose a connection string as an option field and PM uses standard SQL queries to do the job, including a CREATE TABLE at first run to establish the required tables.
Kent Briggs
Site Admin
Posts: 5878
Joined: Wed Mar 19, 2008 8:47 pm

Re: API and HTML Examples

Post by Kent Briggs »

lp69 wrote:OK I see, thanks.
But since the whole process still uses 1 file per account, it is still well under the expected performance of using a database only.
The accounts are all loaded into memory at startup so past that point, the system is actually faster than if it were using an external database. However, the current system isn't very scalable so eventually I will be going to a database so that the load could be spread across multiple servers.
Post Reply