I'm try to make a Telegram bot that'll connect to an RCON, but at the moment I'm stuck in the usage of the sessions, seems like they aren't saved. This is my code so far:
<?php
define('BOT_TOKEN', 'xx:xxxxxx');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
//Start session
session_set_cookie_params(3600, "/");
session_start();
//read incoming info and grab the chatID
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
$reply = "";
if (isset($_SESSION['AskIP'])){
$_SESSION = array('AskPort' => true,
'ip' => $message);
$reply = "Saved IP: ". $message ."Write the port";
}
else if (isset($_SESSION['AskPort'])){
$ip = $_SESSION['ip'];
$_SESSION = array('connected' => true,
'ip' => $ip,
'port' => $message);
$reply = "Now you are connected the rcon (".$_SESSION['ip']. ":". $_SESSION['port'].")! Type /disconnect to disconnect from the rcon!";
}
else if (substr($message, 0, 11) === "/disconnect" && strlen($message) == 11 && isset($_SESSION['connected'])){
$_SESSION['connected'] = false;
$reply = "Disconnected from". $_SESSION['ip'] .":". $_SESSION['port'];
$_SESSION = array();
session_destroy();
}
else if (substr($message, 0, 5) === "/rcon" && strlen($message) == 5) {
$_SESSION = array('AskIP' => true);
$reply = "Write the Server IP";
}
if (empty($reply))
return;
$sendto = API_URL."sendmessage?chat_id=".$chatID."&text=".$reply;
file_get_contents($sendto);
?>
At the momement it only works when you type /rcon (and the replies "Write the IP" but after that no answer, the privacy settings are already disabled.
I ended up just by using mysql.