Page 1 of 1

Return Logged-in Players

Posted: Wed Jan 20, 2010 12:55 pm
by khaznadar
Hey guys,
I've made a small script to show in a table all the players but I can't figure out how to add a field to check whether the player is currently logged on or not, any help??..here's my code:

Code: Select all

   // API $url and $pw values set here
include "api.php" $fields="Player,Title,Level,RealName,PW,Location,Email,Balance,RingChips,LastReset,Avatar,Logins,FirstLogin,LastLogin,Gender";

  $params = "Password=" . $pw . "&Command=AccountsList&Fields=".$fields;
  $api = Poker_API($url,$params,true);
  $result = $api["Result"];
  if ($result == "Error") die("Error: " . $api["Error"]);
  


  // Display results in an html table.
?>
<table width="100%">
	<thead>
		<tr>
            <th width="40px"><a href="#">ID<img src="img/icons/arrow_down_mini.gif" width="16" height="16" align="absmiddle" /></a></th>
            <th><a href="#">Player</a></th>
            <th><a href="#">Real Name</a></th>
            <th><a href="#">Balance</a></th>
            <th><a href="#">Email</a></th>
            <th><a href="#">Logins</a></th> 	    
            <th><a href="#">Last Login</a></th>
            <th>Logged-in</th>
         </tr>
	</thead>
<?php  
  $accounts = $api["Accounts"];
  for ($i = 1; $i <= $accounts; $i++)
  {
    $player = $api["Player" . $i];
    $chips = number_format($api["Balance" . $i]);
    $realname=$api["RealName" . $i];
    $email=$api["Email".$i];
    $logins=$api["Logins".$i];
    $lastlogin=$api["LastLogin".$i];
    $islog=isLogged($player);
    echo "<tr><td class='a-center'>$i</td><td><a href='poker\player_edit.php?player=$player' class='thickbox'>$player</a></td><td>$realname</td><td>$chips</td><td>$email</td><td>$logins</td><td>$lastlogin</td><td>$islog</td></tr>\r\n";
  }
  
  echo "</tbody></table><br>\r\n";
  function isLogged($player){
       $params = "Password=$pw&Command=ConnectionsList&Fields=Player";
      $api2 = Poker_API($url,$params,true);
      $found = false; 
      $connections = $api2["Connections"];
      for ($i = 1; $i <= $connections; $i++)        
      {
        if (strcasecmp($player,$api2["Player" . $i])==0)
        {
          $found=true;
        }

      }
	  return $found;
	}
?>

Re: Return Logged-in Players

Posted: Wed Jan 20, 2010 8:24 pm
by Kent Briggs
khaznadar wrote:Hey guys,
I've made a small script to show in a table all the players but I can't figure out how to add a field to check whether the player is currently logged on or not, any help??
I haven't tried your code but I see you have a function in there checking if a player is logged in. Is that not working? What does it display?

Re: Return Logged-in Players

Posted: Thu Jan 21, 2010 3:53 am
by khaznadar
Hey Kent,
I've tried the code but it doesn't work it only displays the players and their corresponding fields, but concerning the Logged-in in Connections, it returns nothing, i've tried to return the Boolean function inside the For and outside it, it's the same, nothing at all. If you already have made similar function or code, can you please send it to me or post here. I've noticed that in your Online Admin there's something similar "In" if the user is logged in it says "YES" and if "NO" if not.

Thank You

Re: Return Logged-in Players

Posted: Thu Jan 21, 2010 6:01 am
by khaznadar
Hey, Kent
I think I've fixed this problem and I will share it ;)

Code: Select all

<?php

    // Set whatever fields you want
  $fields="Player,Title,Level,RealName,PW,Location,Email,Balance,RingChips,LastReset,Avatar,Logins,FirstLogin,LastLogin,Gender";

  $params = "Password=" . $pw . "&Command=AccountsList&Fields=".$fields;
  $api = Poker_API($url,$params,true);
  $result = $api["Result"];
  if ($result == "Error") die("Error: " . $api["Error"]);
  


  // Display results in an html table.
?>
<table width="100%">
	<thead>
		<tr>
            <th width="40px"><a href="#">ID<img src="img/icons/arrow_down_mini.gif" width="16" height="16" align="absmiddle" /></a></th>
            <th><a href="#">Player</a></th>
            <th><a href="#">Real Name</a></th>
            <th><a href="#">Balance</a></th>
            <th><a href="#">Email</a></th>
            <th><a href="#">Logins</a></th> 	    
            <th><a href="#">Last Login</a></th>
            <th>Logged-in</th>
         </tr>
	</thead>
<?php  
  $accounts = $api["Accounts"];
  // Connections
  for ($i = 1; $i <= $accounts; $i++)
  {
    $player = $api["Player" . $i];
    $chips = "$ ".number_format($api["Balance" . $i]);
    $realname=$api["RealName" . $i];
    $email=$api["Email".$i];
    $logins=$api["Logins".$i];
    $lastlogin=$api["LastLogin".$i];
    
  //Get Currently Logged In
    $params2 = "Password=$pw&Command=ConnectionsList&Fields=Player";
  	$api2 = Poker_API($url,$params2,true);
    $connections = $api2["Connections"];
    $found=0;
    for($j=1;$j<=$connections;$j++){
	    if($api2["Player".$j]==$player){
		     $found=1;
	    }
 	}
 // End of Get Currently Logged in
    echo "<tr><td class='a-center'>$i</td><td><a href='poker\player_edit.php?player=$player' class='thickbox'>$player</a></td><td>$realname</td><td>$chips</td><td>$email</td><td>$logins</td><td>$lastlogin</td><td>$found</td></tr>\r\n"; 
  }
  echo "</tbody></table><br>\r\n";

?>

Re: Return Logged-in Players

Posted: Thu Jan 21, 2010 10:01 am
by Kent Briggs
khaznadar wrote:If you already have made similar function or code, can you please send it to me or post here.
The "Player Search" routine on the API examples page shows the login status:

http://www.briggsoft.com/docs/pmavens/A ... yer_search