21.12.2016, 14:26
Hi,
How in php file, check if speficic player is joined to my server?
How in php file, check if speficic player is joined to my server?
Hi,
How in php file, check if speficic player is joined to my server? |
<?php
$sIP = "localhost";//server IP
$sPORT = 7777;//server Port
require "SampQueryAPIxx.php";
$query = new SampQueryAPI($sIP, $sPORT);
$sInfo = $query->getInfo();
if(!$query->isOnline()) { echo "Server Offline"; exit; }
echo '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';
$aPlayers = $query->getDetailedPlayers();
if(!is_array($aPlayers) || count($aPlayers) == 0)
{
echo "<br /><i>well, either something went wrong or there are no players</i>";
}
else
{
?>
<style type="text/css">
thead
{
background-image: url("head.jpg");
}
table
{
margin:35;
border:1px solid #CCC;
border-collapse:collapse;
}
tr.bottom
{
background-image: url("head.jpg");
}
font
{
opacity: 0.0;
font-family:Roman;
color:#cccccc;
}
font.exception
{
opacity: 100.0;
}
p
{
font-family:Arial;
}
td
{
font-family:Verdana;
}
.highlight
{
background-image: url("row.png");
}
.normal
{
background-image: none;
}
.unselectable
{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
user-select: none;
}
</style>
<center>
<p><?= $sInfo['hostname']; ?></p>
<table width="300" name="board" class="unselectable">
<thead class="head">
<td><b>ID</b></td>
<td align=middle><b>Name</b></td>
<td><b>Score</b></td>
<td><b>Ping</b></td>
</thead>
<?php
foreach($aPlayers as $sValue)
{
?>
<tr OnMouseOver="this.className='highlight'" OnMouseOut="this.className='normal'">
<td><?= $sValue['playerid'] ?></td>
<td><?= htmlentities($sValue['nickname']) ?></td>
<td><?= $sValue['score'] ?></td>
<td align=right><?= $sValue['ping'] ?></td>
</tr>
<?php
}
echo '<tr class="bottom"><td><font>.</font></td><td align=right><font class="exception">Autor: East_Crips</font></td><td><font>.</font></td><td><font>.</font></td></tr>';
echo '</table></center>';
}
?>
<!--
East_Crips 2011
!-->
<?php
echo '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';
$sIP = "127.0.0.1";//server IP
$sPORT = 7777;//server Port
require "SampQueryAPIxx.php";
$query = new SampQueryAPI($sIP, $sPORT);
if(!$query->isOnline()) { echo "Server Offline"; exit; }
$aPlayers = $query->getDetailedPlayers();
$idx = array_search($_GET['target'],array_column($aPlayers,'nickname'));
if($idx !== false)
echo $aPlayers[$idx]['nickname']." is online.";
else
echo $_GET['target']." is offline!";
?>
<!--
East_Crips 2016
!-->
#include <a_samp>
#include <a_http>
#include <YSI\y_commands>
main(){}
forward isPlayerOnline(pId, response, content[]);
YCMD:online(playerid, params[], help)
{
if(help) return SendClientMessage(playerid, -1, "USAGE: /online [Player-Name]");
if(isnull(params)) return SendClientMessage(playerid, -1, "/online [Player-Name] MISSING Player-Name");
printf("its %s",params[0]);
new target[24+7];
format(target, sizeof target, "target=%s",params[0]);
HTTP(playerid, HTTP_POST, "localhost/php/samp/Pdisplay/ison.php", target, "isPlayerOnline");
return 1;
}
public isPlayerOnline(pId, response, content[])
{
new buff[128];
if(response == 200)//OK
{
if(content[0] == '1')
SendClientMessage(pId, -1, "that player is online.");
else
SendClientMessage(pId, -1, "that player it offline!");
}
else//anything else not OK
{
format(buff, sizeof buff,"ERROR %d",response);
SendClientMessage(pId, -1, buff);
}
}
<?php
$sIP = "127.0.0.1";//server IP
$sPORT = 7777;//server Port
require "SampQueryAPIxx.php";
$query = new SampQueryAPI($sIP, $sPORT);
if(!$query->isOnline()) { echo "Server Offline"; exit; }
$aPlayers = $query->getDetailedPlayers();
$idx = array_search($_POST['target'],array_column($aPlayers,'nickname'));
echo ($idx === false)?0:1;
?>