Skip to content

Commit

Permalink
Add option for restricted messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Aug 26, 2019
1 parent e57caec commit f4b4779
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/main/java/de/cubeside/connection/ConnectionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ public interface ConnectionAPI {
/**
* Sends some data to all servers.
* The channel name should use the format <i>plugin.subchannel</i>.
* This message will not be sent to restriced servers.
*
* @param channel
* the channel to use. may not be null
* @param data
* the data to send. may not be null
*/
public void sendData(String channel, byte[] data);

/**
* Sends some data to all servers.
* The channel name should use the format <i>plugin.subchannel</i>.
*
* @param channel
* the channel to use. may not be null
* @param data
* the data to send. may not be null
* @param sendToRestriced
* send this message to restricted servers too.
*/
public void sendData(String channel, byte[] data, boolean sendToRestriced);
}
11 changes: 8 additions & 3 deletions src/main/java/de/cubeside/connection/GlobalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,15 @@ protected synchronized void onPlayerOffline(UUID uuid) {

@Override
public void sendData(String channel, byte[] data) {
sendData(channel, null, null, data);
sendData(channel, data, false);
}

protected synchronized void sendData(String channel, UUID targetUuid, String targetServer, byte[] data) {
@Override
public void sendData(String channel, byte[] data, boolean sendToRestricted) {
sendData(channel, null, null, data, false, sendToRestricted);
}

protected synchronized void sendData(String channel, UUID targetUuid, String targetServer, byte[] data, boolean sendToAll, boolean sendToRestricted) {
Objects.requireNonNull(channel, "channel");
Objects.requireNonNull(data, "data");
byte[] dataClone = data.clone();
Expand All @@ -567,7 +572,7 @@ protected synchronized void sendData(String channel, UUID targetUuid, String tar
try {
dos.writeByte(ClientPacketType.DATA.ordinal());
dos.writeUTF(channel);
int flags = (targetUuid != null ? 1 : 0) + (targetServer != null ? 2 : 0);
int flags = (targetUuid != null ? 1 : 0) + (targetServer != null ? 2 : 0) + (sendToRestricted ? 4 : 0) + (sendToAll ? 8 : 0);
dos.writeByte(flags);
if (targetUuid != null) {
dos.writeLong(targetUuid.getMostSignificantBits());
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/de/cubeside/connection/GlobalPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,35 @@ public UUID getUniqueId() {

/**
* Sends some data to this player. The message will be sent to all servers this player is on.
* The channel name should use the format <i>plugin.subchannel</i>.
* The channel name should use the format <i>plugin.subchannel</i>. This has the same effect as
* calling {@link #sendData(String, byte[], boolean, boolean)} with sendToUnrestricted false and
* sendToRestricted false.
*
* @param channel
* the channel to use. may not be null
* @param data
* the data to send. may not be null
*/
public void sendData(String channel, byte[] data) {
client.sendData(channel, uuid, null, data);
sendData(channel, data, false, false);
}

/**
* Sends some data to this player. The message will be sent to all servers this player is on.
* The channel name should use the format <i>plugin.subchannel</i>.
*
* @param channel
* the channel to use. may not be null
* @param data
* the data to send. may not be null
* @param sendToUnrestricted
* send this message also to unrestricted servers where this player is not online.
* @param sendToRestricted
* send this message to restricted servers too. If the player is online on some server
* the message is always sent there, even if this parameter is false.
*/
public void sendData(String channel, byte[] data, boolean sendToUnrestricted, boolean sendToRestricted) {
client.sendData(channel, uuid, null, data, sendToUnrestricted, sendToRestricted);
}

public boolean isOnAnyServer() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/cubeside/connection/GlobalServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Collection<GlobalPlayer> getPlayers() {
* the data to send. may not be null
*/
public void sendData(String channel, byte[] data) {
client.sendData(channel, null, name, data);
client.sendData(channel, null, name, data, false, false);
}

protected void addPlayer(GlobalPlayer player) {
Expand Down

0 comments on commit f4b4779

Please sign in to comment.