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 {
|
2015-07-20 14:02:42 -04:00
|
|
|
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
|
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
|
|
|
}
|