Application Programming Interface
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Application Programming Interface
I've got a complete API ready for beta testing for any Pro customers who have been using the programmable "/control" interface. Drop me an email if you're interested in getting an advanced copy. No other changes have been made since 2.07 so this will only be of interest to programmers and script writers. The new API contains 43 commands divided into 7 categories:
Accounts - AccountsAdd, AccountsDecBalance, AccountsDelete, AccountsEdit, AccountsGet, AccountsIncBalance, AccountsList
Blacklist - BlacklistAdd, BlacklistCount, BlacklistDelete, BlacklistEdit, BlacklistGet
Connections - ConnectionsGet, ConnectionsList, ConnectionsMessage, ConnectionsTerminate
Logs - LogsAddEvent
Ring Games - RingGamesAdd, RingGamesDelete, RingGamesEdit, RingGamesGet, RingGamesList, RingGamesMessage, RingGamesOffline, RingGamesOnline, RingGamesPause, RingGamesResume
System - SystemGet, SystemSet
Tournaments - TournamentsAdd, TournamentsDelete, TournamentsEdit, TournamentsGet, TournamentsList, TournamentsMessage, TournamentsOffline, TournamentsOnline, TournamentsPause, TournamentsResults, TournamentsResume, TournamentsStart, TournamentsUnregister, TournamentsWaiting
Accounts - AccountsAdd, AccountsDecBalance, AccountsDelete, AccountsEdit, AccountsGet, AccountsIncBalance, AccountsList
Blacklist - BlacklistAdd, BlacklistCount, BlacklistDelete, BlacklistEdit, BlacklistGet
Connections - ConnectionsGet, ConnectionsList, ConnectionsMessage, ConnectionsTerminate
Logs - LogsAddEvent
Ring Games - RingGamesAdd, RingGamesDelete, RingGamesEdit, RingGamesGet, RingGamesList, RingGamesMessage, RingGamesOffline, RingGamesOnline, RingGamesPause, RingGamesResume
System - SystemGet, SystemSet
Tournaments - TournamentsAdd, TournamentsDelete, TournamentsEdit, TournamentsGet, TournamentsList, TournamentsMessage, TournamentsOffline, TournamentsOnline, TournamentsPause, TournamentsResults, TournamentsResume, TournamentsStart, TournamentsUnregister, TournamentsWaiting
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Application Programming Interface
This is a PHP include file (API.php) that I will use in the examples to follow for interfacing with the game server. You only need to replace the $url and $pw values with your own URL and API password:
Code: Select all
<?php
$url = "http://192.168.1.100:8087/api";
$pw = "xyz123";
function Poker_API($url,$params)
{
$curl = curl_init($url);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
curl_setopt($curl,CURLOPT_TIMEOUT,10);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
$response = trim(curl_exec($curl));
curl_close($curl);
$api = Array();
if (empty($response))
{
$api[Result] = "Error";
$api[Error] = "Connection failed";
}
else
{
$paramlist = Explode("\r\n",$response);
foreach ($paramlist As $param)
{
$namevalue = Explode("=",$param,2);
$api[$namevalue[0]] = $namevalue[1];
}
}
return $api;
}
?>
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Application Programming Interface
This is a PHP example (ChipLeaders.php) for displaying a "chip leaders" list on a web site:
Code: Select all
<html>
<body>
<?php
include "API.php"; // API $url and $pw values set here
// Fetch the Site Name using the SystemGet API command.
$params = "Password=" . $pw . "&Command=SystemGet&Property=SiteName";
$api = Poker_API($url,$params);
$result = $api["Result"];
if ($result == "Error") die("Error: " . $api["Error"]);
$sitename = $api["Value"];
// Fetch the list of players using the AccountsList API command.
$params = "Password=" . $pw . "&Command=AccountsList&Fields=Player,Balance";
$api = Poker_API($url,$params);
$result = $api["Result"];
if ($result == "Error") die("Error: " . $api["Error"]);
// Iterate through the players in the response and create a associative
// chips array keyed on player name.
$accounts = $api["Accounts"];
$chips = Array();
for ($i = 1; $i <= $accounts; $i++)
{
$player = $api["Player" . $i];
$chips[$player] = $api["Balance" . $i];
}
// Sort array in decending order.
arsort($chips);
// Display results in an html table.
echo "<table border='1' cellpadding='5'>\r\n";
echo "<tr><th colspan='3'>$sitename - Chip Leaders</th></tr>\r\n";
echo "<tr><th>Rank</th><th>Player</th><th>Balance</th></tr>\r\n";
$rank = 0;
$total = 0;
foreach ($chips as $p => $c)
{
$rank++;
$total += $c;
echo "<tr><td>$rank</td><td>$p</td><td>$c</td></tr>\r\n";
}
echo "<tr><td colspan='2'>Total chips</td><td>$total</td></tr>\r\n";
echo "</table><br>\r\n";
?>
</body>
</html>
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Application Programming Interface
This is a PHP example (NewAcct.php) for creating new accounts using a web site interface. It even graphically displays the list of available avatars (set the $avatarurl variable to match your url):
Code: Select all
<html>
<body>
<?php
$avatarurl = "http://192.168.1.100:8087/avatar";
include "API.php";
if (isset($_REQUEST["Submit"]))
{
$Player = $_REQUEST["Player"];
$RealName = $_REQUEST["RealName"];
$Gender = $_REQUEST["Gender"];
$Location = $_REQUEST["Location"];
$Password1 = $_REQUEST["Password1"];
$Password2 = $_REQUEST["Password2"];
$Email = $_REQUEST["Email"];
$Avatar = $_REQUEST["Avatar"];
if ($Password1 <> $Password2) die("Password mismatch. Click Back Button to correct.");
$params = "Password=$pw&Command=AccountsAdd" .
"&Player=" . urlencode($Player) .
"&RealName=" . urlencode($RealName) .
"&PW=" . urlencode($Password1) .
"&Location=" . urlencode($Location) .
"&Email=" . urlencode($Email) .
"&Avatar=" . urlencode($Avatar) .
"&Gender=" . urlencode($Gender) .
"&Chat=" . "Yes" .
"&Note=" . urlencode("Account created via API");
$api = Poker_API($url,$params);
if ($api["Result"] == "Ok") echo "Account successfully created for $Player";
else echo "Error: " . $api["Error"] . "<br>Click Back Button to correct.";
exit;
}
?>
<h3>Create New Account</h3>
<form method="post">
<table>
<tr><td>Your player name:</td><td><input type="text" name="Player" /></td></tr>
<tr><td>Your real name:</td><td><input type="text" name="RealName" /></td></tr>
<tr><td>Your gender:</td><td><input type="radio" name="Gender" Value="Male" checked>Male</input>
<input type="radio" name="Gender" Value="Female">Female</input></td></tr>
<tr><td>Your location:</td><td><input type="text" name="Location" /></td></tr>
<tr><td>Select a password:</td><td><input type="password" name="Password1" /></td></tr>
<tr><td>Confirm password:</td><td><input type="password" name="Password2" /></td></tr>
<tr><td>Your email address:</td><td><input type="text" name="Email" /></td></tr>
<tr><td>Your avatar:</td><td>
<div style="width: 100px; height: 175px; overflow: auto; border: solid 2px">
<?php
for ($i=1; $i<65; $i++)
{
$s = "<input type='radio' name='Avatar' value='$i'";
if ($i == 1) $s .= " checked";
$s .= "><img src='" . $avatarurl . "?Index=$i' align='middle'>";
echo $s . "<br>";
}
?>
</div>
</td></tr>
</table>
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Application Programming Interface
This is a PHP example (AccountsCSV.php) for exporting the player accounts list to a comma-separated-values (CSV) file which can then be imported directly into an spreadsheet application:
Once displayed in your browser, simply do a "File|Save as" from the browser menu and export to a Text file. Or this PHP code could be modified to do that for you.
Code: Select all
<html>
<body>
<?php
include "API.php"; // API $url and $pw values set here
// Fetch the list of players using the AccountsList API command.
$params = "Password=" . $pw . "&Command=AccountsList&Fields=Player,RealName,PW,Gender,Location,Email,Balance,Avatar,Logins,LastReset,FirstLogin,LastLogin,ValCode,Chat,Note";
$api = Poker_API($url,$params);
$result = $api["Result"];
if ($result == "Error") die("Error: " . $api["Error"]);
// iterate through list
echo "<pre>\r\n";
echo '"Player","RealName","Password","Gender","Location","Email","Balance","Avatar","Logins","LastReset","FirstLogin","LastLogin","ValCode","Chat","Note"' . "\r\n";
for ($i=1; $i<=$api["Accounts"]; $i++)
{
echo '"' . $api["Player" .$i] . '",';
echo '"' . $api["RealName" .$i] . '",';
echo '"' . $api["PW" .$i] . '",';
echo '"' . $api["Gender" .$i] . '",';
echo '"' . $api["Location" .$i] . '",';
echo '"' . $api["Email" .$i] . '",';
echo '"' . $api["Balance" .$i] . '",';
echo '"' . $api["Avatar" .$i] . '",';
echo '"' . $api["Logins" .$i] . '",';
echo '"' . $api["LastReset" .$i] . '",';
echo '"' . $api["FirstLogin" .$i] . '",';
echo '"' . $api["LastLogin" .$i] . '",';
echo '"' . $api["ValCode" .$i] . '",';
echo '"' . $api["Chat" .$i] . '",';
echo '"' . $api["Note" .$i] . '"';
echo "\r\n";
}
echo "</pre>\r\n";
?>
</body>
</html>
-
- Posts: 48
- Joined: Sat Jun 21, 2008 3:39 pm
Re: Application Programming Interface
Can the chipleaders board only show the top 10?
Cheers in advance.
Cheers in advance.
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Application Programming Interface
Just break the foreach loop when $rank gets to 10. Full example here:MonTheHoops wrote:Can the chipleaders board only show the top 10?
Code: Select all
<html>
<body>
<?php
include "API.php"; // API $url and $pw values set here
// Fetch the Site Name using the SystemGet API command.
$params = "Password=" . $pw . "&Command=SystemGet&Property=SiteName";
$api = Poker_API($url,$params);
$result = $api["Result"];
if ($result == "Error") die("Error: " . $api["Error"]);
$sitename = $api["Value"];
// Fetch the list of players using the AccountsList API command.
$params = "Password=" . $pw . "&Command=AccountsList&Fields=Player,Balance";
$api = Poker_API($url,$params);
$result = $api["Result"];
if ($result == "Error") die("Error: " . $api["Error"]);
// Iterate through the players in the response and create a associative
// chips array keyed on player name.
$accounts = $api["Accounts"];
$chips = Array();
for ($i = 1; $i <= $accounts; $i++)
{
$player = $api["Player" . $i];
$chips[$player] = $api["Balance" . $i];
}
// Sort array in decending order.
arsort($chips);
// Display results in an html table.
echo "<table border='1' cellpadding='5'>\r\n";
echo "<tr><th colspan='3'>$sitename - Chip Leaders</th></tr>\r\n";
echo "<tr><th>Rank</th><th>Player</th><th>Balance</th></tr>\r\n";
$rank = 0;
foreach ($chips as $p => $c)
{
$rank++;
echo "<tr><td>$rank</td><td>$p</td><td>$c</td></tr>\r\n";
if ($rank == 10) break;
}
echo "</table><br>\r\n";
?>
</body>
</html>
-
- Posts: 25
- Joined: Sat Sep 27, 2008 4:04 pm
Re: Application Programming Interface
I receive the following error:
Fatal error: Call to undefined function curl_init() in C:\Documents and Settings\Administrator\My Documents\www\api.php on line 8
Could you steer me in the right direction to resolving this issue?
Thank you very much.
Fatal error: Call to undefined function curl_init() in C:\Documents and Settings\Administrator\My Documents\www\api.php on line 8
Could you steer me in the right direction to resolving this issue?
Thank you very much.
-
- Site Admin
- Posts: 5880
- Joined: Wed Mar 19, 2008 8:47 pm
Re: Application Programming Interface
You just need to add the free libcurl extension to your PHP configuration. See this thread:hofdiggity wrote:I receive the following error:
Fatal error: Call to undefined function curl_init() in C:\Documents and Settings\Administrator\My Documents\www\api.php on line 8
Could you steer me in the right direction to resolving this issue?
http://www.briggsoft.com/forums/viewtop ... =145&p=575
-
- Posts: 107
- Joined: Wed May 06, 2009 12:59 pm
- Contact:
Re: Application Programming Interface
My PHP is running but when I test the code provided:
http//:playersclub.ca/PMservice/ChipLeaders.php
it returns the following:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Courier New;}{\f1\froman\fcharset0 Times New Roman;}{\f2\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\tx0\tx959\tx1918\tx2877\tx3836\tx4795\tx5754\tx6713\tx7672\tx8631\f0\fs20 \par \pard\sb100\sa100\f1\fs24\par \pard\f2\fs20\par \par }
What have I done wrong?
Thanks,
George
www.playersclub.ca
http//:playersclub.ca/PMservice/ChipLeaders.php
it returns the following:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Courier New;}{\f1\froman\fcharset0 Times New Roman;}{\f2\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\tx0\tx959\tx1918\tx2877\tx3836\tx4795\tx5754\tx6713\tx7672\tx8631\f0\fs20 \par \pard\sb100\sa100\f1\fs24\par \pard\f2\fs20\par \par }
What have I done wrong?
Thanks,
George
www.playersclub.ca