我正在尝试创建一个能够连接到RCON的Telegram机器人,但是目前我被困在会话的使用中,似乎他们没有被保存。 到目前为止,这是我的代码:
<?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);
&GT;
只有当您输入/ rcon(并且回复“写入IP”但在没有回答之后,隐私设置已被禁用时)它才有效。
答案 0 :(得分:1)
我最后只使用了mysql。