AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Checking if VAC is working (https://forums.alliedmods.net/showthread.php?t=26780)

MaximusBrood 04-09-2006 06:32

Checking if VAC is working
 
I want to catch if VAC is working with a plugin, so I can shutdown server, (and let serverdoc restart it) to make VAC work again.

Anybody knows how to do it?

MaximusBrood 04-10-2006 13:53

Any Idea?

wouter 04-10-2006 13:58

well it stands in HLSW so i guess its a cvar?
Code:

secure "1"

KoST 04-10-2006 15:07

i wrote this php script to query my server via rcon, and modified it a bit:

its output:
"SERVER SECURE !!"
or
"SERVER NOT SECURE !!"

just enter the ip and port of the server you want to query below:
Code:

<?php
        // set the ip and port of server:
  define (RCON_PORT,27015); // server port
  define (RCON_IP,"111.222.333.444"); // server ip
        //-------------------------------------------------------------------------------
 
  define (A2S_SERVERQUERY_GETCHALLENGE,toStream(array(0xFF,0xFF,0xFF,0xFF,0x57)));
  define (A2S_INFO,toStream(array(0xFF,
  0xFF,0xFF,0xFF,0x54,0x53,0x6F,0x75,0x72,0x63,0x65,0x20,0x45,
  0x6E,0x67,0x69,0x6E,0x65,0x20,0x51,0x75,0x65,0x72,0x79,0x00)));
  define (A2S_PLAYER,toStream(array(0xFF,0xFF,0xFF,0xFF,0x55)));
  define (A2S_RULES,toStream(array(0xFF,0xFF,0xFF,0xFF,0x56)));

  $info=array(); 
  $players=array();

  $raw=QueryServer(A2S_SERVERQUERY_GETCHALLENGE);
  $raw=QueryServer(A2S_INFO);
  $raw=QueryServer(A2S_PLAYER.$info['challenge']);
  $raw=QueryServer(A2S_RULES.$info['challenge']);
 
  //print_r($info);                 
  if ($info["Secure"]==1){
          echo "SERVER SECURE !!";
  }else{
              echo "SERVER NOT SECURE !!";
  }




 
  function Rcon($command){
      return trim(QueryServer(toStream(array(0xFF,0xFF,0xFF,0xFF)).$command,true));
  }
 
  function QueryServer($request,$isRconCommand=false){
      global $players,$info;
      $fp = fsockopen("udp://".RCON_IP,RCON_PORT, $errno, $errstr);
      if (!$fp) {
      echo "Fehler: $errno - $errstr
\n";
        return false; 
      } else {
        fwrite($fp,$request);
        $result=fread($fp, 100000);
        fclose($fp);

        $type=substr($result,4,1);
       
        $result=substr($result,5);
        if ($isRconCommand){
            //echo "[RCON]->".$result;
            return $result;
            switch ($type){
           
            }
        }


            switch ($type){
              case 'A':
                  //echo "challenge number:".$result[0]+$result[0]*256+$result[0]*256*256+$result[0]*256*256*256;
                  $info['challenge']=$result;
              break;
              case 'm':

                  $info['ip']=GetResultVal($result,'string');
                  $info['hostname']=GetResultVal($result,'string');
                  $info['map']=GetResultVal($result,'string');
                  $info['game']=GetResultVal($result,'string');
                  $info['description']=GetResultVal($result,'string');
 
                  $info['numPlayers']=GetResultVal($result);
                  $info['maxPlayers']=GetResultVal($result);
                  $info['version']=GetResultVal($result);
                  if (GetResultVal($result)==ord('d')){
                    $info['dedicated']=true;
                  }else{
                    $info['dedicated']=false;
                  }
                  if (GetResultVal($result)==ord('l')){
                    $info['os']='Linux';
                  }else{
                    $info['os']='Windows';
                  }
                  if (GetResultVal($result)==1){
                    $info['pwd']=true;
                  }else{
                    $info['pwd']=false;
                  }
                  if (GetResultVal($result)==1){
                    $info['IsMod']=true;
                  }else{
                    $info['IsMod']=false;
                  }
                 
 
                  $info['URLInfo']=GetResultVal($result,'string');
                  $info['URLDL']=GetResultVal($result,'string');
                  $info['Unused']=GetResultVal($result,'string');
                  $info['ModVersion1']=GetResultVal($result);
                  $info['ModVersion2']=GetResultVal($result);
                  $info['ModVersion3']=GetResultVal($result);
                  $info['ModVersion4']=GetResultVal($result);
                  $info['ModSize1']=GetResultVal($result);
                  $info['ModSize2']=GetResultVal($result);
                  $info['ModSize3']=GetResultVal($result);
                  $info['ModSize4']=GetResultVal($result);
                 
                  $info['SvOnly']=GetResultVal($result);
 
 
 
                  $info['ClDLL']=GetResultVal($result); 
 
                  $info['Secure']=GetResultVal($result);
                  $info['numBots']=GetResultVal($result);
                  $info['realPlayers']=$info['numPlayers']-$info['numBots'];
 
     
 
              break;
 
              case 'D':
                  $n=GetResultVal($result);
                  if ($n!=$info['numPlayers']){
                    echo "sombody joining...";
                  }
                  $players=array();
                  for ($s=0;$s<$n;$s++){
                    $index=GetResultVal($result);
                    $cur=&$players[$index];
                    $cur['name']=GetResultVal($result,'string');
                    $cur['frags']=GetResultVal($result);
                    $frags=GetResultVal($result);
                    $frags=GetResultVal($result);
                    $frags=GetResultVal($result);
 
                    $time=GetResultVal($result);
                    $time=GetResultVal($result);
                    $time=GetResultVal($result);
                    $time=GetResultVal($result);
                  }
              break;
 
              case 'y':
                  //echo "LKJ";
                  $val1=GetResultVal($result);
                  $val1=GetResultVal($result);
                  $n=$val1+$val2*256;
                  for ($s=0;$s>$n;$s++){
                    echo "rule: ".GetResult($result,'string')."
";
                    echo " val: ".GetResult($result,'string')."
";
                  }
              break;
             
              default:
                  //echo "TAPE: ".$type;
              break;
            }
        return true;
      }

      return false; 
  }

  function toStream($arr){
      $tmp="";
      foreach ($arr as $val){
        $tmp.=chr($val);
      }
      return $tmp;
  }


  function GetResultVal(&$result,$mode='byte'){
      if ($mode=='byte'){
        $tmp=ord(substr($result,0,1));
        $result=substr($result,1);
        return $tmp;
      } else if ($mode=='string'){
        $a=explode(chr(0),$result,2);
        $result=$a[1];
        return $a[0];
      }
  }   
 
?>


MaximusBrood 04-10-2006 15:29

Allright, I'll edit the script to only check for secure mode, and when it finds the server insecure, it will connect to server with rcon and shut it down.

---

Only one question left, how to launch the script every minute or so?
If that isn't possible, I can always make a link in my server's motd to the script, but that isn't very neat :wink:

KoST 04-10-2006 16:40

here is the stuff you will need to use rcon password/challenge:

this example executes the 'status' command:
Code:

  $rcon_challenge=substr(Rcon('challenge rcon'),14);
  echo Rcon('rcon '.$rcon_challenge.' "'.RCON_PASSWORD.'" status');

let me know if you got it working.. or if there are further problems..

MaximusBrood 04-10-2006 16:45

I know my PHP, but thanks :)

KoST 04-10-2006 16:48

thats how we like it ! :up:

Twilight Suzuka 04-10-2006 19:20

This would be soooo much easier with an AMXx plugin.

Check to see if secure == 1
if it does, return, if not, shutdown.

DONE.

MaximusBrood 04-11-2006 02:54

Quote:

Originally Posted by Twilight Suzuka
This would be soooo much easier with an AMXx plugin.

Check to see if secure == 1
if it does, return, if not, shutdown.

DONE.

Now you tell me how to do that, since there is no cvar whatsoever that can tell if VAC is on or off.
And no, 'sv_secure' and 'secure' don't work


All times are GMT -4. The time now is 16:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.