More BaseProtocol changes

This commit is contained in:
creeper123123321 2018-07-03 11:19:32 -03:00
parent f81892ea74
commit 697e883649
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
4 changed files with 20 additions and 6 deletions

View File

@ -54,9 +54,15 @@ public class ProtocolPipeline extends Protocol {
*/
public void add(Protocol protocol) {
if (protocolList != null) {
// Make BaseProtocol be in the last position, so the login packets can be modified by other protocols
protocolList.add(protocolList.size() - 1, protocol);
protocolList.add(protocol);
protocol.init(userConnection);
// Move base Protocols to the end, so the login packets can be modified by other protocols
List<Protocol> toMove = new ArrayList<>();
for (Protocol p : protocolList)
if (ProtocolRegistry.isBaseProtocol(p))
toMove.add(p);
protocolList.removeAll(toMove);
protocolList.addAll(toMove);
} else {
throw new NullPointerException("Tried to add protocol to early");
}

View File

@ -230,4 +230,12 @@ public class ProtocolRegistry {
return rangeProtocol.getValue();
throw new IllegalStateException("No Base Protocol for " + serverVersion);
}
public static boolean isBaseProtocol(Protocol protocol) {
for (Pair<Range<Integer>, Protocol> p : baseProtocols)
if (p.getValue() == protocol)
return true;
return false;
}
}

View File

@ -131,8 +131,8 @@ public class BaseProtocol1_13 extends Protocol {
Via.getManager().addPortedClient(wrapper.user());
if (info.getPipeline().pipes().size() == 2
&& info.getPipeline().pipes().get(0).getClass() == BaseProtocol1_13.class
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol.class) // Only base protocol
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_13.class
&& info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol
wrapper.user().setActive(false);
if (Via.getManager().isDebug()) {

View File

@ -131,8 +131,8 @@ public class BaseProtocol1_7 extends Protocol {
Via.getManager().addPortedClient(wrapper.user());
if (info.getPipeline().pipes().size() == 2
&& info.getPipeline().pipes().get(0).getClass() == BaseProtocol1_7.class
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol.class) // Only base protocol
&& info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_7.class
&& info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol
wrapper.user().setActive(false);
if (Via.getManager().isDebug()) {