MCProtocolLib/example/com/github/steveice10/packetlib/test/TestProtocol.java

60 lines
1.6 KiB
Java
Raw Normal View History

2017-03-01 19:09:48 -05:00
package com.github.steveice10.packetlib.test;
2013-11-29 17:34:06 -05:00
2017-03-01 19:09:48 -05:00
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;
2013-11-29 17:34:06 -05:00
public class TestProtocol extends PacketProtocol {
private PacketHeader header = new DefaultPacketHeader();
private AESEncryption encrypt;
@SuppressWarnings("unused")
private TestProtocol() {
}
public TestProtocol(SecretKey key) {
this.setSecretKey(key);
}
public void setSecretKey(SecretKey key) {
this.register(0, PingPacket.class);
try {
this.encrypt = new AESEncryption(key);
} catch(GeneralSecurityException e) {
e.printStackTrace();
}
}
@Override
public String getSRVRecordPrefix() {
return "_test";
}
@Override
public PacketHeader getPacketHeader() {
return this.header;
}
@Override
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());
}
2013-11-29 17:34:06 -05:00
}