ProtoWeaver
一个用于 Minecraft 的网络库,用于创建在内部 Netty 服务器上运行的自定义协议。
这是什么意思?
你是否厌倦了劫持客户端连接以向代理发送和接收数据?我也受够了。ProtoWeaver 允许你创建一个自定义协议,该协议在与 Minecraft 服务器相同的端口上运行。
这意味着像 Velocity 这样的代理无论玩家是否在线,都能与服务器通信,而无需在不同的端口上运行额外的 Socket 服务器。ProtoWeaver 也不仅限于代理。使用 client 模块,任何第三方 Java 应用程序都可以直接与 ProtoWeaver 通信!
ProtoWeaver 快速、安全且易于使用。所有协议都在 Minecraft 使用的同一个 Netty 实例下运行,通过 SSL 进行加密,并封装在一个非常直观的 API 中。让我们来看看:
功能特性
- 零用户配置要求
- SSL 加密
- 协议身份验证
- 数据包作为 POJO(普通旧 Java 对象)
- 压缩(Gzip, Snappy, LZ)
- 支持所有主要加载器(NeoForge 即将推出)
- 注册原始协议(HTTP, SSH 等)的 API
- 自定义序列化
- 自定义 SSL 提供程序/证书
- 多协议连接
- 告诉我你想看到什么!
项目设置
在你的 build.gradle 中包含以下内容
*** 注意:不要对 ProtoWeaver 进行阴影打包(shade)!否则无法正常工作。ProtoWeaver 是一个模组/插件,应与你自己的模组/插件一起安装!
repositories {
maven { url "https://maven.mrnavastar.me/releases" }
}
dependencies {
// 'common' 可以替换为以下任意一项:`client`, `fabric`, `forge`, `paper` 或 `proxy`。
implementation "me.mrnavastar.protoweaver:common:1.3.11"
}
创建协议
协议具有高度可定制性,并内置了大量功能。以下是一个示例协议:
Protocol protocol = Protocol.create("my_mod_id", "cool_protocol")
.setCompression(CompressionType.GZIP)
.setServerHandler(MyCustomServerHandler.class)
.setClientHandler(MyCustomClientHandler.class)
.setMaxConnections(15)
.addPacket(String.class)
.build();
// 在使用之前加载协议
ProtoWeaver.load(protocol);
发送数据包
发送数据包非常简单。任何已添加到协议中的 POJO(参见 创建协议)都是有效的可发送数据包。请注意,所有 POJO 序列化均由 kyro 处理,这是一个快速高效的序列化库。
// 如果你有一个 'ProtoConnection' 的引用,你可以简单地:
connection.send(myObject);
// 如果你有一个 'ProtoClient' 的引用,你也可以:
client.send(myObject);
处理数据包
所有协议都需要处理器来实现功能。客户端和服务器可以使用相同的处理器,也可以使用不同的处理器。
public class MyCustomServerHandler implements ProtoConnectionHandler {
// 注意,所有函数都是可选实现的
@Override
public void onReady(ProtoConnection connection) {
System.out.println("太棒了!看起来一个新的客户端已连接,来自:" + connection.getRemoteAddress());
}
@Override
public void onDisconnect(ProtoConnection connection) {
System.out.println("再见:" + connection.getRemoteAddress());
}
@Override
public void handlePacket(ProtoConnection connection, Object packet) {
System.out.println("哇!收到:" + packet.toString() + " 来自:" + connection.getRemoteAddress());
}
}
public class MyCustomClientHandler implements ProtoConnectionHandler {
// 注意,所有函数都是可选实现的
@Override
public void onReady(ProtoConnection connection) {
System.out.println("太棒了!连接到:" + connection.getRemoteAddress());
}
@Override
public void onDisconnect(ProtoConnection connection) {
System.out.println("再见:" + connection.getRemoteAddress());
}
@Override
public void handlePacket(ProtoConnection connection, Object packet) {
System.out.println("打招呼!");
connection.send("嘿,服务器!");
}
}
自定义序列化
有时,在协议中发送 Minecraft 对象或其他预制的 POJO 会很有用。为了支持这一点,你可以注册一个自定义序列化器。
例如,以下是 NBT 标签的序列化器:
public class NbtSerializer extends ProtoSerializer<CompoundTag> {
public NbtSerializer(Class<CompoundTag> type) {
super(type);
}
@Override
public void write(ByteArrayOutputStream buffer, CompoundTag value) {
try {
NbtIo.writeCompressed(value, buffer);
} catch (IOException e) {
Platform.throwException(e);
}
}
@Override
public CompoundTag read(ByteArrayInputStream buffer) {
try {
return NbtIo.readCompressed(buffer, NbtAccounter.unlimitedHeap());
} catch (IOException e) {
Platform.throwException(e);
throw new RuntimeException(e);
}
}
}
然后要注册该序列化器,只需执行以下操作:
Protocol protocol = Protocol.create("my_mod_id", "cool_protocol")
.setCompression(CompressionType.GZIP)
.setServerHandler(MyCustomServerHandler.class)
.setClientHandler(MyCustomClientHandler.class)
.setMaxConnections(15)
.addPacket(CompoundTag.class, NbtSerializer.class)
.build();
更多文档即将推出!也许会有真正的网站??
ProtoWeaver
A minecraft networking library for creating custom protocols that run on the internal netty server.
What dis mean?
Sick and tired of hyjacking client connections to send data to and from a proxy? Well I sure was. ProtoWeaver allows you to create a custom protocol that runs on the same port that the minecraft server uses.
This means a proxy such as velocity is able to communicate with the server regardless if players are on online or not, without running an extra socket server on a different port. Protoweaver is also not just
limited to proxies. Using the client module, any 3rd party java application can talk directly with ProtoWeaver!
Protoweaver is fast, secure, and easy to use. All protocols run under the same netty instance used by minecraft, are encypted with ssl, and are wrapped in a very straight forward api. Lets take a look:
Features
- Zero user config required
- SSL encrytion
- Protocol authentication
- Packets as POJO's
- Compression (Gzip, Snappy, LZ)
- All major mod loaders (neoforge soon tm)
- API for registering raw protocols (http, ssh, etc)
- Custom serialization
- Custom SSL providers/certs
- Muti-protocol connections
- Tell me what you want to see!
Project Setup
In your build.gradle include
*** Note: Do not shade protoweaver! It will not work properly. ProtoWeaver is a mod/plugin that is installed along side yours!
repositories {
maven { url "https://maven.mrnavastar.me/releases" }
}
dependencies {
// 'common' can be replaced with any of: `client`, `fabric`, `forge`, `paper` or `proxy`.
implementation "me.mrnavastar.protoweaver:common:1.3.11"
}
Creating a Protocol
Protocols are very customizable with a lot of built in functionality. Here is an example protocol:
Protocol protocol = Protocol.create("my_mod_id", "cool_protocol")
.setCompression(CompressionType.GZIP)
.setServerHandler(MyCustomServerHandler.class)
.setClientHandler(MyCustomClientHandler.class)
.setMaxConnections(15)
.addPacket(String.class)
.build();
// Load the protocol before it can be used
ProtoWeaver.load(protocol);
Sending packets
Sending packets is extremely simple. Any POJO that has been added to the protocol (See Creating a Protcol) is a valid packet that can be sent. Note that all POJO serialization is handled through kyro, a fast and fast serialization library.
// If you have a reference to a 'ProtoConnection', you can simply:
connection.send(myObject);
// If you have a reference to a 'ProtoClient', you can also:
client.send(myObject);
Handling packets
All protocols need handlers in order to implement functionality. The client and server can either use the same handler, or both use different ones.
public class MyCustomServerHandler implements ProtoConnectionHandler {
// Note that all functions are optional to implement
@Override
public void void onReady(ProtoConnection connection) {
System.out.println("awesome! looks like a new client has connected from: " + connection.getRemoteAddress());
}
@Override
public void onDisconnect(ProtoConnection connection) {
System.out.println("goodbye: " + connection.getRemoteAddress());
}
@Override
public void handlePacket(ProtoConnection connection, Object packet) {
System.out.println("wow! got: " + packet.toString() + " from: " + connection.getRemoteAddress());
}
}
public class MyCustomClientHandler implements ProtoConnectionHandler {
// Note that all functions are optional to implement
@Override
public void void onReady(ProtoConnection connection) {
System.out.println("awesome! connected to: " + connection.getRemoteAddress());
}
@Override
public void onDisconnect(ProtoConnection connection) {
System.out.println("goodbye: " + connection.getRemoteAddress());
}
@Override
public void handlePacket(ProtoConnection connection, Object packet) {
System.out.println("saying hi!");
connection.send("Hey server!");
}
}
Custom Serialization
Sometimes it can be useful to send minecraft objects or other premade POJO's in your protocol. To allow this, you can register a custom serializer.
For example, here is a serializer for NBT tags:
public class NbtSerializer extends ProtoSerializer<CompoundTag> {
public NbtSerializer(Class<CompoundTag> type) {
super(type);
}
@Override
public void write(ByteArrayOutputStream buffer, CompoundTag value) {
try {
NbtIo.writeCompressed(value, buffer);
} catch (IOException e) {
Platform.throwException(e);
}
}
@Override
public CompoundTag read(ByteArrayInputStream buffer) {
try {
return NbtIo.readCompressed(buffer, NbtAccounter.unlimitedHeap());
} catch (IOException e) {
Platform.throwException(e);
throw new RuntimeException(e);
}
}
}
Then to register the serializer, simply do:
Protocol protocol = Protocol.create("my_mod_id", "cool_protocol")
.setCompression(CompressionType.GZIP)
.setServerHandler(MyCustomServerHandler.class)
.setClientHandler(MyCustomClientHandler.class)
.setMaxConnections(15)
.addPacket(CompoundTag.class, NbtSerializer.class)
.build();
More Docs Coming soon! Maybe a real website??
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ProtoWeaver
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
- 重构代码库,使其更具可维护性
- 修复在新游戏版本上的 Paper 相关问题
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
插件
PacketEvents 是一款专为 Minecraft Java 版打造的协议库,旨在简化数据包的处理与传输。
插件
ExyliaPlugins 的库。
插件
通过对话框或铁砧界面帮助你的 Anthme
插件
重新定义服务器上的生物运输方式。使用高度可定制的口袋道具,安全地捕获、存储和释放任何实体。
插件
为基于 Spigot/Paper/Folia 的服务器添加对 Vivecraft 的支持
插件
用于绘制游戏内地图或在浏览器中随探索实时进行地图绘制的实时地图。
评论 0
登录后参与评分
还没有评论,来抢沙发吧