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;
|
2013-12-14 19:41:25 -05:00
|
|
|
|
|
|
|
import javax.crypto.SecretKey;
|
2014-03-01 19:47:03 -05:00
|
|
|
import java.security.GeneralSecurityException;
|
2013-11-29 17:34:06 -05:00
|
|
|
|
|
|
|
public class TestProtocol extends PacketProtocol {
|
2021-11-13 13:15:43 -05:00
|
|
|
private final PacketHeader header = new DefaultPacketHeader();
|
2015-07-20 14:02:42 -04:00
|
|
|
private AESEncryption encrypt;
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
2021-11-24 23:32:14 -05:00
|
|
|
public TestProtocol() {
|
2015-07-20 14:02:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public TestProtocol(SecretKey key) {
|
|
|
|
this.setSecretKey(key);
|
|
|
|
}
|
|
|
|
|
2022-05-29 13:40:39 -04:00
|
|
|
public PacketCodecHelper createHelper() {
|
|
|
|
return new BasePacketCodecHelper();
|
|
|
|
}
|
|
|
|
|
2015-07-20 14:02:42 -04:00
|
|
|
public void setSecretKey(SecretKey key) {
|
2021-11-13 13:15:43 -05:00
|
|
|
this.register(0, PingPacket.class, PingPacket::new);
|
2015-07-20 14:02:42 -04:00
|
|
|
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
|
2021-01-15 15:42:00 -05:00
|
|
|
public void newClientSession(Session session) {
|
2015-07-20 14:02:42 -04:00
|
|
|
session.addListener(new ClientSessionListener());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void newServerSession(Server server, Session session) {
|
|
|
|
session.addListener(new ServerSessionListener());
|
|
|
|
}
|
2013-11-29 17:34:06 -05:00
|
|
|
}
|