@2003scape/rsc-socket 中文文档教程

发布于 4年前 浏览 28 项目主页 更新于 3年前

rsc-socket

编码/解码 runescape 经典数据包。 设计用于包裹 节点 套接字 或 WebSocket(客户端服务器),类似于 json-socket 有效。

该模块还处理用户名和聊天消息的编码/解码, 将所有内容转换为原生类型。

install

$ npm install @2003scape/rsc-socket

example

const RSCSocket = require('./src');
const net = require('net');

net.createServer((socket) => {
    socket = new RSCSocket(socket, true);
    socket.on('error', (err) => console.error(err));

    socket.on('message', (message) => {
        console.log('packet recevied', message);

        if (message.type === 'login') {
            socket.sendMessage({
                type: 'worldInfo',
                index: 0,
                planeWidth: 2304,
                planeHeight: 1776,
                planeIndex: 0
            });
        }
    });
}).listen(43594);

api

socket = new RSCSocket(net.Socket || WebSocket, isServer = true)

创建一个新的套接字包装器实例。

socket.send(data)

发送原始数据缓冲区(用于登录过程)。

socket.sendMessage(message)

从中发送 POJO 进行编码并写入套接字。

socket.getIPAddress()

将 IPv4 地址作为字符串返回。

socket.close()

终止或销毁套接字。

socket.on('message', (message) => {})

收到解码包POJO。

license

版权所有 2020 2003Scape Team

该程序是免费软件:您可以重新分发它和/或修改它 GNU Affero 通用公共许可证的条款由 自由软件基金会,许可证的第 3 版,或(由您选择) 任何更高版本。

分发该程序是希望它有用,但没有任何 保修单; 甚至没有适销性或适用性的默示保证 特殊用途。 有关详细信息,请参阅 GNU Affero 通用公共许可证。

您应该已经收到 GNU Affero 通用公共许可证的副本 有了这个程序。 如果没有,请参阅 http://www.gnu.org/licenses/。

rsc-socket

encode/decode runescape classic packets. designed to wrap node Socket or WebSocket (client or server), similar to how json-socket works.

this module handles encoding/decoding of usernames and chat messages as well, converting everything to native types.

install

$ npm install @2003scape/rsc-socket

example

const RSCSocket = require('./src');
const net = require('net');

net.createServer((socket) => {
    socket = new RSCSocket(socket, true);
    socket.on('error', (err) => console.error(err));

    socket.on('message', (message) => {
        console.log('packet recevied', message);

        if (message.type === 'login') {
            socket.sendMessage({
                type: 'worldInfo',
                index: 0,
                planeWidth: 2304,
                planeHeight: 1776,
                planeIndex: 0
            });
        }
    });
}).listen(43594);

api

socket = new RSCSocket(net.Socket || WebSocket, isServer = true)

create a new socket wrapper instance.

socket.send(data)

send a raw data buffer (used in login process).

socket.sendMessage(message)

send a POJO from to be encoded and written to the socket.

socket.getIPAddress()

return the IPv4 address as a string.

socket.close()

terminate or destroy the socket.

socket.on('message', (message) => {})

received a decoded packet POJO.

license

Copyright 2020 2003Scape Team

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文