<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[修改 websocket 插件以支持 socks5 代理或者指定 IP 接口]]></title><description><![CDATA[<p dir="auto">PYMUD支持使用socks5代理或者本机的特定网络接口进行网络访问，这本来是没问题的，但是对应北侠fullme的时候，原来提供的websocket插件会无法显示图片。使用浏览器打开时，会提示同一个IP为其他IP的角色显示过fullme图片，因此不能正确显示。此时，就需要让websocket插件通过与会话角色对应的代理或者网络设置来进行显示了。修改原 <a href="http://websocket.py" rel="nofollow ugc">websocket.py</a> 中的 loadAndSenfFullme 的函数代码，改为如下内容，可以使用与会话相同的网络配置来进行图片获取和下载，再使用websocket传送到web端页面上用于显示。只需要修改此处一个函数即可。</p>
<p dir="auto">修改后的代码片段如下：</p>
<pre><code class="language-Python">async def loadAndSendFullme(sender, text_msg: str, fullme_url: str, times: int = 3, combine: bool = False):
    fmadress = fullme_url.split("robot.php?filename=")[-1]
    url = f"http://fullme.pkuxkx.net/robot.php?filename={fmadress}"
    images = []

    # 使用与会话相同的网络配置进行图片抓取
    conn = None
    pymudapp = app.pymud
    if isinstance(pymudapp, PyMudApp):
        session = pymudapp.sessions.get(sender)

        if isinstance(session, Session):
            if session.proxy:
                conn = ProxyConnector.from_url(session.proxy)
            elif session.local_address:
                conn = TCPConnector(local_addr=(session.local_address, 0))

    async with ClientSession(connector=conn) as client:
        for i in range(0, times):
            async with client.get(url) as response:
                if response.status != 200:
                    continue

                text = await response.text()
                matches = re.search(r'src="\.([^"]+\.jpg)"', text)
                if not matches:
                    continue

                img_url = "http://fullme.pkuxkx.net" + matches.group(1)

                # 解析URL获取文件名
                parsed_url = urlparse(img_url)
                filename = os.path.basename(unquote(parsed_url.path))
                # 创建fullme目录
                fullme_dir = os.path.join(os.path.dirname(__file__), 'fullme')#cl
                os.makedirs(fullme_dir, exist_ok=True)
                # 本地文件路径
                local_img_path = os.path.join(fullme_dir, filename)
                # 下载图片
                #async with ClientSession(connector=conn) as session:
                async with client.get(img_url) as img_response:
                    if img_response.status == 200:
                        with open(local_img_path, 'wb') as f:
                            f.write(await img_response.read())
                        # 使用本地路径调用
                        if not combine:
                            await send_message_to_clients(sender, text_msg, local_img_path)
                        else:
                            images.append(local_img_path)
                    else:
                        asyncio.create_task(send_message_to_clients(sender, f"{text_msg} (图片下载失败: HTTP {img_response.status})", ""))

            await asyncio.sleep(0.5)

    if combine:
        await send_message_to_clients(sender, text_msg, images)
</code></pre>
<p dir="auto">以下是我使用本地IP连接了5个账号，同时使用代理后，利用远端云服务器连接了2个账号时，websocket插件的显示部分。<br />
<img src="/assets/uploads/files/1777790384147-qq_1777790361323.png" alt="QQ_1777790361323.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://bbs.pymud.cn/topic/32/修改-websocket-插件以支持-socks5-代理或者指定-ip-接口</link><generator>RSS for Node</generator><lastBuildDate>Thu, 04 Jun 2026 19:58:17 GMT</lastBuildDate><atom:link href="https://bbs.pymud.cn/topic/32.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 03 May 2026 06:40:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 修改 websocket 插件以支持 socks5 代理或者指定 IP 接口 on Thu, 07 May 2026 09:19:48 GMT]]></title><description><![CDATA[<p dir="auto">要像上图一样同时监控多个账号的状态，参考以下方法：</p>
<ol>
<li>使用本帖附带的 <a href="/assets/uploads/files/1778144881357-websocket.2.0.5.zip">websocket 插件</a></li>
<li>在某一个角色都加载的脚本中，构建一个 overview 函数，并通过调用插件的 sendOverview 方法注册到插件中。示例如下：</li>
</ol>
<pre><code class="language-Python">
from pymud import IConfig

class AExampleOfOverview(IConfig):
    def __init__(self, session, *args, **kwargs):
        ws = self.session.getGlobal("ws")
        if ws and hasattr(ws, "sendOverview"):
            ws.sendOverview(self.session, self.overview)

    # 此函数为关键，返回一个dict，key会作为websocket显示状态的表头，内容在下面
    def overview(self):
        data = dict()
        data["角色"] = (
            f"{self.session.getVariable('name', 'none')}({self.session.getVariable('id', 'id')})"
        )

        # fullme time
        fullme = int(self.session.getVariable("%fullme", 0))
        delta = time.time() - fullme
        data["FM"] = int(delta // 60)
        data["发呆"] = int(self.session.idletime // 60)

        data["位置"] = (
            f"{self.session.getVariable('city', '未知地域')}{self.session.getVariable('room', '未知房间')}"
        )

        data["任务"] = self.session.cmds["jobmanager"].currentJob
        data["状态"] = self.session.cmds["jobmanager"].currentStatus
        data["忙闲"] = "忙" if self.session.getVariable("is_busy", False) else "闲"
        data["战斗"] = self.session.getVariable("is_fighting", False)

        return data

</code></pre>
<p dir="auto">以下是插件最新版本</p>
<p dir="auto"><a href="/assets/uploads/files/1778144881357-websocket.2.0.5.zip">websocket.2.0.5.zip</a></p>
]]></description><link>https://bbs.pymud.cn/post/118</link><guid isPermaLink="true">https://bbs.pymud.cn/post/118</guid><dc:creator><![CDATA[newstart]]></dc:creator><pubDate>Thu, 07 May 2026 09:19:48 GMT</pubDate></item><item><title><![CDATA[Reply to 修改 websocket 插件以支持 socks5 代理或者指定 IP 接口 on Thu, 07 May 2026 08:11:39 GMT]]></title><description><![CDATA[<p dir="auto">楼主这个同时监控几个账号的，如何实现的求代码</p>
]]></description><link>https://bbs.pymud.cn/post/117</link><guid isPermaLink="true">https://bbs.pymud.cn/post/117</guid><dc:creator><![CDATA[粉红凤凰飞]]></dc:creator><pubDate>Thu, 07 May 2026 08:11:39 GMT</pubDate></item></channel></rss>