Compare commits

...

2 Commits
1.5.6 ... 1.5.8

Author SHA1 Message Date
whale
504934f057 update to 1.5.8 version
add fullMatch to CQCommand.php
2020-06-26 15:53:40 +08:00
whale
e976a96d0b add auto-reconnect method to terminal_listener.php
add short name of ZM_BREAKPOINT (BP)
fix loop error of syntax happened
2020-06-20 14:51:24 +08:00
9 changed files with 32 additions and 11 deletions

View File

@@ -3,7 +3,7 @@
"description": "High performance QQ robot and web server development framework",
"minimum-stability": "stable",
"license": "Apache-2.0",
"version": "1.5.6",
"version": "1.5.8",
"authors": [
{
"name": "whale",

View File

@@ -184,6 +184,7 @@ class Console
$vss->callback = function(?WSConnection $conn) use ($terminal_id){
$req = ctx()->getRequest();
if($conn->getType() != "terminal") return false;
Console::debug("Terminal fd: ".$conn->fd);
if(($req->header["x-terminal-id"] ?? "") != $terminal_id) {
$conn->close();
return false;
@@ -195,6 +196,7 @@ class Console
$vss2->type = "message";
$vss2->rule = "connectType:terminal";
$vss2->callback = function(?WSConnection $conn){
if ($conn === null) return false;
if($conn->getType() != "terminal") return false;
$cmd = ctx()->getFrame()->data;
self::executeCommand($cmd);

View File

@@ -151,6 +151,7 @@ class FrameworkLoader
define("ZM_MATCH_NUMBER", 2);
define("ZM_MATCH_SECOND", 3);
define("ZM_BREAKPOINT", 'if(in_array("--debug-mode", \Framework\FrameworkLoader::$argv)) extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : @get_called_class()));');
define("BP", ZM_BREAKPOINT);
define("ZM_DEFAULT_FETCH_MODE", self::$settings->get("sql_config")["sql_default_fetch_mode"] ?? 4);
}

View File

@@ -3,6 +3,7 @@
use Swoole\Coroutine\Http\Client;
Co\run(function (){
hello:
global $terminal_id, $port;
$client = new Client("127.0.0.1", $port);
$client->set(['websocket_mask' => true]);
@@ -17,8 +18,9 @@ Co\run(function (){
break;
}
if($r === false) {
echo "Unable to connect framework terminal, connection closed.\n";
break;
echo "Unable to connect framework terminal, connection closed. Trying to reconnect after 5s.\n";
sleep(5);
goto hello;
}
} else {
break;

View File

@@ -111,6 +111,7 @@ class AnnotationParser
if ($vss instanceof Rule) $vss = self::registerRuleEvent($vss, $vs, $reflection_class);
else $vss = self::registerMethod($vss, $vs, $reflection_class);
Console::debug("寻找 ".$vs->getName() ." -> ".get_class($vss));
if ($vss instanceof SwooleEventAt) ZMBuf::$events[SwooleEventAt::class][] = $vss;
elseif ($vss instanceof SwooleEventAfter) ZMBuf::$events[SwooleEventAfter::class][] = $vss;
elseif ($vss instanceof CQMessage) ZMBuf::$events[CQMessage::class][] = $vss;

View File

@@ -19,6 +19,8 @@ class CQCommand extends AnnotationBase implements Level
public $match = "";
/** @var string */
public $regexMatch = "";
/** @var string */
public $fullMatch = "";
/** @var string[] */
public $alias = [];
/** @var string */

View File

@@ -100,7 +100,7 @@ class MessageEvent
$obj = [];
foreach (ZMBuf::$events[CQCommand::class] ?? [] as $v) {
/** @var CQCommand $v */
if ($v->match == "" && $v->regexMatch == "") continue;
if ($v->match == "" && $v->regexMatch == "" && $v->fullMatch == "") continue;
elseif (($v->user_id == 0 || ($v->user_id != 0 && $v->user_id == context()->getData()["user_id"])) &&
($v->group_id == 0 || ($v->group_id != 0 && $v->group_id == (context()->getData()["group_id"] ?? 0))) &&
($v->discuss_id == 0 || ($v->discuss_id != 0 && $v->discuss_id == (context()->getData()["discuss_id"] ?? 0))) &&
@@ -135,6 +135,14 @@ class MessageEvent
return true;
});
return;
} elseif ($v->fullMatch != "" && (preg_match("/".$v->fullMatch."/u", ctx()->getMessage(), $args)) != 0) {
Console::debug("Calling $c -> {$v->method}");
array_shift($args);
$this->function_call = EventHandler::callWithMiddleware($obj[$c], $v->method, $class_construct, [$args], function ($r) {
if (is_string($r)) context()->reply($r);
return true;
});
return;
}
}
}

View File

@@ -39,14 +39,17 @@ class EventHandler
switch ($event_name) {
case "workerstart":
try {
register_shutdown_function(function () {
register_shutdown_function(function () use ($param0) {
$error = error_get_last();
if ($error["type"] != 0) {
Console::error("Internal fatal error: " . $error["message"] . " at " . $error["file"] . "({$error["line"]})");
}
DataProvider::saveBuffer();
ZMBuf::$server->shutdown();
/** @var Server $param0 */
if (ZMBuf::$server === null) $param0->shutdown();
else ZMBuf::$server->shutdown();
});
ZMBuf::$server = $param0;
$r = (new WorkerStartEvent($param0, $param1))->onActivate();
Console::log("\n=== Worker #" . $param0->worker_id . " 已启动 ===\n", "gold");
$r->onAfter();
@@ -57,7 +60,9 @@ class EventHandler
ZMUtil::stop();
return;
} catch (Error $e) {
var_export($e);
Console::error("PHP Error: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine());
Console::error("Maybe it caused by your own code if in your own Module directory.");
Console::log($e->getTraceAsString(), 'gray');
ZMUtil::stop();
}
break;
@@ -85,7 +90,7 @@ class EventHandler
" [" . $param1->getStatusCode() . "] " . $param0->server["request_uri"]
);
if (!$param1->isEnd()) $param1->end("Internal server error: " . $e->getMessage());
Console::error("Internal server exception (500), caused by ".get_class($e));
Console::error("Internal server exception (500), caused by " . get_class($e));
Console::log($e->getTraceAsString(), "gray");
} catch (Error $e) {
/** @var Response $param1 */
@@ -134,7 +139,7 @@ class EventHandler
* @throws AnnotationException
*/
public static function callCQEvent($event_data, $conn_or_response, int $level = 0) {
ctx()->setCache("level",$level);
ctx()->setCache("level", $level);
if ($level >= 5) {
Console::warning("Recursive call reached " . $level . " times");
Console::stackTrace();
@@ -172,7 +177,7 @@ class EventHandler
* @throws AnnotationException
*/
public static function callCQResponse($req) {
Console::debug("收到来自API连接的回复".json_encode($req, 128|256));
Console::debug("收到来自API连接的回复" . json_encode($req, 128 | 256));
$status = $req["status"];
$retcode = $req["retcode"];
$data = $req["data"];

View File

@@ -24,7 +24,7 @@ class ZMUtil
public static function stop($without_shutdown = false) {
Console::info(Console::setColor("Stopping server...", "red"));
foreach (ZMBuf::$server->connections as $v) {
foreach ((ZMBuf::$server->connections ?? []) as $v) {
ZMBuf::$server->close($v);
}
DataProvider::saveBuffer();