debumori-osc / Another-Mirai-Native

来了,又是一个酷Q兼容项目
18 stars 2 forks source link

与 Overflow 环境下的 Mirai Http Api 通讯不正常 #18

Closed MisaLiu closed 6 months ago

MisaLiu commented 6 months ago

不知道喜师傅用过 MrXiaoM/Overflow 没有,这几天我的 mirai 与签名服务器频繁断连,我就想试试迁移到 go-cqhttp 然后换用 Overflow 兼容旧的 Mirai 插件。

然后我发现在相同配置文件的情况下,AMN 无法连接以 Overflow 启动的 HTTP API,但是以 Mirai 启动的 HTTP API 依旧可以正常启动

我不太确定这是 Overflow 还是 AMN 的问题,特意开此 issue 询问

MisaLiu commented 6 months ago

我翻看了下代码逻辑,似乎是在创建 WebSocket 链接的时候就出错了,但是我自己编写的测试链接脚本没有出现任何问题,很奇怪

Hellobaka commented 6 months ago

嗯?这个项目不是把mirai插件连接到go-cqhttp吗,我这个框架实现的不是OneBot协议肯定连不上的啊

MisaLiu commented 6 months ago

嗯?这个项目不是把mirai插件连接到go-cqhttp吗,我这个框架实现的不是OneBot协议肯定连不上的啊

我利用这个玩意的架构比较奇异搞笑,原先应该是这样的:

graph TD;
    Mirai-->Mirai-Api-Http;
    Mirai-Api-Http-->Another-Mirai-Native;

现在加入了 Overflow,架构就变成了这个鬼样子:

graph TD;
    go-cqhttp-->Overflow;
    Overflow-->Mirai-Api-Http;
    Mirai-Api-Http-->Another-Mirai-Native;
MisaLiu commented 6 months ago

主要原因还是因为上面提到的,AMN 只支持 Mirai HTTP 协议,然后我也没有找到 OneBot 转 Mirai HTTP 协议的工具,就想到了这么个架构想要继续兼容 AMN

Hellobaka commented 6 months ago

看mirai论坛的说法,go-cqhttp社区似乎有转换协议为MAH的,但是那边的社区我不熟,也不知道从哪帮你找。 至于你说的无法连接指的是什么样子的?是提示无法连接到Mirai-API-Http吗,如果是这样的话试着换一下AuthKey与端口配置。

MisaLiu commented 6 months ago

看mirai论坛的说法,go-cqhttp社区似乎有转换协议为MAH的,但是那边的社区我不熟,也不知道从哪帮你找。 至于你说的无法连接指的是什么样子的?是提示无法连接到Mirai-API-Http吗,如果是这样的话试着换一下AuthKey与端口配置。

无法与Mirai-API-Http建立连接 这个提示,我已经尝试过修改监听端口和 AuthKey,但是没有用

我找一下那个工具先

Hellobaka commented 6 months ago

如果弹出这个错误说明WebSocket服务器配置有问题,连接不上。你做测试的时候,go-cqhttp已经登录上了吗。如果没有的话,QQ号可能没有对应上(猜的

MisaLiu commented 6 months ago

如果弹出这个错误说明WebSocket服务器配置有问题,连接不上。你做测试的时候,go-cqhttp已经登录上了吗。如果没有的话,QQ号可能没有对应上(猜的

cq-http 已经登上了,Overflow 也可以正常处理消息

Hellobaka commented 6 months ago

https://websocketking.com/ 推荐使用工具连接一下看看什么情况。 事件:ws://127.0.0.1:33333/event?verifyKey={AuthKey}&qq={QQ} 消息:ws://127.0.0.1:33333/message?verifyKey={AuthKey}&qq={QQ}

MisaLiu commented 6 months ago

image image image

看不出来

192.168.120.160 是机器的内网地址

Hellobaka commented 6 months ago

MAH响应正常。 如果你把amn框架搬到用postman的电脑上呢?还是连不上的话能麻烦你挂个调试器看看到底发生了什么吗(

MisaLiu commented 6 months ago

我本地搭建了一下测试环境,然后它好了。。。

image

Hellobaka commented 6 months ago

猜测与监听的localhost有关,改为127.0.0.1或者0.0.0.0试试?

MisaLiu commented 6 months ago

我在服务器上重新搭建了环境,然后在自己的机器上链接,依旧提示无法建立通讯

同时服务器上的 Overflow 有如下报错:

2024-01-13 17:07:13 E/MahKtorAdapter[ws]: Websocket handler failed
java.util.ConcurrentModificationException
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1135)
        at mirai-api-http-2.10.0.mirai2.jar//net.mamoe.mirai.api.http.context.session.manager.DefaultSessionManager.getCache(default.kt:79)
        at mirai-api-http-2.10.0.mirai2.jar//net.mamoe.mirai.api.http.context.session.manager.DefaultSessionManager.authSession(default.kt:56)
        at mirai-api-http-2.10.0.mirai2.jar//net.mamoe.mirai.api.http.adapter.ws.router.BaseKt$wsRouter$1$invoke$$inlined$miraiWebsocket$1.invokeSuspend(utils.kt:55)
        at mirai-api-http-2.10.0.mirai2.jar//net.mamoe.mirai.api.http.adapter.ws.router.BaseKt$wsRouter$1$invoke$$inlined$miraiWebsocket$1.invoke(utils.kt)
        at mirai-api-http-2.10.0.mirai2.jar//net.mamoe.mirai.api.http.adapter.ws.router.BaseKt$wsRouter$1$invoke$$inlined$miraiWebsocket$1.invoke(utils.kt)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt.handleServerSession(Routing.kt:251)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt.proceedWebSocket(Routing.kt:237)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt.access$proceedWebSocket(Routing.kt:1)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt$webSocket$2.invokeSuspend(Routing.kt:201)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt$webSocket$2.invoke(Routing.kt)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt$webSocket$2.invoke(Routing.kt)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt$webSocketRaw$2$1$1$1$1.invokeSuspend(Routing.kt:105)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt$webSocketRaw$2$1$1$1$1.invoke(Routing.kt)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.RoutingKt$webSocketRaw$2$1$1$1$1.invoke(Routing.kt)
        at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.server.websocket.WebSocketUpgrade$upgrade$2.invokeSuspend(WebSocketUpgrade.kt:99)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
MisaLiu commented 6 months ago

猜测与监听的localhost有关,改为127.0.0.1或者0.0.0.0试试?

改的是 0.0.0.0

Hellobaka commented 6 months ago

查了一下,这个异常似乎是集合在上一次迭代没有完成时被更改发生的。但是由于在另一台机器上没有问题,所以MAH插件出问题的可能不大。 https://github.com/dnSpy/dnSpy 请用调试器启动一下AMN框架看看异常在哪

image

在箭头这里设置断点,之后启动程序,等到运行到这一行时,打开上方的调试-窗口-输出的窗口,查看异常信息

MisaLiu commented 6 months ago

查了一下,这个异常似乎是集合在上一次迭代没有完成时被更改发生的。但是由于在另一台机器上没有问题,所以MAH插件出问题的可能不大。 https://github.com/dnSpy/dnSpy 请用调试器启动一下AMN框架看看异常在哪

image

在箭头这里设置断点,之后启动程序,等到运行到这一行时,打开上方的调试-窗口-输出的窗口,查看异常信息

17:41:27.654 AnotherMiraiNative.exe (CLR v4.0.30319: DefaultDomain): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
17:41:27.719 AnotherMiraiNative.exe (CLR v4.0.30319: DefaultDomain): 已加载 'C:\Users\misaliu\Desktop\AMN\AnotherMiraiNative.exe'
17:41:27.754 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'
17:41:27.765 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
17:41:27.774 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
17:41:27.859 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
17:41:27.906 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'
17:41:28.129 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'
17:41:28.602 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'Newtonsoft.Json'
17:41:28.610 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'
17:41:28.642 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'
17:41:29.913 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'
17:41:29.958 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'
17:41:30.115 AnotherMiraiNative.exe (CLR v4.0.30319: AnotherMiraiNative.exe): 已加载 'websocket-sharp'
17:41:30.294 2024/1/13 17:41:30|Fatal|WebSocket.doHandshake|Includes an invalid Sec-WebSocket-Extensions header.
17:41:30.301 2024/1/13 17:41:30|Fatal|WebSocket.doHandshake|Includes an invalid Sec-WebSocket-Extensions header.
17:42:07.362 引发异常: 'System.Exception' in AnotherMiraiNative.exe
17:42:07.365 其他信息: 无法与Mirai-api-http建立连接

下面是 Overflow 侧的报错

2024-01-13 17:41:31 W/stderr: java.io.IOException: 远程主机强迫关闭了一个现有的连接。
2024-01-13 17:41:31 W/stderr:   at java.base/sun.nio.ch.SocketDispatcher.read0(Native Method)
2024-01-13 17:41:31 W/stderr:   at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
2024-01-13 17:41:31 W/stderr:   at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
2024-01-13 17:41:31 W/stderr:   at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233)
2024-01-13 17:41:31 W/stderr:   at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
2024-01-13 17:41:31 W/stderr:   at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:356)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.sockets.CIOReaderKt$readFrom$2.invoke(CIOReader.kt:134)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.sockets.CIOReaderKt$readFrom$2.invoke(CIOReader.kt:133)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.utils.io.ByteBufferChannel.writeAvailable(ByteBufferChannel.kt:1458)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.utils.io.ByteBufferChannel.write$suspendImpl(ByteBufferChannel.kt:1488)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.utils.io.ByteBufferChannel.write(ByteBufferChannel.kt)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.utils.io.ByteWriteChannel$DefaultImpls.write$default(ByteWriteChannel.kt:88)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.sockets.CIOReaderKt.readFrom(CIOReader.kt:133)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.sockets.CIOReaderKt.access$readFrom(CIOReader.kt:1)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.sockets.CIOReaderKt$attachForReadingDirectImpl$1.invokeSuspend(CIOReader.kt:109)
2024-01-13 17:41:31 W/stderr:   at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:190)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:328)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.selector.SelectorManagerSupport.handleSelectedKey(SelectorManagerSupport.kt:89)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.selector.SelectorManagerSupport.handleSelectedKeys(SelectorManagerSupport.kt:70)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.selector.ActorSelectorManager.process(ActorSelectorManager.kt:70)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.selector.ActorSelectorManager.access$process(ActorSelectorManager.kt:18)
2024-01-13 17:41:31 W/stderr:   at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.network.selector.ActorSelectorManager$process$1.invokeSuspend(ActorSelectorManager.kt)
2024-01-13 17:41:31 W/stderr:   at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
2024-01-13 17:41:31 W/stderr:   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Hellobaka commented 6 months ago

RJAGNFD C9V)`RRUNM7KC37_tmb

感觉超出我能改的范围了。 最后看看MAH插件的配置吧,已经完全没有解决思路了

MisaLiu commented 6 months ago

AMN/conf/Config.json

{
  "MaxLogCount": 500,
  "AutoLogin": false,
  "QQ": "1233456",
  "Ws_Url": "ws://127.0.0.1:27529",
  "Ws_AuthKey": "ktwgALJgFLXcIjWO",
  "API_Timeout": 6000,
  "FloatWindow_TopMost": false,
  "FloatWindow_Visible": false,
  "FloatWindow_Location": "336,128"
}

Overflow/mirai-api-http/settings.yml

adapters: 
  - ws
debug: true
enableVerify: true
verifyKey: UP4DMK98tKWK5FtZ
singleMode: false
cacheSize: 4096
persistenceFactory: 'built-in'
adapterSettings: 
  ws:
    host: 0.0.0.0
    port: 27529
Hellobaka commented 6 months ago

啊?你这AuthKey没对上啊

MisaLiu commented 6 months ago

啊?你这AuthKey没对上啊

刚拿去测试原生 Mirai 了所以是另外一个 authKey

Hellobaka commented 6 months ago

除去这个看不出问题……我看看我能不能搭一个试试

Hellobaka commented 6 months ago

本地运行正常,复现不来……

Hellobaka commented 6 months ago

嗯……你把MAH的debug关掉应该就好了。我打开debug之后出现了相同的问题

“AnotherMiraiNative.exe”(CLR v4.0.30319: AnotherMiraiNative.exe): 已加载“C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll”。
“AnotherMiraiNative.exe”(CLR v4.0.30319: AnotherMiraiNative.exe): 已加载“websocket-sharp”。模块已生成,不包含符号。
2024/1/13 18:38:28|Fatal|WebSocket.doHandshake|Includes an invalid Sec-WebSocket-Extensions header.
2024/1/13 18:38:28|Fatal|WebSocket.doHandshake|Includes an invalid Sec-WebSocket-Extensions header.
引发的异常:“System.Exception”(位于 AnotherMiraiNative.exe 中)
无法与Mirai-api-http建立连接