mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-18 05:04:51 +08:00
修复多账号的问题,完全支持多账号
This commit is contained in:
parent
2de4337600
commit
527814592d
@ -11,8 +11,10 @@ class WSMessageEvent extends Event
|
||||
public function __construct(swoole_websocket_server $server, swoole_websocket_frame $frame) {
|
||||
$req = json_decode($frame->data, true);
|
||||
if (isset($req["echo"])) if (APIHandler::execute($req["echo"], $req)) return;
|
||||
if (isset($req["echo"]["type"]) && $req["echo"]["type"] === "handshake") {
|
||||
//echo Console::setColor(json_encode($req, 128|256), "gold");
|
||||
if (isset($req["echo"]["type"]) && $req["echo"]["type"] == "handshake") {
|
||||
$fd_id = $frame->fd;
|
||||
$req["user_id"] = $req["data"]["user_id"];
|
||||
$connect = CQUtil::getConnection($fd_id);
|
||||
$connect->setQQ($req["user_id"]);
|
||||
$connect->setType(1);
|
||||
@ -30,11 +32,12 @@ class WSMessageEvent extends Event
|
||||
foreach ($data as $e) {
|
||||
$msg = $msg . $e . "\n";
|
||||
}
|
||||
CQUtil::sendDebugMsg($msg, $req["user_id"], 0);
|
||||
CQUtil::sendDebugMsg($msg, strval($req["user_id"]), 0);
|
||||
CQUtil::sendDebugMsg("[CQBot] 成功开启!", $req["user_id"], 0);
|
||||
file_put_contents(CONFIG_DIR . "error_flag", time());
|
||||
file_put_contents(CONFIG_DIR . "last_error.log", "");
|
||||
} else {
|
||||
Console::info("监测到API连接,已经完成初始化!");
|
||||
CQUtil::sendDebugMsg("[CQBot] 成功开启!", $req["user_id"], 0);
|
||||
}
|
||||
CQUtil::sendAPI($frame->fd, "_get_friend_list", ["get_friend_list"]);
|
||||
|
||||
@ -10,6 +10,7 @@ class WSOpenEvent extends Event
|
||||
{
|
||||
public function __construct(swoole_websocket_server $server, swoole_http_request $request) {
|
||||
$fd = $request->fd;
|
||||
//Console::info("收到连接:".$fd);
|
||||
CQUtil::getConnection($fd);
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ class CQUtil
|
||||
* @return null
|
||||
*/
|
||||
static function sendDebugMsg($msg, $self_id, $need_head = 1) {
|
||||
if (Framework::$admin_group[$self_id] == "") return null;
|
||||
if (Framework::$admin_group[strval($self_id)] == "") return null;
|
||||
if ($need_head)
|
||||
$data = CQMsg("[DEBUG] " . date("H:i:s") . ": " . $msg, "group", Framework::$admin_group);
|
||||
else
|
||||
@ -255,6 +255,7 @@ class CQUtil
|
||||
* @return WSConnection
|
||||
*/
|
||||
static function getConnection($fd) {
|
||||
//var_dump(Buffer::$connect);
|
||||
if (!isset(Buffer::$connect[$fd])) {
|
||||
$s = new WSConnection(Buffer::$event, $fd);
|
||||
Buffer::$connect[$fd] = $s;
|
||||
@ -420,7 +421,6 @@ class CQUtil
|
||||
$reply = ["action" => "send_group_msg", "params" => ["group_id" => $groupId, "message" => $msg]];
|
||||
$reply["echo"] = $reply;
|
||||
$reply["echo"]["time"] = time();
|
||||
$reply = json_encode($reply);
|
||||
$connections = CQUtil::getApiConnectionByQQ($self_id);
|
||||
if ($connections === null) {
|
||||
Console::error("未找到qq号:" . $self_id . "的API连接");
|
||||
@ -450,7 +450,6 @@ class CQUtil
|
||||
$reply = ["action" => "send_private_msg", "params" => ["user_id" => $userId, "message" => $msg]];
|
||||
$reply["echo"] = $reply;
|
||||
$reply["echo"]["time"] = time();
|
||||
$reply = json_encode($reply);
|
||||
$connections = CQUtil::getApiConnectionByQQ($self_id);
|
||||
if ($connections === null) {
|
||||
Console::error("未找到qq号:" . $self_id . "的API连接");
|
||||
@ -496,6 +495,7 @@ class CQUtil
|
||||
"params" => $rw
|
||||
];
|
||||
$api["echo"] = $echo;
|
||||
Console::info("将要发送的API包:" . json_encode($api, 128 | 256));
|
||||
return self::APIPush($fd, json_encode($api));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user