mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 04:41:06 -05:00
3a51f530c6
Changes: - Removed NetInput/NetOutput and replaced them with ByteBuf - Added PacketSerializer to PacketDefinition - Added packet codecs which implementations can supply with custom readers/writers for buffers
62 lines
1.7 KiB
Java
62 lines
1.7 KiB
Java
package com.github.steveice10.packetlib.test;
|
|
|
|
import com.github.steveice10.packetlib.Server;
|
|
import com.github.steveice10.packetlib.Session;
|
|
import com.github.steveice10.packetlib.crypt.AESEncryption;
|
|
import com.github.steveice10.packetlib.crypt.PacketEncryption;
|
|
import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
|
|
import com.github.steveice10.packetlib.packet.PacketHeader;
|
|
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
|
|
|
import javax.crypto.SecretKey;
|
|
import java.security.GeneralSecurityException;
|
|
|
|
public class TestProtocol extends PacketProtocol {
|
|
private final PacketHeader header = new DefaultPacketHeader();
|
|
private AESEncryption encrypt;
|
|
|
|
@SuppressWarnings("unused")
|
|
public TestProtocol() {
|
|
}
|
|
|
|
public TestProtocol(SecretKey key) {
|
|
this.setSecretKey(key);
|
|
}
|
|
|
|
public PacketCodecHelper createHelper() {
|
|
return new BasePacketCodecHelper();
|
|
}
|
|
|
|
public void setSecretKey(SecretKey key) {
|
|
this.register(0, PingPacket.class, PingPacket::new);
|
|
try {
|
|
this.encrypt = new AESEncryption(key);
|
|
} catch(GeneralSecurityException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getSRVRecordPrefix() {
|
|
return "_test";
|
|
}
|
|
|
|
@Override
|
|
public PacketHeader getPacketHeader() {
|
|
return this.header;
|
|
}
|
|
|
|
public PacketEncryption getEncryption() {
|
|
return this.encrypt;
|
|
}
|
|
|
|
@Override
|
|
public void newClientSession(Session session) {
|
|
session.addListener(new ClientSessionListener());
|
|
}
|
|
|
|
@Override
|
|
public void newServerSession(Server server, Session session) {
|
|
session.addListener(new ServerSessionListener());
|
|
}
|
|
}
|