Coder Social home page Coder Social logo

felixms / arma-rcon-class-php Goto Github PK

View Code? Open in Web Editor NEW
46.0 11.0 22.0 112 KB

A lightweight client for sending commands easily to a BattlEye server.

License: MIT License

PHP 100.00%
battleye client rcon php php-library battleye-server battleye-commands composer api socket

arma-rcon-class-php's People

Contributors

cat24max avatar felixms avatar nerdalertdk avatar rexeh avatar scsmncao avatar steffalon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arma-rcon-class-php's Issues

Can't connect. Always get Login error

If I establish a connection as in the readme, I only get the error: "Ups! Something went wrong: Login failed, wrong password or wrong port!"
Although the port and password must be correct.
I already tested the whole RCON connection with the BattleEye "BERCon" client for Windows. There I have no connection problems, everything works. I only get the error here.

Tested Code:

use \Nizarii\ARC;

require_once "app/arc.php";

try {
    $rcon = new ARC('IP', 'Password', 2309);

    $array = $rcon->getPlayersArray();

    $rcon
        ->sayGlobal('example')
        ->kickPlayer(1, 'example')
        ->sayPlayer(0, 'example')
        ->disconnect()
    ;

    $rcon->getBans();
} catch (Exception $e) {
    echo "Ups! Something went wrong: {$e->getMessage()}";
}

Would be nice if you can help me :)

Optimization? Avoid RCON connection spam

I've started playing around with your class in my project. It is working fine for me. But I don't know if there is a smarter to do what I'm doing.

I have created some sort of profile for each player on the server where I can see if they're online on the server by sending a call to the RCON. However I create a new connection every single time meaning that every single time a players profile is accessed it would create a new connection to the RCON. I was wondering if there is any way for me to run something that keeps the connection alive that I then can tell my controllers to use instead of establishing a new connection all the time.

I've seen the socket functions mentioned in the readme. However I'm unsure if those can be used to implement the functionality I'm looking for.

In the end I just wanna avoid spamming the servers RCON with connections if I can keep it to one.

try and catch no error?

Im using Laravel, I have the following code, comming from a form, there comes no error if the connection is 100% wrong.

      if ( $rcon ) {
        try {
          $rconconnection = new ARC($rconhost, $rconpass, $rconport);
          $rconconnection
                      ->sayGlobal('VitControl: Connection successful!')
                      ->disconnect()
          ;
        } catch (Exception $e) {
          $exception = $e->getMessage();

          return \Redirect::route('addServerForm')
            ->with('message', $exception);
        }
        return \Redirect::route('addServerForm')
            ->with('message', 'Server registered!');
      } else {
      return \Redirect::route('addServerForm')
        ->with('message', 'Server registered!');
      }

    }

Fatal error: Uncaught Exception: Wrong constructor parameter type(s)!

Hallo,

ich hab echt lange Probiert.
Egal welche Zugänge ich eingebe, er gibt mir jedesmal die Fehlermeldung:

Fatal error: Uncaught Exception: Wrong constructor parameter type(s)!

$rcon = new ARC('12.123.123.12', 'Passwort', '2903'); $array = $rcon->getPlayersArray(); debug($array);

Wenn ich allerdings die Zugangsdaten mit einem RCON Programm von 2014 öffne, kann ich mich direkt verbinden! Ist die Version mittlerweile zu alt?

LG Max

Chat

Is there anyway to get chat? Would that be possible?

Web console help

Guten Tag Felix,
erstmal danke das du eine so schöne API hier hast
aber kommen wir mal zum wichtigen ich würde gerne eine Web Rcon Console machen
könntest du mir evt. sagen wie es geht ich bin via Discord erreichbar Blxcky | Fabian#4724
danke :D

getPlayersArray / getBansArray

Nizarii commented 3 days ago

Mir ist bis jetzt nichts Ungewöhnliches aufgefallen, bis auf https://github.com/Nizarii/arma-rcon-class-php/blob/master/arc.php#L532. Kannst bitte mal die Funktion formatList durch diese hier ersetzten? Vielen Dank schon mal im voraus! 👍

Ich habe das selbe Problem, dass offenbar schon geklärt wurde.
Leider ist der "diese hier" Github Link von dir nicht mehr aktiv.

Die Fehlerquelle ist:

preg_match_all("#(\d+)\s+(\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}:\d+\b)\s+(\d+)\s+([0-9a-fA-F]+)(\w+)\s([\S ]+)$#im", $bans, $str);

Er sortiert das PlayersArray ordentlich, gibt aber bei den Bans boolean:null aus.

Ich kann den Fehler darin leider nicht finden.
Die preg_match_all Suche liefert keinen Wert zurück. Warum, wo ist der Fehler?
Das Suchmuster ist das selbige wie bei dem PlayerArray

$rcon->sayGlobal nur einmal ausführbar

Hallo,

Ich habe ein Restart-System für meinen Arma Server erstellt.
Das Restart system soll eigentlich 10 Sekunden bevor der Server restartet, hingehen und mittels sayGlobal Eine Nachricht schicken und danach von 10 runter zählen.

Ich habe mir dafür ein PHP-TCP Server erstellt:

 <?php 

set_time_limit (0); 
error_reporting(E_ALL);
ini_set("display_errors","true");
try {
    $rcon = new ARC('127.0.0.1', '0000',2903);
       
    
  
  
  echo "Verbindung zu Arma hergestellt. \n";
    
   
// Set the ip and port we will listen on 
$address = '127.0.0.1'; 
$port = 9000; 

// Create a TCP Stream socket 
$sock = socket_create(AF_INET, SOCK_STREAM, 0); 
echo "PHP Socket Server started at " . $address . " " . $port . "\n";

// Bind the socket to an address/port 
socket_bind($sock, $address, $port) or die('Could not bind to address'); 
// Start listening for connections 
socket_listen($sock); 

//loop and listen

while (true) {
    /* Accept incoming requests and handle them as child processes */ 
    $client = socket_accept($sock); 
    
    // Read the input from the client – 1024 bytes 
    $input = socket_read($client, 1024); 
    
    // Strip all white spaces from input 
    
    
    // Display output back to client 
   
    // display input on server side
    echo "received: " . $input . "\n";
	$data = explode(";",$input);
	if($data[0]=="/sendmessage ")
	{
		$rcon->sayGlobal($data[1]);
		
		echo "Nachricht '".$data[1]."' gesendet. \n";
	}
}

// Close the client (child) socket 
socket_close($client); 

// Close the master sockets 
socket_close($sock); 
$rcon->disconnect();
 } catch (Exception $e) {
    echo "Verbindung zu Arma konnte nicht hergestellt werden.";
}
?> 

In dem Server baue ich eine RCON Verbindung auf, und wollte diese dann für alle Anfragen nutzen.

Aber er sendet wenn überhaupt nur eine Nachricht und nicht die anderen. Ein reconnect(), wie in #12 kann ich nicht ausführen, da ich nach kurzer zeit mich nicht verbinden kann.

Chat stream not constant

Hey, do I have to use getSocket() function to get the chat/rcon logs? I know it will return a stream resource but how do I make it constant? I have tried to use reactphp loops/streams but it looks like when I ran getSocket() every time it will only send it once and not the whole stream. I only get "logged in" responds but then it stops executing further. Do I have to change something to keep it constantly connected?

Unable to ignore/catch login error.

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.
    }
}

Heartbeat

When using the heartbeat code I get:

<b>Fatal error</b>: Call to private method Nizarii\ARC::sendHeartbeat() from context '' in <b>heartbeat.php</b> on line <b>16</b><br>

Commands not working after kickPlayer() & banPlayer()

Grüße Felix,

die Arrays der Spieler und Bans werden nun korrekt dargestellt.
Wie ich gelesen habe, lag der Fehler ja doch im Suchmuster.

Nun aber zu einem anderen Problem:

Beim Senden eines Formulars bsp. um einen Spieler zu kicken,
wird die Funktion kickPlayer() erfolgreich ausgeführt. Seltsamerweise
geben alle anderen Funktionen, die nach kickPlayer() aufgerufen werden
nichts mehr zurück. Bsp. wird nach dem Senden des Formulars noch die
Spielertabelle durch getPlayersArray() geladen und gibt nix mehr zurück.

Der Descrutor ist dafür allerdings nicht verantwortlich.
Eine Auskommentierung hat in diesem Falle nichts bewirkt.

Ich verstehe nicht ganz, wieso die Verbindung offenbar getrennt ist.

Kannst du mir dazu etwas sagen?

Übrigens sprachst du letztes mal davon, dass ich close() nicht verwenden
müsse und die Funktion privat sei, sie ist aber eine öffentliche Funktion.

(das nur mal am Rande erwähnt...)

remove RCon admin on login

Hi,

is there any way to remove the RCon admin when open a connection ?
I am making an ban controlpanel with extra features and every time i run a command i log in :(

ps. i have multiple server support so have to connect to the server I select when running a command

__construct doesnt work

Is the script compatible with PHP7?
I get the following error message:

Fatal error: Uncaught Exception: Wrong constructor parameter type(s)! in C:\xampp\htdocs\ArmaRConClass\rcon.php:77 Stack trace: #0 C:\xampp\htdocs\rCon\getPlayers.php(7): Nizarii\ARC->__construct('localhost', int, 'password') #1 {main} thrown in C:\xampp\htdocs\ArmaRConClass\rcon.php on line 77

But I see no real mistake in it ...

Connection - fatal error

Hallöchen,

deine RCON Klasse spuckt mir seit dem letzten Update folgenden Fehler aus:

Fatal error: Uncaught exception 'Exception' with message '[ARC] Wrong parameter type!'

Witzigerweise entsprechen allerdings alle Parameter den Vorgaben string oder int.

$rcon = new \Nizarii\ARC("255.255.255.255", 2353, "Passwort");

IP und Passwort wurden natürlich geändert.
Kommentiere ich die folgende Überprüfung aus (inkl, throw)

if ( !is_int($serverPort) || !is_string($RCONpassword) || !is_string($serverIP) )

...kann plötzlich kein socket mehr erstellt werden.
Das Script scheitert an fsockopen also der Funtion connect.

Error while executing some commands

Hello,
I am currently in the process of setting up RCON on PHP for a project. We quickly encountered a problem; some commands are sent but nothing is done in-game. After much research, I decide to write to you here.
The connection is made and valid on the server.
For example, the sayGlobal command works perfectly, same for the addBan command but the banPlayer or even kickPlayer command, they do not execute anything on the server despite the absence of error messages on the PHP page.

I don't see how to do it now, if you have any ideas / informations, I'm interested!

Thank's, Tom

Battleye id to steam id

Hi

An option to convert Battleye Id to steam Id would be awesome
I've been googling all day but no luck find anything. So let's work together

sayPlayer Wrong Parameters

Am I stupid?
I am providing an integer for the player and a message as a string and the answer I get is "Wrong parameter type(s)!"

Am I doing something wrong?

php-library

where can i find the php-library for that PHP
any one please help me

RCON Console

Hey buddy, i'm trying to build a live console in the browser to monitor chat.
We've tried it using the socketLoop function, and using reconnect(); sadly enough without success, in the end we did manage to read one of the lines (the Rcon Admin logged in), but then it closes the socket.
Do you have an example how to do this?

getPlayersArray Funktioniert nicht.

Hi, die Neue API funktioniert soweit ganz gut. Allerdings wenn ich die Spieler in einem Array haben will: $players = $rcon->getPlayersArray(); und sie dann Test weise mit mit print_r print_r($players); ausgeben will sieht man auf der Seite einfach nur Array ( )

Functions not working after getPlayersArray()

Hallo Felix!

wie du in einem anderen Issue beschrieben hast, funktionieren die Funktionen nicht mehr nachdem eine andere bereits aufgerufen wurde. Du hast dies mit dem Befehl $this->reconnect(); gelöst doch nicht überall eingetragen.

Heute musste ich leider feststellen dass die Funktion getPlayersArray() ebenfalls dieses Problem aufweist.
Kurzerhand wurde dies aber gelöst durch ein einfaches einfügen von $this->reconnect(); über return players;

Gruß und schönes Wochenende,
Pac

RCON Login Spam

When I run a simple script to connect, and get users and bans, In my RTP the RCON script will login multiple times. Usually between 3-6 but sometimes more. I used to have a heartbeat script which checked the online status once every 2 minutes, and that would cause excessive RCON login spam. I have followed the construct of your class, and am disconnecting from the server, and PHP Access logs only say the server is running the script once, yet I get numerous logins from my servers RCON class.

13:39:30 BattlEye Server: RCon admin #0 (*:58854) logged in
13:39:31 BattlEye Server: RCon admin #1 (*:52640) logged in
13:39:31 BattlEye Server: RCon admin #2 (*:40464) logged in
13:39:32 BattlEye Server: RCon admin #3 (*:58214) logged in
13:39:32 BattlEye Server: RCon admin #4 (*:41285) logged in
13:39:33 BattlEye Server: RCon admin #0 (*:41024) logged in
13:39:33 BattlEye Server: RCon admin #1 (*:51242) logged in

the connection script

<?php

	require_once('arc.php');
	
	use \Nizarii\ARC;
	
	try {
		$rcon = new ARC('*', '*', 2309);
	} catch(Exception $e) {
		print 'Waiting for server...' . "\n";
		exit;
	}

The Stats script

<?php

	require_once('rconnect.php');

	try {
		$online = $rcon->getPlayersArray();
		$bans = $rcon->getBans();
		$rcon->disconnect();
		echo '<span style="color:#3e97b2;">' . count($online) . '</span> User(s) Online | <span style="color:#3e97b2;">' . (count($bans)-1) . '</span> User(s) Banned';
	} catch (Exception $e) {
		echo 'Waiting for Server...';
	}
	

No Connection und Loading Time

Hi.
Sometimes the connection stops and when I am reloading the site, it says: no connection, wrong login data or something like that.

But my main problem is, that my website loads very long. When there are 5 players the site loads really fast but when the server got about 60 to 80 players, the site take 8 seconds to load until it's ready. Maybe you got a good solution to list all players without waiting my hole life.

~ Felix

fwrite error

@steffalon i don't suppose you could contact me via discord Root#4362

I've been having this issue for days now between myself and my host we have white listed everything and attempted everything i cannot for the life of me figure out the solution to this error

[28-Dec-2018 16:24:13 Europe/London] PHP Notice: fwrite(): send of 9 bytes failed with errno=1 Operation not permitted in /home/malibuap/public_html/exile/players.php on line 95 [28-Dec-2018 16:24:13 Europe/London] PHP Notice: Undefined offset: 1 in /home/malibuap/public_html/exile/players.php on line 99

That's using this code you submitted

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$ip = ""; //Ip here [127.0.0.1]
$port = 2310; //Port here [2022]
$pass = ""; //Password here
define("debug", true); //Debug option for developers

if (debug) echo "Debug mode turned on!\n";

$msgseq = 0; //Do not change this variable. Important for sequence steps.

// Login package
$authCRC = crc32(chr(255).chr(00).trim($pass));
$authCRC = sprintf("%x", $authCRC);
$authCRC = array(substr($authCRC,-2,2),substr($authCRC,-4,2),substr($authCRC,-6,2),substr($authCRC,0,2));
$loginmsg = "BE".chr(hexdec($authCRC[0])).chr(hexdec($authCRC[1])).chr(hexdec($authCRC[2])).chr(hexdec($authCRC[3]));
$loginmsg .= chr(hexdec('ff')).chr(hexdec('00')).$pass;
 
if(!($sock = fsockopen("udp://$ip", $port, $errno, $errstr)))
{
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
     
    die("Couldn't create socket: [$errorcode] $errormsg \n");
}


stream_set_timeout($sock, 25);
stream_set_blocking($sock, true);


echo "Socket created \n";
fwrite($sock, $loginmsg);


//Communication loop
while($sock)
{   
    //Receive some data
    $msg = fread($sock, 5000);
    echo substr($msg, 9).PHP_EOL;
    $info = stream_get_meta_data($sock);
    if ($info['timed_out']) {
        if (debug) echo '--Keep connection alive--'.PHP_EOL;
        $keepalive = "BE".chr(hexdec("be")).chr(hexdec("dc")).chr(hexdec("c2")).chr(hexdec("58"));
        $keepalive .= chr(hexdec('ff')).chr(hexdec('01')).chr(hexdec(sprintf('00')));
        fwrite($sock, $keepalive);
    } else {
        $responseCode = unpack('H*', $msg); //Make message usefull for battleye packet by unpacking it to hexbyte.
        $responseCode = str_split(substr($responseCode[1], 12), 2); //Get important hexbytes.
        switch ($responseCode[1]) { //See https://www.battleye.com/downloads/BERConProtocol.txt for packet info.
            case "00": //Login
                if ($responseCode[2] == "01") { //Login successful.
                    echo "Accepted BERCon login.".PHP_EOL;
                } else { //Otherwise $responseCode[2] == "0x00" (Login failed)
                    echo "Invalid BERCon login details. This process is getting stopped.".PHP_EOL;
                    break 2;
                }
                break;
            case "01": //Send commands by this client.
                if (count($responseCode) == 3) {
                    break;
                }
                if ($responseCode[3] !== "00") {
                    if (debug) echo "This is a small package. No further actions needed.".PHP_EOL; //This package is not special. Allow to be continued.
                } else {
                    if (debug) echo "Multi-packet.".PHP_EOL;
                     if (debug) var_dump($responseCode); //Useful developer information.
                     if ($responseCode[5] == "00") {
                         $getAmount = $responseCode[4];
                         if (debug) var_dump($getAmount);
                     }
                }
                break;
            case "02": //acknowledge as client.
                if (debug) echo "Acknowledge!".PHP_EOL;  
                $needBuffer = chr(hexdec('ff')).chr(hexdec('02')).chr(hexdec(sprintf('%2X', $msgseq)));
                $needBuffer = hash("crc32b", $needBuffer);
                $needBuffer = str_split($needBuffer, 2);
                $needBuffer = array_reverse($needBuffer);
                $statusmsg = "BE".chr(hexdec($needBuffer[0])).chr(hexdec($needBuffer[1])).chr(hexdec($needBuffer[2])).chr(hexdec($needBuffer[3]));
                $statusmsg .= chr(hexdec('ff')).chr(hexdec('02')).chr(hexdec(sprintf('%2X', $msgseq)));
                fwrite($sock, $statusmsg);
                $msgseq ++; //Add +1 to sequence.
                break;
        }
    }
}

socket_close($sock);?>

I'm just wanting Rcon but for the web, the ability to read/send messages via chat in the browser and a playerlist to kick/ban.

Chat

Hi

Would it be able get the In game chat ?
Like if someone call's for an admin ?

Bug with long answer in function get_answer()

There is an issue with this function, when the answer is longer than 1024 characters.
The answer is truncated to the first 1024 characters.
I found the issue when I tried to retrieve my ban list, which contains 48 lines.
BTW thanks for the great job, very usefull class

getPlayerArray() format

What exactly is the format of the array that is given when getPlayerArray() is called? I am trying to display the player list as a table on a control panel but for me to display them I need to know what the indexes are for the array. If you could please help it would be greatly appreciated.

Fatal Error Class Nizarii\ARC not Found

Guten Tag, ich wollte mir gerade das ARC wieder auf setzen aber bekomme immer diesen Fehler wenn ich eine neue verbindung aufbauen will

Fatal error: Uncaught Error: Class 'Nizarii\ARC' not found in C:\xampp\htdocs\rcon\test.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\rcon\test.php on line 5

Ich versuche eine Verbindung wie über das Beispiel herzustellen aber es funktioniert nicht könnten sie mir helfen?

Error Ban Arma 3

Hello, I have a problem with the ability to ban a player.

$rcon->ban_player('f276e058bbaaff85d23070c9bd43e2aa', 'test', 30);

Return true

But at the console is not banned. We see just that it is logged

No response after x seconds

Hello Nizarii,

actually i'm using your Rcon Class in a queue daemon where I only opens the connection once and everytime I need new information there will be a new command issued.

The first command gives me successful information back. But all others after that are give me an "" empty response.

I thought maybe the heartbeat is wrong implemented. As it only get called once at the start.
My understanding of a heartbeat is that you call it every x seconds to tell the server i'm still here.

Do you had this issue? I want to keep connection alive and not reconnect every 5 seconds. You know?

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.