2021-07-27 17:42:47 +00:00
|
|
|
import asyncio
|
2022-12-15 15:58:41 +00:00
|
|
|
import re
|
2021-07-27 17:42:47 +00:00
|
|
|
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.builtins import Bot
|
2023-03-04 08:51:56 +00:00
|
|
|
from core.component import module
|
2021-07-27 17:42:47 +00:00
|
|
|
from core.dirty_check import check
|
|
|
|
from .server import server
|
|
|
|
|
2023-03-04 08:51:56 +00:00
|
|
|
s = module('server', alias='s', developers=['_LittleC_', 'OasisAkari'])
|
2021-07-27 17:42:47 +00:00
|
|
|
|
2021-10-24 10:55:45 +00:00
|
|
|
|
2023-03-14 12:05:42 +00:00
|
|
|
@s.handle('<ServerIP:Port> [-r] [-p] {{server.help}}',
|
2023-05-21 03:48:33 +00:00
|
|
|
options_desc={'-r': '{server.help.option.r}', '-p': '{server.help.option.p}'})
|
2023-02-05 14:33:33 +00:00
|
|
|
async def main(msg: Bot.MessageSession):
|
2021-07-27 17:42:47 +00:00
|
|
|
gather_list = []
|
2022-12-15 15:58:41 +00:00
|
|
|
matchObj = re.match(r'(.*)[\s:](.*)', msg.parsed_msg["<ServerIP:Port>"], re.M | re.I)
|
2023-02-03 13:32:13 +00:00
|
|
|
is_local_ip = False
|
2022-12-15 16:00:33 +00:00
|
|
|
server_address = msg.parsed_msg["<ServerIP:Port>"]
|
2022-12-15 15:58:41 +00:00
|
|
|
if matchObj:
|
2022-12-15 16:00:33 +00:00
|
|
|
server_address = matchObj.group(1)
|
2023-07-04 08:54:59 +00:00
|
|
|
|
2023-02-03 13:32:13 +00:00
|
|
|
if server_address == 'localhost':
|
|
|
|
is_local_ip = True
|
2023-07-04 08:54:59 +00:00
|
|
|
|
2022-12-15 16:00:33 +00:00
|
|
|
matchserip = re.match(r'(.*?)\.(.*?)\.(.*?)\.(.*?)', server_address)
|
|
|
|
if matchserip:
|
2023-04-12 08:25:47 +00:00
|
|
|
if matchserip.group(1) == '192':
|
|
|
|
if matchserip.group(2) == '168':
|
2023-02-03 13:32:13 +00:00
|
|
|
is_local_ip = True
|
2023-04-12 08:25:47 +00:00
|
|
|
if matchserip.group(1) == '172':
|
|
|
|
if 16 <= int(matchserip.group(2)) <= 31:
|
|
|
|
is_local_ip = True
|
|
|
|
if matchserip.group(1) == '10':
|
|
|
|
if 0 <= int(matchserip.group(2)) <= 255:
|
|
|
|
is_local_ip = True
|
|
|
|
if matchserip.group(1) == '127':
|
|
|
|
is_local_ip = True
|
|
|
|
if matchserip.group(1) == '0':
|
|
|
|
if matchserip.group(2) == '0':
|
|
|
|
if matchserip.group(3) == '0':
|
|
|
|
is_local_ip = True
|
2023-02-03 13:32:13 +00:00
|
|
|
if is_local_ip:
|
2023-07-04 08:54:59 +00:00
|
|
|
await msg.finish(msg.locale.t('server.message.error.local_ip'))
|
|
|
|
|
2021-07-27 17:42:47 +00:00
|
|
|
sm = ['j', 'b']
|
|
|
|
for x in sm:
|
2021-11-21 13:20:07 +00:00
|
|
|
gather_list.append(asyncio.ensure_future(s(
|
2022-12-15 15:58:41 +00:00
|
|
|
msg, f'{msg.parsed_msg["<ServerIP:Port>"]}', msg.parsed_msg.get('-r', False), msg.parsed_msg.get('-p', False
|
2023-07-04 08:54:59 +00:00
|
|
|
), x)))
|
2021-07-27 17:42:47 +00:00
|
|
|
g = await asyncio.gather(*gather_list)
|
|
|
|
if g == ['', '']:
|
2023-07-04 08:54:59 +00:00
|
|
|
message = msg.locale.t('server.message.not_found')
|
|
|
|
await msg.finish(message)
|
2022-07-01 14:12:26 +00:00
|
|
|
|
|
|
|
|
2023-07-04 08:54:59 +00:00
|
|
|
async def s(msg: Bot.MessageSession, address, raw, showplayer, mode):
|
2023-03-23 15:25:46 +00:00
|
|
|
sendmsg = await server(msg, address, raw, showplayer, mode)
|
2021-07-27 17:42:47 +00:00
|
|
|
if sendmsg != '':
|
2021-11-01 15:54:12 +00:00
|
|
|
sendmsg = await check(sendmsg)
|
2021-11-12 14:25:53 +00:00
|
|
|
for x in sendmsg:
|
2021-11-16 14:19:48 +00:00
|
|
|
m = x['content']
|
2023-07-04 08:54:59 +00:00
|
|
|
await msg.finish(m)
|
2023-03-04 10:08:40 +00:00
|
|
|
return sendmsg
|