Secret Experience

Secret Experience (https://secretexperience.net/)
-   [L2OFF | Admin] Web Sites (https://secretexperience.net/l2off-admin-web-sites/)
-   -   [Web Site] Script Server Status: ON | OFF - Quantidade de Players ON e Record de Players ON (https://secretexperience.net/l2off-admin-web-sites/34079-script-server-status-off-quantidade-de-players-e-record-de-players.html)

Setokaiba 12-08-2013 10:23 PM

Script Server Status: ON | OFF - Quantidade de Players ON e Record de Players ON
 
Esse script se resume em mostrar o status do servidor, quantos player encontram-se online no mesmo, e o recorde de players que já estiveram online em tal servidor.

Código:

<?php
class ServerStatus
{
  private $ip, $port, $interval, $timeout;

  public function __construct($ip = '127.0.0.1', $port = 2106, $interval = 30, $timeout = 1)
  {
      $this->ip = $ip;
      $this->port = $port;
      $this->interval = $interval;
      $this->timeout = $timeout;
  }

  public function GetStatusFromAuth()
  {
      $status = array();
      $f = @fsockopen($this->ip, $this->port, $errno, $errstr, $this->timeout);
      if ($f)
      {
        do
        {
            $sec = floor($this->timeout);
            $msec = ($this->timeout - $sec) * 1000;
            socket_set_timeout($f, $sec, $msec);

            $buf = fread($f, 2);
            if (strlen($buf) != 2) break;
            $a = unpack('vsize', $buf);
            $size = $a['size'] - 2;
            if ($size < 1) break;

            $buf = fread($f, $size);
            if (strlen($buf) != $size) break;

            fwrite($f, "\x03\x00\xFE", 3);

            $buf = fread($f, 2);
            if (strlen($buf) != 2) break;
            $a = unpack('vsize', $buf);
            $size = $a['size'] - 2;
            if ($size < 1) break;

            $buf = fread($f, $size);
            if (strlen($buf) != $size) break;

            if (ord($buf[0]) != 0xFE) break;
            if (strlen($buf) < 3) break;
            $amount = ord($buf[1]) + ord($buf[2]) * 256;
            $buf = substr($buf, 3);
            if (strlen($buf) != $amount * 4) break;
            $a = unpack('v' . ($amount * 2), $buf);
            for ($i = 0; $i < $amount; $i++) $status[$a[$i * 2 + 1]] = $a[$i * 2 + 2];
        }
        while (false);
        fclose ($f);
      }
      return $status;
  }

  public function GetStatus()
  {
      $fn = dirname(__FILE__) . '/status.txt';
      $status = array();
      fclose(fopen($fn, 'a+b'));
      $f = @fopen($fn, 'r+b');
      if ($f)
      {
        flock($f, LOCK_EX);
        $cache = unserialize(fread($f, 1024));
        $status = @$cache['status'];
        $time = @$cache['time'];
        if (!IsSet($status) || !IsSet($time))
        {
            $status = array();
            $time = 0;
        }
        if (time() - $time > $this->interval)
        {
            $new = $this->GetStatusFromAuth();
            foreach ($status as $id => $value)
            {
              $c = &$status[$id];
              $c['on'] = false;
              $c['cur'] = 0;
            }
            foreach ($new as $id => $value)
            {
              if (!IsSet($status[$id])) $status[$id] = array('on' => false, 'cur' => 0, 'max' => 0);
              $c = &$status[$id];
              $c['on'] = true;
              $c['cur'] = $new[$id];
              if ($c['cur'] > $c['max']) $c['max'] = $c['cur'];
            }
            $cache = array('status' => $status, 'time' => time());
            $s = serialize($cache);
            rewind($f);
            ftruncate($f, 0);
            fwrite($f, $s, strlen($s));
        }
        fclose($f);
      }
      return $status;
  }

  public function GetText($id, $online, $offline)
  {
      $status = $this->GetStatus();
      if (IsSet($status[$id])) $c = &$status[$id]; else $c = array('on' => false, 'cur' => 0, 'max' => 0);
      $res = str_replace(array('%c', '%m'), array($c['cur'], $c['max']), $c['on'] ? $online : $offline);
      return $res;
  }
}

$status = new ServerStatus('127.0.0.1');
$online = 'Status: <b><font color="#00AA00">ONLINE</font></b> | Players: <b>%c</b> | Record: <b>%m</b>';
$offline = 'Status: <b><font color="#FF0000">OFFLINE</font></b> | Players: <b>%c</b> | Record: <b>%m</b>';
echo $status->GetText(1, $online, $offline); //1 - ServerID
?>


daniel000 12-12-2013 02:33 AM

onde coloca as config do mssql ?

Setokaiba 12-12-2013 04:51 AM

Defina aqui o seu arquivo de class:
Código:

<?php
class ServerStatus
{

Exemplo:
Código:

<?php

require_once('functions.php');
require_once('settings.php');

Onde functions.php poderia ser:
Código:

<?php

function mssql_ex() {
        global $CONFIG;
        $mssql = mssql_connect($CONFIG['mssql_host'],$CONFIG['mssql_user'],$CONFIG['mssql_pass']) or die ('Unable to connect to server.');
        $select = mssql_select_db($CONFIG['mssql_db'], $mssql) or die ('Unable to select database.');
}

?>

E settings.php poderia ser:
Código:

<?php

global $CONFIG;

// MSQL
$CONFIG['mssql_host'] = 'hostname';
$CONFIG['mssql_user'] = 'username';
$CONFIG['mssql_pass'] = 'password';
$CONFIG['mssql_db'] = 'lin2db';

// SCRIPT REFRESH TIME
$CONFIG['refresh_time'] = 300;        // default: 300 (seconds)

?>


isacasj91 12-12-2013 12:40 PM

Voce tem apenas o codigo da quantidade de players ON?

Setokaiba 12-12-2013 02:42 PM

Visite a área:
[Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]

[Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]


Horários baseados na GMT -3. Agora são 03:22 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0