felixms / arma-rcon-class-php

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

$rcon->sayGlobal nur einmal ausführbar #34

Closed DLRG-Dominik closed 6 years ago

DLRG-Dominik commented 6 years ago

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.

felixms commented 6 years ago

Vorweg würde ich dich darum bitten, Issues in Englisch zu erstellen, da viele Beteiligte an dem Projekt kein Deutsch sprechen und nur ich dir so helfen kann. Nun zu deiner Frage: das ist sehr komisch :/ ich kenn einige die ARC in Prod. nutzen und keine Probleme haben. So kann ich mir nur eine Verbindung zu #31 erklären, dass die Verbindung vom Server getrennt wird, da die Packages nicht "bestätigt" werden.

The server's BE RCon tries to send a server message packet 5 times for 10 seconds. If the client fails to acknowledge the packet within this time, it will be removed from BE RCon's list of authenticated clients and will no longer be able to issue any commands.

Auszug aus den docs
Versuche mal die Verbindung mit einem Loop sozusagen am Leben zu erhalten, oder ganz simpel: sende die Nachrichten einfach 9 statt 10 Sekunden vorher :D

steffalon commented 6 years ago

Hi @DLRG-Dominik ,

When sending a command like, say something in global, you need to acknowledge the command package that you have been sending to the server. See my ReactPHP example and in there you can make a timer of 10 seconds to restart your game server. Keep in mind that you need dependencies when using ReactPHP library.

Also you have to acknowledge the chat logs if someone is talking in your server when your process got started to restart the server. My ReactPHP script will do it for you.