-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a way to specify how to cut buffers into Packets Added a way to send multiple packets at once Added a PacketHandler that will handle only packets that verify a certain condition
- Loading branch information
Showing
20 changed files
with
222 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/fr/adamaq01/ozao/net/client/ClientPacketHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fr.adamaq01.ozao.net.client; | ||
|
||
import fr.adamaq01.ozao.net.packet.Packet; | ||
|
||
import java.util.function.Function; | ||
|
||
public abstract class ClientPacketHandler { | ||
|
||
protected Function<Packet, Boolean> verifyConsumer; | ||
|
||
public ClientPacketHandler(Function<Packet, Boolean> verifyConsumer) { | ||
this.verifyConsumer = verifyConsumer; | ||
} | ||
|
||
public abstract void onPacketReceive(Client client, Packet packet); | ||
|
||
public boolean verify(Packet packet) { | ||
return verifyConsumer.apply(packet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/fr/adamaq01/ozao/net/packet/PacketContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fr.adamaq01.ozao.net.packet; | ||
|
||
import fr.adamaq01.ozao.net.protocol.Protocol; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.function.Consumer; | ||
|
||
public class PacketContainer { | ||
|
||
public static PacketContainer create(Packet... packets) { | ||
return new PacketContainer(packets); | ||
} | ||
|
||
private Collection<Packet> packets; | ||
|
||
private PacketContainer(Packet... packets) { | ||
this.packets = Arrays.asList(packets); | ||
} | ||
|
||
public boolean verify(Protocol protocol) { | ||
return packets.stream().allMatch(packet -> protocol.verify(packet)); | ||
} | ||
|
||
public PacketContainer filter(Protocol protocol) { | ||
packets.removeIf(packet -> !protocol.verify(packet)); | ||
|
||
return this; | ||
} | ||
|
||
public PacketContainer put(Packet... packets) { | ||
Arrays.stream(packets).forEachOrdered(packet -> this.packets.add(packet)); | ||
|
||
return this; | ||
} | ||
|
||
public void forEach(Consumer<Packet> packetConsumer) { | ||
this.packets.forEach(packetConsumer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.