скрипты по типу http://cs-monitoring.ru/

Discussion in 'PHP' started by mixdw, 6 Jun 2009.

  1. mixdw

    mixdw Banned

    Joined:
    27 Mar 2008
    Messages:
    81
    Likes Received:
    30
    Reputations:
    0
    http://cs-monitoring.ru/
    http://control-strike.ru/
    Есть какие-нибудь бесплатные в паблике аналоги данных скриптов?
     
  2. Winst0n

    Winst0n Elder - Старейшина

    Joined:
    19 Aug 2008
    Messages:
    92
    Likes Received:
    5
    Reputations:
    0
    $data=monitor_cs(ip, port, halflife, info);
    echo $data[hostname], $data[mapname], etc...

    Code:
     function monitor_cs($ip, $port, $game, $request)
        {
    		   $fp = @fsockopen("udp://$ip", $port, $errno, $errstr, 1);
    
    			if (!$fp) { return FALSE; } 
    
    			    stream_set_timeout($fp, 1, 0);
    			    stream_set_blocking($fp, true);  
    
    	 if (($request == "settings" || $request == "players"))
    	     {
    	    $challenge_code = "\xFF\xFF\xFF\xFF\x57"; 
    	          fwrite($fp, $challenge_code);
    	         $buffer = fread($fp, 4096);
    	        if (!trim($buffer)) { fclose($fp); return FALSE; }
    			$challenge_code = substr($buffer, 5, 4);
        }
    
    		   if ($request == "info")     { $challenge = "\xFF\xFF\xFF\xFFTSource Engine Query\x00"; }
    		  if ($request == "players")  { $challenge = "\xFF\xFF\xFF\xFFU".$challenge_code;        }
    		        if ($request == "settings") { $challenge = "\xFF\xFF\xFF\xFFV".$challenge_code;        }
    
    
    		     fwrite($fp, $challenge);
    
    		  $buffer = fread($fp, 4096);
    
    		      if (!$buffer) { fclose($fp); return FALSE; }     
    
    		   if ($request == "settings")
    		       {
    		$second_packet = fread($fp, 4096);
    
    		 if (strlen($second_packet) > 0)
    		{
    		 $reverse_check = dechex(ord($buffer[8]));      
    
    		  if ($reverse_check[0] == "1")
    		   {
    		      $tmp           = $buffer;                 
    		         $buffer        = $second_packet;
    		            $second_packet = $tmp;
    		      }
    
    		$buffer        = substr($buffer, 13);         
    		 $second_packet = substr($second_packet, 9);   
    		  $buffer        = trim($buffer.$second_packet);
    		 }
    		    else
    		   {
    		    $buffer = trim(substr($buffer, 4)); 
    		   }
    		}
    		    else
    		 {
    		       $buffer = trim(substr($buffer, 4)); 
    		    }
    
    		        fclose($fp);
    
    		     if (!trim($buffer)) { return FALSE; }
    		     //---------------------------------------------------------+
    		   if ($request == "info")
    		{
    
    		   unset($data);
    
    		  $tmp = explode("\x00", $buffer);
    
    		 $place = strlen($tmp[0].$tmp[1].$tmp[2].$tmp[3].$tmp[4]) + 5;
    		$data['gamemod']        = $tmp[3];
    		      $data['hostname']       = $tmp[1];
    		     $data['mapname']        = $tmp[2];
    		    $data['players']        = ord($buffer[$place]);
    		   $data['maxplayers']     = ord($buffer[$place + 1]);
    		         $data['password']       = ord($buffer[$place + 5]);
    				 $data['cs_players']	=	$cs_players;
    		  //--- NONSTANDARD INFORMATION ----------------------------+
    		      $data['datatype']       = $buffer[0];               // m for steam info
    		      $data['version']        = ord($buffer[$place + 2]); // Network Version
    		      $data['description']    = $tmp[4];
    		      $data['server_type']    = $buffer[$place + 3];      // D edicated or L isten
    			  $data['server_os']      = $buffer[$place + 4];      // W indows or L inux
    			  $data['server_secure']  = ord($tmp[14]);            // VAC
    			  $data['server_bots']    = ord($tmp[15]);            // Number of Bots
    			  $data['ip']     		 = $ip;
    			  $data['port']     		= $port;
    					      //--------------------------------------------------------+
    					            return $data;  
    						        }
    							//---------------------------------------------------------+
    							    if ($request == "players")
    							        {
    
    									          $player_number = 0;
    										        $position = 2;                                          
    
    		do
    		      {
    		       $player_number++;                                      
    
    		        $player[$player_number]['id'] = ord($buffer[$position]);
    		         $position ++;                                             
    
    		          while($buffer[$position] != "\x00" && $position < 4000)   
    		           {
    		              $player[$player_number]['name'] .= $buffer[$position];  
    			                $position ++;
    					        }
    						        $player[$player_number]['score'] = (ord($buffer[$position + 1]))
    							                                         + (ord($buffer[$position + 2]) * 256)
    		                     + (ord($buffer[$position + 3]) * 65536)
    		                           + (ord($buffer[$position + 4]) * 16777216);
    
    		if ($player[$player_number]['score'] > 2147483648) { $player[$player_number]['score'] -= 4294967296; }  
    
    		 $time = substr($buffer, $position + 5, 4);               
    		  if (strlen($time) < 4) { return FALSE; }               
    		   list(,$time) = unpack("f", $time);                
    		    $time = mktime(0, 0, $time);                          
    		     $player[$player_number]['time'] = date("H:i:s", $time);  
    
    		      $position += 9;
    		     }
    		    while ($position < strlen($buffer));                   
    		          return $player;
    		       }
    		//---------------------------------------------------------+
    		    if ($request == "settings")
    		        {
    
    			           $tmp     = substr($buffer, 2); 
    				         $rawdata = explode("\x00", $tmp);
    
    		for($i=1; $i<count($rawdata); $i=$i+2)
    		      {
    		       $rawdata[$i] = strtolower($rawdata[$i]);  
    		        $setting[$rawdata[$i]] = $rawdata[$i+1];  
    		       }
    
    		      return $setting; 
    		   }
     }
    
    а дальше сам ))
    не думаю что найдешь :rolleyes:
     
    1 person likes this.
  3. Player#1

    Player#1 Member

    Joined:
    11 Nov 2008
    Messages:
    95
    Likes Received:
    35
    Reputations:
    10
    Вот отличный рабочий скрипт.
    Могу помочь поставить его на сайт, пиши в личку...

    Code:
    <?php
    if(!function_exists('getmicrotime'))
    {
    	function getmicrotime() 
    	{ 
    		list($usec, $sec) = explode(" ", microtime()); 
    		return ((float)$usec + (float)$sec); 
    	}
    }
    
    $ip="217.170.80.4";
    $port="27015";
    
    	$ip = gethostbyname($ip);
    	$timeStart = getmicrotime();
    	$fp = fsockopen('udp://'.$ip, $port) or die("ERROR!!!");
    	stream_set_timeout($fp, 2); 
    	if($fp) 
    	{ 
    		fwrite($fp,"\xFF\xFF\xFF\xFFTSource Engine Query\0\r");
    		$temp = fread($fp, 4);
    		$status = socket_get_status($fp); 
    		if($status['unread_bytes']>0) 
    		{
    			$temp = fread($fp, $status['unread_bytes']);
    			$server['ping'] = (int)((getmicrotime() - $timeStart)*1000);
    			$array = array(); 
    			$pos = 0; 
    			while($pos !== false) 
    			{ 
    				$pos2 = strpos($temp, "\0", $pos+1); 
    				$array[] = substr($temp, $pos+1, $pos2-$pos)."\n"; 
    				$pos = $pos2; 
    			}
    			$server['status'] = 'on';
    			if( strpos($array[0], $ip) !== 0) 
    			{ 
    				$server['players'] = ord($array[5][0]); 
    				$server['maxplayers'] = ord($array[5][1]); 
    				$server['name'] = trim(substr($array[0], 1)); 
    				$server['map'] = trim($array[1]); 
    				$server['game'] = trim($array[2]);
    			} 
    			else 
    			{ 
    				$server['players'] = ord($array[5][0]); 
    				$server['maxplayers'] = ord($array[5][1]); 
    				$server['name'] = trim($array[1]); 
    				$server['map'] = trim($array[2]);
    				$server['game'] = trim($array[3]);
    			}
    			$command = pack("V", -1) . 'W';
    			fwrite($fp, $command, strlen($command));
    			$temp = fread($fp, 1500);
    			$temp = substr($temp, 5);
    			$lo = (ord($temp[1]) << 8) | ord($temp[0]);
    			$hi = (ord($temp[3]) << 8) | ord($temp[2]);
    			$data = "\xFF\xFF\xFF\xFF\x55".pack("V", ($hi << 16) | $lo);
    			fwrite($fp, $data);
    			$temp = fread($fp, 5);
    			$status = socket_get_status($fp);
    			if($status['unread_bytes']>0) 
    			{
    				$temp = fread($fp, $status['unread_bytes']);
    				
    				$array = array();
    				$temp = substr($temp, 1);
    				for($i=1;$i<=$server['players'];$i++)
    				{
    					$temp = substr($temp, 1);
    					$pos = strpos($temp, "\0");
    					$name = substr($temp, 0, $pos);
    					$temp = substr($temp, $pos+1);
    					$lo = (ord($temp[1]) << 8) | ord($temp[0]);
    					$hi = (ord($temp[2]) << 8) | ord($temp[3]);
    					$temp = substr($temp, 4);
    					$kills = ($hi << 16) | $lo;
    					$f = @unpack("f1float", $temp);
    					$temp = substr($temp, 4);
    					$time = (int)$f['float'];
    					if(trim($name))
    						$server['stats'][] = array("name" => $name, "kills" => 
    
    $kills,
    												   "time" => 
    
    gmdate("H:i:s", $time));
    				}
    			}
    		}
    		else
    			$server['status'] = 'off';
    	}
    echo "<pre>";
    print_r($server);
    echo "</pre>";
    
    
    
    ?>
     
    5 people like this.
  4. mixdw

    mixdw Banned

    Joined:
    27 Mar 2008
    Messages:
    81
    Likes Received:
    30
    Reputations:
    0
    Спасибо конечно,но такие маленькие скрипты у меня есть.
    Лучше я уже поспользуюсь Phgstats если на то пошло.
     
  5. gLuk!

    gLuk! New Member

    Joined:
    27 Mar 2009
    Messages:
    27
    Likes Received:
    0
    Reputations:
    0
    юзай lgsl, туда вполне реально прикрутить голосовалку да vip серваки... хотя это извращение)
    лучше купи у кого-нить.
     
Loading...