nonebot-plugin-mccheck 0.2.0__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/PKG-INFO +4 -2
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/__init__.py +20 -24
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/configs.py +1 -1
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/data_source.py +154 -165
- nonebot_plugin_mccheck-0.2.3/nonebot_plugin_mccheck/templates/README.md +9 -0
- nonebot_plugin_mccheck-0.2.3/nonebot_plugin_mccheck/templates/default.html +48 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/utils.py +109 -132
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/pyproject.toml +1 -1
- nonebot_plugin_mccheck-0.2.0/nonebot_plugin_mccheck/templates/default.html +0 -56
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/LICENSE +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/README.md +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/config.py +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/language.json +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/templates/Minecraft_AE.ttf +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/templates/background.png +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/templates/imagelesshoverbg.png +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/templates/main.css +0 -0
- {nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/templates/no_favicon.png +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: nonebot-plugin-mccheck
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Minecraft服务器状态查询的nonebot插件,支持IPv6/Minecraft server status query plugin for nonebot, IPv6 supported
|
|
5
5
|
License: GPL-3.0
|
|
6
|
+
License-File: LICENSE
|
|
6
7
|
Keywords: nonebot,nonebot2,minecraft,i18n,plugin,server
|
|
7
8
|
Author: molanp
|
|
8
9
|
Author-email: molanpp@outlook.com
|
|
@@ -20,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
20
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
23
|
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
25
|
Requires-Dist: dnspython (>=2.5.0)
|
|
24
26
|
Requires-Dist: nonebot-plugin-alconna (>=0.48.0)
|
|
25
27
|
Requires-Dist: nonebot-plugin-htmlrender (>=0.3.5)
|
{nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/__init__.py
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
|
|
1
3
|
from nonebot import require
|
|
2
4
|
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
|
|
3
5
|
from .config import Config
|
|
@@ -14,12 +16,12 @@ from .utils import (
|
|
|
14
16
|
require("nonebot_plugin_alconna")
|
|
15
17
|
require("nonebot_plugin_uninfo")
|
|
16
18
|
from arclet.alconna import Alconna, Args, CommandMeta
|
|
17
|
-
from nonebot_plugin_alconna import
|
|
18
|
-
from nonebot_plugin_uninfo import
|
|
19
|
+
from nonebot_plugin_alconna import Match, Text, UniMessage, on_alconna
|
|
20
|
+
from nonebot_plugin_uninfo import Uninfo
|
|
19
21
|
|
|
20
22
|
__plugin_meta__ = PluginMetadata(
|
|
21
23
|
name="Minecraft查服",
|
|
22
|
-
description="Minecraft服务器状态查询,支持IPv6
|
|
24
|
+
description="Minecraft服务器状态查询,支持IPv6",
|
|
23
25
|
type="application",
|
|
24
26
|
homepage="https://github.com/molanp/nonebot_plugin_mccheck",
|
|
25
27
|
supported_adapters=inherit_supported_adapters(
|
|
@@ -33,7 +35,7 @@ __plugin_meta__ = PluginMetadata(
|
|
|
33
35
|
设置语言 zh-cn
|
|
34
36
|
当前语言
|
|
35
37
|
语言列表
|
|
36
|
-
|
|
38
|
+
eg:
|
|
37
39
|
mcheck ip:port / mcheck ip
|
|
38
40
|
set_lang en
|
|
39
41
|
lang_now
|
|
@@ -43,9 +45,9 @@ __plugin_meta__ = PluginMetadata(
|
|
|
43
45
|
)
|
|
44
46
|
|
|
45
47
|
check = on_alconna(
|
|
46
|
-
Alconna("mcheck", Args["host?", str]),
|
|
48
|
+
Alconna("mcheck", Args["host?", str], meta=CommandMeta(compact=True)),
|
|
47
49
|
aliases={"查服"},
|
|
48
|
-
priority=
|
|
50
|
+
priority=5,
|
|
49
51
|
block=True,
|
|
50
52
|
)
|
|
51
53
|
|
|
@@ -53,35 +55,35 @@ check = on_alconna(
|
|
|
53
55
|
lang_change = on_alconna(
|
|
54
56
|
Alconna("set_lang", Args["language", str], meta=CommandMeta(compact=True)),
|
|
55
57
|
aliases={"设置语言"},
|
|
56
|
-
priority=
|
|
58
|
+
priority=5,
|
|
57
59
|
block=True,
|
|
58
60
|
)
|
|
59
61
|
|
|
60
62
|
lang_now = on_alconna(
|
|
61
63
|
Alconna("lang_now", meta=CommandMeta(compact=True)),
|
|
62
64
|
aliases={"当前语言"},
|
|
63
|
-
priority=
|
|
65
|
+
priority=5,
|
|
64
66
|
block=True,
|
|
65
67
|
)
|
|
66
68
|
|
|
67
69
|
lang_list = on_alconna(
|
|
68
70
|
Alconna("lang_list", meta=CommandMeta(compact=True)),
|
|
69
71
|
aliases={"语言列表"},
|
|
70
|
-
priority=
|
|
72
|
+
priority=5,
|
|
71
73
|
block=True,
|
|
72
74
|
)
|
|
73
75
|
|
|
74
76
|
|
|
75
77
|
@check.handle()
|
|
76
|
-
async def _(
|
|
77
|
-
if not
|
|
78
|
+
async def _(host: Match[str], session: Uninfo):
|
|
79
|
+
if not host.available:
|
|
78
80
|
await check.finish(Text(f"{lang_data[lang]['where_ip']}"), reply_to=True)
|
|
79
|
-
address, port = await parse_host(
|
|
81
|
+
address, port = await parse_host(host.result)
|
|
80
82
|
|
|
81
83
|
if not str(port).isdigit() or not (0 <= int(port) <= 65535):
|
|
82
84
|
await check.finish(Text(f"{lang_data[lang]['where_port']}"), reply_to=True)
|
|
83
85
|
|
|
84
|
-
if
|
|
86
|
+
if is_validity_address(address):
|
|
85
87
|
await get_info(address, port, session)
|
|
86
88
|
return
|
|
87
89
|
|
|
@@ -91,26 +93,20 @@ async def get_info(ip, port, session):
|
|
|
91
93
|
|
|
92
94
|
try:
|
|
93
95
|
message_list = await get_message_list(ip, port, 3)
|
|
94
|
-
if
|
|
95
|
-
for sublist in message_list:
|
|
96
|
-
if is_qbot(session):
|
|
97
|
-
for m in sublist:
|
|
98
|
-
await check.send(UniMessage(m), reply_to=True)
|
|
99
|
-
else:
|
|
100
|
-
await check.send(UniMessage(sublist), reply_to=True)
|
|
101
|
-
elif is_qbot(session):
|
|
96
|
+
if is_qbot(session):
|
|
102
97
|
for m in message_list:
|
|
103
98
|
await check.send(UniMessage(m), reply_to=True)
|
|
104
99
|
else:
|
|
100
|
+
message_list = list(itertools.chain.from_iterable(message_list))
|
|
105
101
|
await check.send(UniMessage(message_list), reply_to=True)
|
|
106
102
|
except BaseException as e:
|
|
107
|
-
await check.send(
|
|
103
|
+
await check.send(handle_exception(e), reply_to=True)
|
|
108
104
|
|
|
109
105
|
|
|
110
106
|
@lang_change.handle()
|
|
111
107
|
async def _(language: str):
|
|
112
108
|
if language:
|
|
113
|
-
await lang_change.send(Text(
|
|
109
|
+
await lang_change.send(Text(change_language_to(language)), reply_to=True)
|
|
114
110
|
else:
|
|
115
111
|
await lang_change.send(Text("Language?"), reply_to=True)
|
|
116
112
|
|
|
@@ -123,4 +119,4 @@ async def _():
|
|
|
123
119
|
@lang_list.handle()
|
|
124
120
|
async def _():
|
|
125
121
|
i = "\n".join(list(lang_data.keys()))
|
|
126
|
-
await lang_list.send(Text(f"Language List:\n{i}"), reply_to=True)
|
|
122
|
+
await lang_list.send(Text(f"Language List:\n{i}"), reply_to=True)
|
{nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/data_source.py
RENAMED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
# Copyright (C) 2016-2023 Lloyd Dilley, Felix Ern (MindSolve)
|
|
3
3
|
# http://www.dilley.me/
|
|
4
4
|
#
|
|
5
|
-
# Secondary optimization and customization are carried out by @molanp.
|
|
6
|
-
#
|
|
7
5
|
# This program is free software; you can redistribute it and/or modify
|
|
8
6
|
# it under the terms of the GNU General Public License as published by
|
|
9
7
|
# the Free Software Foundation; either version 3 of the License, or
|
|
@@ -17,6 +15,13 @@
|
|
|
17
15
|
# You should have received a copy of the GNU General Public License along
|
|
18
16
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
19
17
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18
|
+
#
|
|
19
|
+
# 本文件由 @molanp 进行优化与需求定制
|
|
20
|
+
#
|
|
21
|
+
# 由于 wiki.vg 站点已关闭,现在你可以在
|
|
22
|
+
# https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge#Project_pages
|
|
23
|
+
# 找到原始内容的副本
|
|
24
|
+
|
|
20
25
|
import base64
|
|
21
26
|
from enum import Enum
|
|
22
27
|
import io
|
|
@@ -30,73 +35,71 @@ from time import perf_counter, time
|
|
|
30
35
|
|
|
31
36
|
class ConnStatus(Enum):
|
|
32
37
|
"""
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- `
|
|
36
|
-
- `
|
|
37
|
-
- `
|
|
38
|
-
- `UNKNOWN`: The connection was established, but the server spoke an unknown/unsupported SLP protocol.
|
|
38
|
+
包含可能的连接状态
|
|
39
|
+
- `SUCCESS`:指定的 SLP 连接成功(请求和响应解析正常)
|
|
40
|
+
- `CONNFAIL`:无法建立到服务器的套接字连接。服务器离线、主机名或端口错误?
|
|
41
|
+
- `TIMEOUT`:连接超时。(服务器负载过高?防火墙规则是否正确?)
|
|
42
|
+
- `UNKNOWN`:连接已建立,但服务器使用了未知或不支持的 SLP 协议
|
|
39
43
|
"""
|
|
40
44
|
|
|
41
45
|
def __str__(self) -> str:
|
|
42
46
|
return str(self.name)
|
|
43
47
|
|
|
44
48
|
SUCCESS = 0
|
|
45
|
-
"""
|
|
49
|
+
"""指定的 SLP 连接成功(请求和响应解析正常)"""
|
|
46
50
|
|
|
47
51
|
CONNFAIL = -1
|
|
48
|
-
"""
|
|
52
|
+
"""无法建立与服务器的套接字连接。(服务器离线,主机名或端口错误?)"""
|
|
49
53
|
|
|
50
54
|
TIMEOUT = -2
|
|
51
|
-
"""
|
|
55
|
+
"""连接超时。(服务器负载过高?防火墙规则是否正确?)"""
|
|
52
56
|
|
|
53
57
|
UNKNOWN = -3
|
|
54
|
-
"""
|
|
58
|
+
"""连接已建立,但服务器使用了未知或不支持的 SLP 协议"""
|
|
55
59
|
|
|
56
60
|
|
|
57
61
|
class SlpProtocols(Enum):
|
|
58
62
|
"""
|
|
59
|
-
|
|
63
|
+
包含可能的 SLP(服务器列表 Ping)协议。
|
|
60
64
|
|
|
61
|
-
- `ALL
|
|
65
|
+
- `ALL`:尝试所有协议。
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
is received or until failure.
|
|
67
|
+
尝试使用所有可用协议连接到远程服务器,直到收到可接受的响应或失败为止。
|
|
65
68
|
|
|
66
|
-
- `QUERY
|
|
67
|
-
|
|
68
|
-
Query
|
|
69
|
+
- `QUERY`:用于 Minecraft Java 服务器的 Query / GameSpot4 / UT3 协议。
|
|
70
|
+
需要在 Minecraft 服务器上启用。
|
|
71
|
+
Query 类似于 SLP,但会返回更多技术相关的数据。
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
*自 Minecraft 1.9 起可用*
|
|
71
74
|
|
|
72
|
-
- `BEDROCK_RAKNET
|
|
75
|
+
- `BEDROCK_RAKNET`:Minecraft 基岩版/教育版协议。
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
*适用于所有 Minecraft 基岩版版本,与 Java 版不兼容。*
|
|
75
78
|
|
|
76
|
-
- `JSON
|
|
79
|
+
- `JSON`:最新且当前支持的 SLP 协议。
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
使用(包装的)JSON 作为负载。复杂查询,详见 `json_query()` 的协议实现。
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
- `EXTENDED_LEGACY
|
|
83
|
+
*自 Minecraft 1.7 起可用*
|
|
84
|
+
- `EXTENDED_LEGACY`:上一代 SLP 协议
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
Minecraft 1.6 使用,所有新版本服务器仍兼容。
|
|
87
|
+
需要复杂查询,详见 `extended_legacy_query()` 的完整协议细节。
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
- `LEGACY
|
|
89
|
+
*自 Minecraft 1.6 起可用*
|
|
90
|
+
- `LEGACY`:传统 SLP 协议。
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
Minecraft 1.4 和 1.5 使用,是第一个包含服务器版本号的协议。
|
|
93
|
+
非常简单的协议调用(2 字节),简单的响应解码。
|
|
94
|
+
详见 `legacy_query()` 的完整实现和协议细节。
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
- `BETA
|
|
96
|
+
*自 Minecraft 1.4 起可用*
|
|
97
|
+
- `BETA`:第一个 SLP 协议。
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
Minecraft Beta 1.8 到 Release 1.3 使用,是最早的 SLP 协议。
|
|
100
|
+
包含的信息很少,没有服务器版本,仅有 MOTD、最大和在线玩家数。
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
*自 Minecraft Beta 1.8 起可用*
|
|
100
103
|
"""
|
|
101
104
|
|
|
102
105
|
def __str__(self) -> str:
|
|
@@ -104,77 +107,80 @@ class SlpProtocols(Enum):
|
|
|
104
107
|
|
|
105
108
|
ALL = 5
|
|
106
109
|
"""
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
尝试所有协议。
|
|
111
|
+
|
|
112
|
+
尝试使用所有可用协议连接到远程服务器,直到收到可接受的响应或失败为止。
|
|
113
|
+
"""
|
|
109
114
|
|
|
110
115
|
QUERY = 6
|
|
111
116
|
"""
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
用于 Minecraft Java 服务器的 Query / GameSpot4 / UT3 协议。
|
|
118
|
+
需要在 Minecraft 服务器上启用。
|
|
114
119
|
|
|
115
|
-
|
|
120
|
+
Query 类似于 SLP,但会返回更多技术相关的数据。
|
|
116
121
|
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
*自 Minecraft 1.9 起可用*
|
|
123
|
+
"""
|
|
119
124
|
|
|
120
125
|
BEDROCK_RAKNET = 4
|
|
121
126
|
"""
|
|
122
|
-
|
|
127
|
+
Minecraft 基岩版/教育版协议。
|
|
123
128
|
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
目前为实验性支持。
|
|
130
|
+
"""
|
|
126
131
|
|
|
127
132
|
JSON = 3
|
|
128
133
|
"""
|
|
129
|
-
|
|
134
|
+
最新且当前支持的 SLP 协议。
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
使用(包装的)JSON 作为负载。复杂查询,详见 `json_query()` 的协议实现。
|
|
132
137
|
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
*自 Minecraft 1.7 起可用*
|
|
139
|
+
"""
|
|
135
140
|
|
|
136
141
|
EXTENDED_LEGACY = 2
|
|
137
|
-
"""
|
|
142
|
+
"""
|
|
143
|
+
上一代 SLP 协议
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
Minecraft 1.6 使用,所有新版本服务器仍兼容。
|
|
146
|
+
需要复杂查询,详见 `extended_legacy_query()` 的完整协议细节。
|
|
141
147
|
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
*自 Minecraft 1.6 起可用*
|
|
149
|
+
"""
|
|
144
150
|
|
|
145
151
|
LEGACY = 1
|
|
146
152
|
"""
|
|
147
|
-
|
|
153
|
+
传统 SLP 协议。
|
|
148
154
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
Minecraft 1.4 和 1.5 使用,是第一个包含服务器版本号的协议。
|
|
156
|
+
非常简单的协议调用(2 字节),简单的响应解码。
|
|
157
|
+
详见 `legacy_query()` 的完整实现和协议细节。
|
|
152
158
|
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
*自 Minecraft 1.4 起可用*
|
|
160
|
+
"""
|
|
155
161
|
|
|
156
162
|
BETA = 0
|
|
157
163
|
"""
|
|
158
|
-
|
|
164
|
+
第一个 SLP 协议。
|
|
159
165
|
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
Minecraft Beta 1.8 到 Release 1.3 使用,是最早的 SLP 协议。
|
|
167
|
+
包含的信息很少,没有服务器版本,仅有 MOTD、最大和在线玩家数。
|
|
162
168
|
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
*自 Minecraft Beta 1.8 起可用*
|
|
170
|
+
"""
|
|
165
171
|
|
|
166
172
|
|
|
167
173
|
class MineStat:
|
|
168
|
-
VERSION = "2.6.
|
|
169
|
-
"""
|
|
174
|
+
VERSION = "2.6.4@molanp"
|
|
175
|
+
"""MineStat 版本"""
|
|
170
176
|
DEFAULT_TCP_PORT = 25565
|
|
171
|
-
"""
|
|
177
|
+
"""SLP 查询的默认 TCP 端口"""
|
|
172
178
|
DEFAULT_BEDROCK_PORT_V4 = 19132
|
|
173
|
-
"""
|
|
179
|
+
"""Bedrock/MCPE IPv4 服务器的默认 UDP 端口"""
|
|
174
180
|
DEFAULT_BEDROCK_PORT_V6 = 19133
|
|
175
|
-
"""
|
|
181
|
+
"""Bedrock/MCPE IPv6 服务器的默认 UDP 端口"""
|
|
176
182
|
DEFAULT_TIMEOUT = 5
|
|
177
|
-
"""
|
|
183
|
+
"""默认 TCP 超时时间(秒)"""
|
|
178
184
|
|
|
179
185
|
def __init__(
|
|
180
186
|
self,
|
|
@@ -186,27 +192,25 @@ class MineStat:
|
|
|
186
192
|
use_ipv6: bool = False,
|
|
187
193
|
) -> None:
|
|
188
194
|
"""
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
:param address:
|
|
192
|
-
:param port:
|
|
193
|
-
:param timeout:
|
|
194
|
-
:param query_protocol:
|
|
195
|
-
:param refer:
|
|
196
|
-
:param use_ipv6:
|
|
195
|
+
Minecraft 状态检查器,支持 Minecraft Java 版和基岩版/Education/PE 服务器
|
|
196
|
+
|
|
197
|
+
:param address: Minecraft 服务器的 IP 地址。
|
|
198
|
+
:param port: Minecraft 服务器的端口。默认为自动检测
|
|
199
|
+
:param timeout: 每次连接尝试的超时时间。默认为 5 秒。
|
|
200
|
+
:param query_protocol: 使用的协议。详见 minestat.SlpProtocols。默认为ALL
|
|
201
|
+
:param refer: 发送数据包时使用的 IP 来源。默认使用 address。
|
|
202
|
+
:param use_ipv6: 是否使用 IPv6 进行套接字连接。默认为 False。
|
|
197
203
|
"""
|
|
198
204
|
|
|
199
|
-
|
|
200
|
-
|
|
205
|
+
self.refer: str
|
|
206
|
+
"""已发送数据包中 IP 的来源"""
|
|
201
207
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
self.refer = address
|
|
205
|
-
else:
|
|
206
|
-
self.refer = refer
|
|
208
|
+
self.use_ipv6: bool = use_ipv6
|
|
209
|
+
"""是否使用 IPv6 进行套接字连接"""
|
|
207
210
|
|
|
211
|
+
self.refer = address if refer is None else refer
|
|
208
212
|
self.address: str = address
|
|
209
|
-
"""
|
|
213
|
+
"""Minecraft 服务器的 IP 地址"""
|
|
210
214
|
|
|
211
215
|
autoport: bool = False
|
|
212
216
|
if not port:
|
|
@@ -220,53 +224,53 @@ class MineStat:
|
|
|
220
224
|
port = self.DEFAULT_TCP_PORT
|
|
221
225
|
|
|
222
226
|
self.port: int = port
|
|
223
|
-
"""
|
|
227
|
+
"""Minecraft 服务器接受连接的端口号"""
|
|
224
228
|
self.online: bool = False
|
|
225
|
-
"""
|
|
229
|
+
"""在线或离线"""
|
|
226
230
|
self.version: str | None = None
|
|
227
|
-
"""
|
|
231
|
+
"""服务器版本号"""
|
|
228
232
|
self.plugins: list[str] | None = None
|
|
229
|
-
"""
|
|
233
|
+
"""由 Query 协议返回的插件列表,可能为空"""
|
|
230
234
|
self.motd: str | None = None
|
|
231
|
-
"""
|
|
235
|
+
"""当天消息,服务器响应保持不变(包括格式代码/JSON)"""
|
|
232
236
|
self.stripped_motd: str | None = None
|
|
233
|
-
"""
|
|
237
|
+
"""每日消息,已去除所有格式(人类可读)"""
|
|
234
238
|
self.current_players: int | None = None
|
|
235
|
-
"""
|
|
239
|
+
"""当前在线玩家人数"""
|
|
236
240
|
self.max_players: int | None = None
|
|
237
|
-
"""
|
|
241
|
+
"""最大玩家容量"""
|
|
238
242
|
self.player_list: list[str] | None = None
|
|
239
|
-
"""
|
|
243
|
+
"""在线玩家列表,即使`current_players`大于0,也可能为空"""
|
|
240
244
|
self.map: str | None = None
|
|
241
|
-
"""
|
|
245
|
+
"""服务器运行的地图名称,仅由 Query 和 Bedrock 协议支持"""
|
|
242
246
|
self.latency: int | None = None
|
|
243
|
-
"""
|
|
247
|
+
"""到服务器的延迟时间(毫秒)"""
|
|
244
248
|
self.timeout: int = timeout
|
|
245
|
-
"""
|
|
249
|
+
"""套接字超时"""
|
|
246
250
|
self.slp_protocol: SlpProtocols | None = None
|
|
247
|
-
"""
|
|
251
|
+
"""服务器列表 ping 协议"""
|
|
248
252
|
self.protocol_version: int | None = None
|
|
249
|
-
"""
|
|
253
|
+
"""服务器协议版本"""
|
|
250
254
|
self.favicon_b64: str | None = None
|
|
251
|
-
"""
|
|
255
|
+
"""可能包含在 JSON 1.7 响应中的 base64 编码图标"""
|
|
252
256
|
self.favicon: str | None = None
|
|
253
|
-
"""
|
|
257
|
+
"""解码后的网站图标数据"""
|
|
254
258
|
self.gamemode: str | None = None
|
|
255
|
-
"""
|
|
256
|
-
self.srv_record: bool | None = None
|
|
257
|
-
"""wether the server has a SRV record"""
|
|
259
|
+
"""基岩版特有:当前游戏模式(Creative/Survival/Adventure))"""
|
|
258
260
|
self.connection_status: ConnStatus | None = None
|
|
259
|
-
"""
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
267
|
-
#
|
|
268
|
-
|
|
269
|
-
#
|
|
261
|
+
"""连接状态 ("SUCCESS", "CONNFAIL", "TIMEOUT", 或 "UNKNOWN")"""
|
|
262
|
+
self.edition: str | None = None
|
|
263
|
+
"""基岩版特有:服务器类型(MCPE/MCEE)"""
|
|
264
|
+
|
|
265
|
+
# 未来改进:IPv4/IPv6,多地址
|
|
266
|
+
# 如果主机有多个IP地址或同时拥有IPv4和IPv6地址,
|
|
267
|
+
# socket.connect 会选择DNS返回的第一个IPv4地址。
|
|
268
|
+
# 如果Minecraft服务器通过IPv4不可用,则会失败并显示“离线”。
|
|
269
|
+
# 或者在某些环境中,DNS返回外部地址和内部地址,
|
|
270
|
+
# 但从内部客户端只能访问内部地址。
|
|
271
|
+
# 详见 https://docs.python.org/3/library/socket.html#socket.getaddrinfo
|
|
272
|
+
|
|
273
|
+
# 如果用户希望使用特定协议,仅使用该协议。
|
|
270
274
|
result = ConnStatus.UNKNOWN
|
|
271
275
|
if query_protocol is not SlpProtocols.ALL:
|
|
272
276
|
if query_protocol is SlpProtocols.BETA:
|
|
@@ -285,11 +289,10 @@ class MineStat:
|
|
|
285
289
|
|
|
286
290
|
return
|
|
287
291
|
|
|
288
|
-
#
|
|
289
|
-
#
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
# A legacy query alone works fine.
|
|
292
|
+
# 注意:此处 Java 版本的顺序不幸地非常重要。
|
|
293
|
+
# 某些较老的 MC 版本在接收到无法识别的数据包后的几秒钟内不接受新的数据包。
|
|
294
|
+
# 例如 MC 1.4:在发送 JSON 请求后,任何操作都不能立即生效。
|
|
295
|
+
# 单独的传统查询则可以正常工作。
|
|
293
296
|
|
|
294
297
|
# Minecraft Bedrock/Pocket/Education Edition (MCPE/MCEE)
|
|
295
298
|
if autoport and not self.port:
|
|
@@ -327,10 +330,10 @@ class MineStat:
|
|
|
327
330
|
@staticmethod
|
|
328
331
|
def motd_strip_formatting(raw_motd: str | dict) -> str:
|
|
329
332
|
"""
|
|
330
|
-
|
|
331
|
-
|
|
333
|
+
用于去除 MOTD 中所有格式代码的函数。
|
|
334
|
+
支持 JSON 聊天组件(以字典形式)以及旧版格式代码
|
|
332
335
|
|
|
333
|
-
:param raw_motd:
|
|
336
|
+
:param raw_motd: 原始 MOTD,可以是字符串或字典
|
|
334
337
|
"""
|
|
335
338
|
stripped_motd = ""
|
|
336
339
|
|
|
@@ -348,13 +351,13 @@ class MineStat:
|
|
|
348
351
|
|
|
349
352
|
def bedrock_raknet_query(self) -> ConnStatus:
|
|
350
353
|
"""
|
|
351
|
-
|
|
352
|
-
|
|
354
|
+
用于查询基岩版服务器(Minecraft PE、Windows 10 或教育版)的方法。
|
|
355
|
+
该协议基于 RakNet 协议。
|
|
353
356
|
|
|
354
|
-
|
|
357
|
+
详见 https://wiki.vg/Raknet_Protocol#Unconnected_Ping
|
|
355
358
|
|
|
356
|
-
|
|
357
|
-
|
|
359
|
+
注意:此方法目前的实现假设连接通过 TCP 处理(即假定不会发生数据包丢失)。
|
|
360
|
+
应实现数据包丢失处理(如重发机制)。
|
|
358
361
|
"""
|
|
359
362
|
|
|
360
363
|
RAKNET_MAGIC = bytearray(
|
|
@@ -404,8 +407,8 @@ class MineStat:
|
|
|
404
407
|
# 16 byte - magic
|
|
405
408
|
# short - Server ID string length
|
|
406
409
|
# string - Server ID string
|
|
410
|
+
start_time = perf_counter() # 记录发送时间
|
|
407
411
|
try:
|
|
408
|
-
start_time = perf_counter() # 记录发送时间
|
|
409
412
|
sock.connect((self.address, self.port))
|
|
410
413
|
sock.send(req_data)
|
|
411
414
|
|
|
@@ -475,43 +478,29 @@ class MineStat:
|
|
|
475
478
|
|
|
476
479
|
self.current_players = int(payload["current_players"])
|
|
477
480
|
self.max_players = int(payload["max_players"])
|
|
478
|
-
|
|
479
|
-
self.version = (
|
|
480
|
-
payload["version"]
|
|
481
|
-
+ " "
|
|
482
|
-
+ payload["motd_2"]
|
|
483
|
-
+ " ("
|
|
484
|
-
+ payload["edition"]
|
|
485
|
-
+ ")"
|
|
486
|
-
)
|
|
487
|
-
except (
|
|
488
|
-
KeyError
|
|
489
|
-
): # older Bedrock server versions do not respond with the secondary MotD.
|
|
490
|
-
self.version = payload["version"] + " (" + payload["edition"] + ")"
|
|
491
|
-
|
|
481
|
+
self.version = payload["version"]
|
|
492
482
|
self.motd = payload["motd_1"]
|
|
483
|
+
# 旧版 Bedrock 服务器不会用第二条服务器信息(MotD)进行响应。
|
|
484
|
+
self.map = payload.get("motd_2")
|
|
485
|
+
self.edition = payload["edition"]
|
|
493
486
|
self.stripped_motd = self.motd_strip_formatting(self.motd)
|
|
494
487
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
except (
|
|
498
|
-
KeyError
|
|
499
|
-
): # older Bedrock server versions do not respond with the game mode.
|
|
500
|
-
self.gamemode = None
|
|
488
|
+
# 旧版 Bedrock 服务器不会返回游戏模式。
|
|
489
|
+
self.gamemode = payload.get("gamemode")
|
|
501
490
|
|
|
502
491
|
return ConnStatus.SUCCESS
|
|
503
492
|
|
|
504
493
|
def fullstat_query(self) -> ConnStatus:
|
|
505
494
|
"""
|
|
506
|
-
|
|
507
|
-
|
|
495
|
+
用于通过 fullstat Query / GameSpot4 / UT3 协议
|
|
496
|
+
查询 Minecraft Java 版服务器的方法
|
|
497
|
+
需要在 Minecraft 服务器上启用此功能,
|
|
498
|
+
方法是在服务器的 "server.properties" 文件中添加以下配置:
|
|
508
499
|
|
|
509
|
-
|
|
500
|
+
`enable-query=true`
|
|
510
501
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
This method ONLY supports full stat querys.
|
|
514
|
-
Documentation for this protocol: https://wiki.vg/Query
|
|
502
|
+
该方法仅支持完整的状态查询。
|
|
503
|
+
协议文档详见:https://wiki.vg/Query
|
|
515
504
|
"""
|
|
516
505
|
# protocol:
|
|
517
506
|
# send handshake request
|
|
@@ -521,7 +510,7 @@ class MineStat:
|
|
|
521
510
|
|
|
522
511
|
# Create UDP socket and set timeout
|
|
523
512
|
if self.use_ipv6:
|
|
524
|
-
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM
|
|
513
|
+
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
|
525
514
|
else:
|
|
526
515
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
527
516
|
sock.settimeout(self.timeout)
|
|
@@ -596,11 +585,11 @@ class MineStat:
|
|
|
596
585
|
|
|
597
586
|
def __parse_query_payload(self, raw_res) -> ConnStatus:
|
|
598
587
|
"""
|
|
599
|
-
|
|
588
|
+
用于解析 Query 请求响应的辅助方法。
|
|
600
589
|
|
|
601
|
-
|
|
590
|
+
详见 https://wiki.vg/Query 获取详细信息。
|
|
602
591
|
|
|
603
|
-
|
|
592
|
+
此实现并未解析 Query 协议返回的所有值。
|
|
604
593
|
"""
|
|
605
594
|
try:
|
|
606
595
|
self.__extracted_from___parse_query_payload_11(raw_res)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="stylesheet" href="main.css" />
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
+
<title>Template</title>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<div class="server-form">
|
|
13
|
+
<img
|
|
14
|
+
class="favicon"
|
|
15
|
+
src="{{ data['favicon'] }}"
|
|
16
|
+
alt="Fail to load the favicon."
|
|
17
|
+
/>
|
|
18
|
+
<div class="content">
|
|
19
|
+
<label> {{ data["lang"]["version"] }}{{ data["version"] }} </label>
|
|
20
|
+
<label> {{ data["lang"]["motd"] }}{{ data["motd"]|safe }} </label>
|
|
21
|
+
<label>
|
|
22
|
+
{{ data["lang"]["slp_protocol"] }}{{ data["slp_protocol"] }}
|
|
23
|
+
</label>
|
|
24
|
+
{% if data["protocol_version"] is not none %}
|
|
25
|
+
<label>
|
|
26
|
+
{{ data["lang"]["protocol_version"] }}{{ data["protocol_version"]}}
|
|
27
|
+
</label>
|
|
28
|
+
{% endif %}
|
|
29
|
+
<label> {{ data["lang"]["address"] }}{{ data["address"] }} </label>
|
|
30
|
+
<label> {{ data["lang"]["ip"] }}{{ data["ip"] }} </label>
|
|
31
|
+
<label> {{ data["lang"]["port"] }}{{ data["port"] }} </label>
|
|
32
|
+
<label> {{ data["lang"]["delay"] }}{{ data["delay"]}} </label>
|
|
33
|
+
{% if 'BEDROCK' in data["slp_protocol"] %}
|
|
34
|
+
<label>{{ data["lang"]["gamemode"] }}{{ data["gamemode"] }}</label>
|
|
35
|
+
{% endif %}
|
|
36
|
+
<label> {{ data["lang"]["players"] }}{{ data["players"] }} </label>
|
|
37
|
+
{% if data["player_list"] is not none %}
|
|
38
|
+
<label>
|
|
39
|
+
{{ data["lang"]["player_list"] }}{{ data["player_list"] }}
|
|
40
|
+
</label>
|
|
41
|
+
{% endif %}
|
|
42
|
+
</div>
|
|
43
|
+
<div class="watermark">
|
|
44
|
+
nonebot_plugin_mccheck v{{ data["VERSION"] }} by molanp.
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|
{nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/utils.py
RENAMED
|
@@ -4,6 +4,7 @@ import contextlib
|
|
|
4
4
|
import os
|
|
5
5
|
import re
|
|
6
6
|
import traceback
|
|
7
|
+
from typing import Literal
|
|
7
8
|
|
|
8
9
|
import dns.asyncresolver
|
|
9
10
|
import dns.exception
|
|
@@ -21,13 +22,13 @@ from nonebot_plugin_alconna import Image, SupportScope, Text
|
|
|
21
22
|
from nonebot_plugin_uninfo import Uninfo
|
|
22
23
|
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
def handle_exception(e):
|
|
25
26
|
error_message = str(e)
|
|
26
27
|
logger.error(traceback.format_exc())
|
|
27
28
|
return Text(f"[CrashHandle]{error_message}\n>>更多信息详见日志文件<<")
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
def change_language_to(language: str):
|
|
31
32
|
global lang
|
|
32
33
|
|
|
33
34
|
try:
|
|
@@ -41,21 +42,19 @@ async def change_language_to(language: str):
|
|
|
41
42
|
return f"Change to '{language}' success!"
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
async def build_result(
|
|
45
|
+
async def build_result(
|
|
46
|
+
ms: MineStat, address: str, type: int = 0
|
|
47
|
+
) -> list[Image | Text]:
|
|
45
48
|
"""
|
|
46
49
|
根据类型构建并返回查询结果。
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- type: 结果类型,决定返回结果的格式,默认为0。
|
|
51
|
-
|
|
52
|
-
返回:
|
|
53
|
-
- 根据类型不同返回不同格式的查询结果。
|
|
51
|
+
:params ms: 包含服务器信息的对象。
|
|
52
|
+
:params type: 结果类型,决定返回结果的格式,默认为0。
|
|
54
53
|
"""
|
|
55
54
|
if type == 0:
|
|
56
55
|
result = {
|
|
57
56
|
"favicon": ms.favicon_b64 if ms.favicon else "no_favicon.png",
|
|
58
|
-
"version":
|
|
57
|
+
"version": parse_motd2html(ms.version),
|
|
59
58
|
"slp_protocol": str(ms.slp_protocol),
|
|
60
59
|
"protocol_version": ms.protocol_version,
|
|
61
60
|
"address": address,
|
|
@@ -63,16 +62,15 @@ async def build_result(ms, address, type=0):
|
|
|
63
62
|
"port": ms.port,
|
|
64
63
|
"delay": f"{ms.latency}ms",
|
|
65
64
|
"gamemode": ms.gamemode,
|
|
66
|
-
"motd":
|
|
65
|
+
"motd": parse_motd2html(ms.motd),
|
|
67
66
|
"players": f"{ms.current_players}/{ms.max_players}",
|
|
68
67
|
"player_list": (
|
|
69
|
-
|
|
70
|
-
if ms.player_list
|
|
71
|
-
else None
|
|
68
|
+
parse_motd2html("§r, ".join(ms.player_list)) if ms.player_list else None
|
|
72
69
|
),
|
|
73
70
|
"lang": lang_data[lang],
|
|
74
71
|
"VERSION": VERSION,
|
|
75
72
|
}
|
|
73
|
+
require("nonebot_plugin_htmlrender")
|
|
76
74
|
from nonebot_plugin_htmlrender import template_to_pic
|
|
77
75
|
|
|
78
76
|
template_dir = os.path.join(os.path.dirname(__file__), "templates")
|
|
@@ -81,7 +79,7 @@ async def build_result(ms, address, type=0):
|
|
|
81
79
|
template_name="default.html",
|
|
82
80
|
templates={"data": result},
|
|
83
81
|
)
|
|
84
|
-
return Image(raw=pic)
|
|
82
|
+
return [Image(raw=pic)]
|
|
85
83
|
else:
|
|
86
84
|
motd_part = f"\n{lang_data[lang]['motd']}{ms.stripped_motd}"
|
|
87
85
|
version_part = f"\n{lang_data[lang]['version']}{ms.version}"
|
|
@@ -104,43 +102,39 @@ async def build_result(ms, address, type=0):
|
|
|
104
102
|
+ motd_part
|
|
105
103
|
+ f"\n{lang_data[lang]['players']}{ms.current_players}/{ms.max_players}"
|
|
106
104
|
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
105
|
+
result += (
|
|
106
|
+
f"\n{lang_data[lang]['player_list']}{', '.join(ms.player_list)}"
|
|
107
|
+
if ms.player_list
|
|
108
|
+
else ""
|
|
109
|
+
)
|
|
110
|
+
return (
|
|
111
|
+
[
|
|
112
|
+
Text(result),
|
|
113
|
+
Text("\nFavicon:"),
|
|
114
|
+
Image(raw=base64.b64decode(ms.favicon_b64.split(",")[1])),
|
|
115
|
+
]
|
|
116
|
+
if ms.favicon and ms.favicon_b64
|
|
117
|
+
else [Text(result)]
|
|
118
|
+
)
|
|
122
119
|
|
|
123
120
|
|
|
124
121
|
async def get_mc(
|
|
125
|
-
ip, port, ip_type, refer, timeout: int = 5
|
|
122
|
+
ip: str, port: int, ip_type: str, refer, timeout: int = 5
|
|
126
123
|
) -> list[tuple[MineStat | None, ConnStatus | None]]:
|
|
127
124
|
"""
|
|
128
125
|
获取Java版和Bedrock版的MC服务器信息。
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- timeout (int): 请求超时时间,默认为5秒。
|
|
127
|
+
:params ip: 服务器的IP地址。
|
|
128
|
+
:params port: 服务器的端口。
|
|
129
|
+
:params ip_type: 服务器的IP类型。
|
|
130
|
+
:params refer: 服务器来源地址
|
|
131
|
+
:params timeout: 请求超时时间,默认为5秒。
|
|
136
132
|
|
|
137
133
|
返回:
|
|
138
134
|
- list: 包含Java版和Bedrock版服务器信息的列表。
|
|
139
135
|
"""
|
|
140
136
|
if ip_type.startswith("SRV"):
|
|
141
|
-
return [
|
|
142
|
-
await asyncio.to_thread(get_java, ip, port, ip_type, refer, timeout)
|
|
143
|
-
]
|
|
137
|
+
return [await asyncio.to_thread(get_java, ip, port, ip_type, refer, timeout)]
|
|
144
138
|
|
|
145
139
|
return list(
|
|
146
140
|
await asyncio.gather(
|
|
@@ -150,17 +144,17 @@ async def get_mc(
|
|
|
150
144
|
)
|
|
151
145
|
|
|
152
146
|
|
|
153
|
-
async def get_message_list(
|
|
147
|
+
async def get_message_list(
|
|
148
|
+
ip: str, port: int, timeout: int = 5
|
|
149
|
+
) -> list[list[Text | Image]]:
|
|
154
150
|
"""
|
|
155
|
-
|
|
151
|
+
根据IP和端口获取消息列表。
|
|
156
152
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
- timeout (int, 可选): 超时时间,默认为5秒。
|
|
153
|
+
:params ip: 服务器的IP地址。
|
|
154
|
+
:params port: 服务器的端口。
|
|
155
|
+
:params timeout: 超时时间,默认为5秒。
|
|
161
156
|
|
|
162
|
-
|
|
163
|
-
- list: 包含消息的列表。
|
|
157
|
+
:returns: 包含消息的列表。
|
|
164
158
|
"""
|
|
165
159
|
ip_groups = await get_origin_address(ip, port)
|
|
166
160
|
messages = []
|
|
@@ -194,17 +188,17 @@ def get_bedrock(
|
|
|
194
188
|
host: str, port: int, ip_type: str, refer: str, timeout: int = 5
|
|
195
189
|
) -> tuple[MineStat | None, ConnStatus | None]:
|
|
196
190
|
"""
|
|
197
|
-
|
|
191
|
+
通过指定的主机名、端口和超时时间获取Minecraft Bedrock版服务器状态。
|
|
198
192
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
- timeout: 连接超时时间,默认为5秒。
|
|
193
|
+
:params host: 服务器的主机名。
|
|
194
|
+
:params port: 服务器的端口号。
|
|
195
|
+
:params ip_type: 服务器地址类型。
|
|
196
|
+
:params refer: 服务器地址来源。
|
|
197
|
+
:params timeout: 连接超时时间,默认为5秒。
|
|
205
198
|
|
|
206
|
-
|
|
207
|
-
- MineStat
|
|
199
|
+
:returns:
|
|
200
|
+
- MineStat实例,包含服务器状态信息,如果服务器不在线返回None。
|
|
201
|
+
- ConnStatus实例,包含服务器连接状态,如果服务器不在线返回None。
|
|
208
202
|
"""
|
|
209
203
|
v6 = "IPv6" in ip_type
|
|
210
204
|
result = MineStat(host, port, timeout, SlpProtocols.BEDROCK_RAKNET, refer, v6)
|
|
@@ -218,17 +212,17 @@ def get_java(
|
|
|
218
212
|
host: str, port: int, ip_type: str, refer: str, timeout: int = 5
|
|
219
213
|
) -> tuple[MineStat | None, ConnStatus | None]:
|
|
220
214
|
"""
|
|
221
|
-
|
|
215
|
+
通过指定的主机名、端口和超时时间获取Minecraft Java版服务器状态。
|
|
222
216
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
- timeout: 连接超时时间,默认为5秒。
|
|
217
|
+
:params host: 服务器的主机名。
|
|
218
|
+
:params port: 服务器的端口号。
|
|
219
|
+
:params ip_type: 服务器地址类型。
|
|
220
|
+
:params refer: 服务器地址来源。
|
|
221
|
+
:params timeout: 连接超时时间,默认为5秒。
|
|
229
222
|
|
|
230
|
-
|
|
231
|
-
- MineStat
|
|
223
|
+
:returns:
|
|
224
|
+
- MineStat实例,包含服务器状态信息,如果服务器不在线返回None。
|
|
225
|
+
- ConnStatus实例,包含服务器连接状态,如果服务器不在线返回None。
|
|
232
226
|
"""
|
|
233
227
|
v6 = "IPv6" in ip_type
|
|
234
228
|
|
|
@@ -256,20 +250,18 @@ def get_java(
|
|
|
256
250
|
return None, result.connection_status
|
|
257
251
|
|
|
258
252
|
|
|
259
|
-
async def parse_host(host_name) -> tuple[str, int]:
|
|
253
|
+
async def parse_host(host_name: str) -> tuple[str, int]:
|
|
260
254
|
"""
|
|
261
255
|
解析主机名(可选端口)。
|
|
262
256
|
|
|
263
257
|
该函数尝试从主机名中提取IP地址和端口号。如果主机名中未指定端口,
|
|
264
258
|
则默认端口号为0。
|
|
265
259
|
|
|
266
|
-
|
|
267
|
-
host_name (str): 主机名,可能包含端口。
|
|
260
|
+
:params host_name: 主机名,可能包含端口。
|
|
268
261
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
-
|
|
272
|
-
- 第二个元素是主机的端口号(整数形式),如果主机名中未指定端口,则为0。
|
|
262
|
+
:returns: 一个元组,包含两个元素:
|
|
263
|
+
- 第一个元素是主机的地址
|
|
264
|
+
- 第二个元素是主机的端口号,如果主机名中未指定端口,则为0。
|
|
273
265
|
"""
|
|
274
266
|
pattern = r"(?:\[(.+?)\]|(.+?))(?:[::](\d+))?$"
|
|
275
267
|
if not (match := re.match(pattern, host_name)):
|
|
@@ -283,33 +275,25 @@ async def parse_host(host_name) -> tuple[str, int]:
|
|
|
283
275
|
return address, port
|
|
284
276
|
|
|
285
277
|
|
|
286
|
-
|
|
278
|
+
def is_validity_address(address: str) -> bool:
|
|
287
279
|
"""
|
|
288
|
-
|
|
280
|
+
判断给定的地址是否为有效的域名或IP地址。
|
|
289
281
|
|
|
290
|
-
|
|
291
|
-
address (str): 需要验证的地址,可以是域名地址或IP地址。
|
|
282
|
+
:params address: 需要验证的地址,可以是域名地址或IP地址。
|
|
292
283
|
|
|
293
|
-
|
|
294
|
-
bool: 如果地址有效则返回True,否则返回False。
|
|
284
|
+
:returns: 如果地址有效则返回True,否则返回False。
|
|
295
285
|
"""
|
|
296
286
|
|
|
297
|
-
return (
|
|
298
|
-
(await is_domain(address))
|
|
299
|
-
or (await is_ipv4(address))
|
|
300
|
-
or (await is_ipv6(address))
|
|
301
|
-
)
|
|
287
|
+
return (is_domain(address)) or (is_ipv4(address)) or (is_ipv6(address))
|
|
302
288
|
|
|
303
289
|
|
|
304
|
-
|
|
290
|
+
def is_domain(address: str) -> bool:
|
|
305
291
|
"""
|
|
306
292
|
判断给定的地址是否为域名。
|
|
307
293
|
|
|
308
|
-
|
|
309
|
-
address (str): 需要验证的地址。
|
|
294
|
+
:params address: 需要验证的地址。
|
|
310
295
|
|
|
311
|
-
|
|
312
|
-
bool: 如果地址为域名则返回True,否则返回False。
|
|
296
|
+
:returns: 如果地址为域名则返回True,否则返回False。
|
|
313
297
|
"""
|
|
314
298
|
try:
|
|
315
299
|
punycode_address = idna.encode(address).decode("utf-8")
|
|
@@ -322,15 +306,13 @@ async def is_domain(address: str) -> bool:
|
|
|
322
306
|
return bool(domain_pattern.match(punycode_address))
|
|
323
307
|
|
|
324
308
|
|
|
325
|
-
|
|
309
|
+
def is_ipv4(address: str) -> bool:
|
|
326
310
|
"""
|
|
327
311
|
判断给定的地址是否为IPv4地址。
|
|
328
312
|
|
|
329
|
-
|
|
330
|
-
address (str): 需要验证的地址。
|
|
313
|
+
:params address: 需要验证的地址。
|
|
331
314
|
|
|
332
|
-
|
|
333
|
-
bool: 如果地址为IPv4地址则返回True,否则返回False。
|
|
315
|
+
:returns: 如果地址为IPv4地址则返回True,否则返回False。
|
|
334
316
|
"""
|
|
335
317
|
ipv4_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
|
|
336
318
|
match_ipv4 = ipv4_pattern.match(address)
|
|
@@ -342,15 +324,13 @@ async def is_ipv4(address: str) -> bool:
|
|
|
342
324
|
return not any(not part.isdigit() or not 0 <= int(part) <= 255 for part in parts)
|
|
343
325
|
|
|
344
326
|
|
|
345
|
-
|
|
327
|
+
def is_ipv6(address: str) -> bool:
|
|
346
328
|
"""
|
|
347
329
|
判断给定的地址是否为IPv6地址。
|
|
348
330
|
|
|
349
|
-
|
|
350
|
-
address (str): 需要验证的地址。
|
|
331
|
+
:params address: 需要验证的地址。
|
|
351
332
|
|
|
352
|
-
|
|
353
|
-
bool: 如果地址为IPv6地址则返回True,否则返回False。
|
|
333
|
+
:returns: 如果地址为IPv6地址则返回True,否则返回False。
|
|
354
334
|
"""
|
|
355
335
|
ipv6_pattern = re.compile(
|
|
356
336
|
r"^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$"
|
|
@@ -360,12 +340,13 @@ async def is_ipv6(address: str) -> bool:
|
|
|
360
340
|
return bool(match_ipv6)
|
|
361
341
|
|
|
362
342
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
343
|
+
def get_ip_type(address: str) -> Literal["IPv4", "IPv6", "Domain"]:
|
|
344
|
+
"""获取地址类型"""
|
|
345
|
+
if not is_validity_address(address):
|
|
346
|
+
raise ValueError("Invalid address")
|
|
347
|
+
if is_ipv4(address):
|
|
367
348
|
return "IPv4"
|
|
368
|
-
elif
|
|
349
|
+
elif is_ipv6(address):
|
|
369
350
|
return "IPv6"
|
|
370
351
|
else:
|
|
371
352
|
return "Domain"
|
|
@@ -373,25 +354,24 @@ async def get_ip_type(address: str) -> str:
|
|
|
373
354
|
|
|
374
355
|
async def get_origin_address(
|
|
375
356
|
domain: str, ip_port: int = 0, is_resolve_srv=True
|
|
376
|
-
) -> list[tuple[str, int,
|
|
357
|
+
) -> list[tuple[str, int, Literal["IPv4", "IPv6", "SRV", "SRV-IPv4", "SRV-IPv6"], str]]:
|
|
377
358
|
"""
|
|
378
359
|
获取地址所解析的A或AAAA记录,如果传入不是域名直接返回。
|
|
379
360
|
同时返回地址是IPv6还是IPv4。
|
|
380
361
|
如果地址是域名,首先尝试解析SRV记录。
|
|
381
362
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
- is_resolve_srv (bool): 师是否解析SRV,默认True
|
|
363
|
+
:params domain: 需要解析的地址。
|
|
364
|
+
:params ip_port: 适用于IPv4和IPv6地址的默认端口号。
|
|
365
|
+
:params is_resolve_srv: 是否解析SRV,默认True
|
|
386
366
|
|
|
387
367
|
返回:
|
|
388
|
-
|
|
389
|
-
-
|
|
390
|
-
-
|
|
391
|
-
-
|
|
368
|
+
:returns: 一个列表,包含一个元组,元组包含四个元素:
|
|
369
|
+
- 第一个元素是解析后的IP地址
|
|
370
|
+
- 第二个元素是地址的端口号
|
|
371
|
+
- 第三个元素是地址的类型
|
|
392
372
|
- 第四个元素是解析地址的来源域名或IP
|
|
393
373
|
"""
|
|
394
|
-
ip_type =
|
|
374
|
+
ip_type = get_ip_type(domain)
|
|
395
375
|
try:
|
|
396
376
|
refer_domain = idna.encode(domain).decode("utf-8")
|
|
397
377
|
except idna.IDNAError:
|
|
@@ -417,7 +397,7 @@ async def get_origin_address(
|
|
|
417
397
|
for rdata in srv_response:
|
|
418
398
|
srv_address = str(rdata.target).rstrip(".") # type: ignore
|
|
419
399
|
srv_port = rdata.port # type: ignore
|
|
420
|
-
ip_type =
|
|
400
|
+
ip_type = get_ip_type(srv_address)
|
|
421
401
|
try:
|
|
422
402
|
srv_refer = idna.encode(srv_address).decode("utf-8")
|
|
423
403
|
except idna.IDNAError:
|
|
@@ -441,8 +421,7 @@ async def get_origin_address(
|
|
|
441
421
|
)
|
|
442
422
|
if not any(
|
|
443
423
|
entry[0] == srv_data[0]
|
|
444
|
-
and entry[1] == srv_data[1]
|
|
445
|
-
and entry[2].replace("SRV-", "") == srv_data[2].replace("SRV-", "")
|
|
424
|
+
and (entry[1] == srv_data[1] or srv_data[1] == 25565)
|
|
446
425
|
for entry in data
|
|
447
426
|
):
|
|
448
427
|
data.append(srv_data)
|
|
@@ -480,18 +459,16 @@ async def get_origin_address(
|
|
|
480
459
|
return data
|
|
481
460
|
|
|
482
461
|
|
|
483
|
-
|
|
462
|
+
def parse_motd2html(data: str | None) -> str:
|
|
484
463
|
"""
|
|
485
464
|
解析MOTD数据并转换为带有自定义颜色的HTML字符串。
|
|
486
465
|
|
|
487
|
-
|
|
488
|
-
- data (str|None): MOTD数据。
|
|
466
|
+
:params data: MOTD数据。
|
|
489
467
|
|
|
490
|
-
|
|
491
|
-
- str | None: 带有自定义颜色的HTML字符串。
|
|
468
|
+
:returns: 带有自定义颜色的HTML字符串。
|
|
492
469
|
"""
|
|
493
|
-
if data
|
|
494
|
-
return
|
|
470
|
+
if not data:
|
|
471
|
+
return ""
|
|
495
472
|
|
|
496
473
|
standard_color_map = {
|
|
497
474
|
"black": ('<span style="color:#000000;">', "</span>"),
|
|
@@ -547,7 +524,7 @@ async def parse_motd2html(data: str | None) -> str | None:
|
|
|
547
524
|
"§u": ('<span style="color:#9A5CC6;">', "</span>"), # material amethyst
|
|
548
525
|
}
|
|
549
526
|
|
|
550
|
-
|
|
527
|
+
def parse_text_motd(text: str) -> str:
|
|
551
528
|
result = ""
|
|
552
529
|
i = 0
|
|
553
530
|
styles = []
|
|
@@ -582,19 +559,19 @@ async def parse_motd2html(data: str | None) -> str | None:
|
|
|
582
559
|
|
|
583
560
|
return result
|
|
584
561
|
|
|
585
|
-
|
|
562
|
+
def parse_json_motd(json, styles=[]) -> str:
|
|
586
563
|
result = ""
|
|
587
564
|
if isinstance(json, dict) and "extra" in json:
|
|
588
565
|
for key in json:
|
|
589
566
|
if key == "extra":
|
|
590
|
-
result +=
|
|
567
|
+
result += parse_json_motd(json[key], styles)
|
|
591
568
|
elif key == "text":
|
|
592
|
-
result +=
|
|
569
|
+
result += parse_json_motd(json[key], styles)
|
|
593
570
|
elif isinstance(json, dict):
|
|
594
571
|
color = json.get("color", "")
|
|
595
572
|
text = json.get("text", "")
|
|
596
573
|
if "§" in text:
|
|
597
|
-
text =
|
|
574
|
+
text = parse_text_motd(text)
|
|
598
575
|
|
|
599
576
|
# 将颜色转换为 HTML 的 font 标签
|
|
600
577
|
if color.startswith("#"):
|
|
@@ -631,7 +608,7 @@ async def parse_motd2html(data: str | None) -> str | None:
|
|
|
631
608
|
result += open_tag + text + close_tag
|
|
632
609
|
elif isinstance(json, list):
|
|
633
610
|
for item in json:
|
|
634
|
-
result +=
|
|
611
|
+
result += parse_json_motd(item, styles)
|
|
635
612
|
else:
|
|
636
613
|
result += str(json)
|
|
637
614
|
return result.replace("\n", "<br>")
|
|
@@ -639,9 +616,9 @@ async def parse_motd2html(data: str | None) -> str | None:
|
|
|
639
616
|
try:
|
|
640
617
|
data = ujson.loads(data)
|
|
641
618
|
except ujson.JSONDecodeError:
|
|
642
|
-
return
|
|
619
|
+
return parse_text_motd(data)
|
|
643
620
|
|
|
644
|
-
return
|
|
621
|
+
return parse_json_motd(data)
|
|
645
622
|
|
|
646
623
|
|
|
647
624
|
def is_qbot(session: Uninfo) -> bool:
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<link rel="stylesheet" href="main.css">
|
|
7
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
9
|
-
<title>Template</title>
|
|
10
|
-
</head>
|
|
11
|
-
|
|
12
|
-
<body>
|
|
13
|
-
<div class="server-form">
|
|
14
|
-
<img class="favicon" src="{{ data['favicon'] }}" alt="Fail to show favicon.">
|
|
15
|
-
<div class="content">
|
|
16
|
-
<label>
|
|
17
|
-
{{ data["lang"]["version"]|safe }}{{ data["version"]|safe }}
|
|
18
|
-
</label>
|
|
19
|
-
<label>
|
|
20
|
-
{{ data["lang"]["motd"]|safe }}{{ data["motd"]|safe }}
|
|
21
|
-
</label>
|
|
22
|
-
<label>
|
|
23
|
-
{{ data["lang"]["slp_protocol"]|safe }}{{ data["slp_protocol"]|safe }}
|
|
24
|
-
</label>
|
|
25
|
-
{% if data["protocol_version"] is not none %}
|
|
26
|
-
<label>{{ data["lang"]["protocol_version"]|safe }}{{ data["protocol_version"]|safe }}</label>
|
|
27
|
-
{% endif %}
|
|
28
|
-
<label>
|
|
29
|
-
{{ data["lang"]["address"]|safe }}{{ data["address"]|safe }}
|
|
30
|
-
</label>
|
|
31
|
-
<label>
|
|
32
|
-
{{ data["lang"]["ip"]|safe }}{{ data["ip"]|safe }}
|
|
33
|
-
</label>
|
|
34
|
-
<label>
|
|
35
|
-
{{ data["lang"]["port"]|safe }}{{ data["port"]|safe }}
|
|
36
|
-
</label>
|
|
37
|
-
<label>
|
|
38
|
-
{{ data["lang"]["delay"]|safe }}{{ data["delay"]|safe}}
|
|
39
|
-
</label>
|
|
40
|
-
{% if 'BEDROCK' in data["slp_protocol"] %}
|
|
41
|
-
<label>{{ data["lang"]["gamemode"]|safe }}{{ data["gamemode"]|safe }}</label>
|
|
42
|
-
{% endif %}
|
|
43
|
-
<label>
|
|
44
|
-
{{ data["lang"]["players"]|safe }}{{ data["players"]|safe }}
|
|
45
|
-
</label>
|
|
46
|
-
{% if data["player_list"] is not none %}
|
|
47
|
-
<label>{{ data["lang"]["player_list"]|safe }}{{ data["player_list"]|safe }}</label>
|
|
48
|
-
{% endif %}
|
|
49
|
-
</div>
|
|
50
|
-
<div class="watermark">
|
|
51
|
-
nonebot_plugin_mccheck v{{ data["VERSION"] }} by molanp.
|
|
52
|
-
</div>
|
|
53
|
-
</div>
|
|
54
|
-
</body>
|
|
55
|
-
|
|
56
|
-
</html>
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/config.py
RENAMED
|
File without changes
|
{nonebot_plugin_mccheck-0.2.0 → nonebot_plugin_mccheck-0.2.3}/nonebot_plugin_mccheck/language.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|