felixms / arma-rcon-class-php

A lightweight client for sending commands easily to a BattlEye server.
MIT License
46 stars 22 forks source link

Unable to ignore/catch login error. #36

Closed kobadg closed 5 years ago

kobadg commented 5 years ago

I have a few servers that I am checking against, and getting the number of players for. However if the rcon or server isn't on, I get an exception when trying to connect (line 199 in the arc.php file). The exception is great, except when I try to surround it in a try/catch block... it's acting as if the try/catch is ignored completely? Or maybe I'm just not understanding it... but hopefully I can get some help.

Below is the offending area. I have a list of servers that have rcon credentials, and I am getting this single piece of info from each.

foreach($serverInfoArray as $key => $value){
    try {
        $rcon = new Arc($value['game_ip'], $value['rcon_password'], $value['rcon_port']); //If the server is off, this throws the exception, but then never hits the catch block?
        $serverInfoArray[$key]['players_online'] = count($rcon->getPlayersArray());
        unset($serverInfoArray[$key]['rcon_password']);
        unset($serverInfoArray[$key]['rcon_port']);
    } catch (Exception $e) {
        echo $e->getMessage(); //This never happens.
    }
}
steffalon commented 5 years ago

Hi @kobadg,

Maybe this will help. We use \Exception class.

felixms commented 5 years ago

Issue closed because of inactivity.