Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add permission option for IRC commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Mar 27, 2014
1 parent 2f46fdf commit 230601c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
10 changes: 4 additions & 6 deletions dependency-reduced-pom.xml
Expand Up @@ -99,7 +99,9 @@
<releases>
<enabled>false</enabled>
</releases>
<snapshots />
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>sonatype-nexus-public</id>
<name>SonaType public snapshots and releases repository</name>
<url>https://oss.sonatype.org/content/groups/public</url>
Expand All @@ -122,11 +124,7 @@
<url>http://repo.regularbox.com/artifactory/repo/</url>
</repository>
<repository>
<id>comphenix-rep</id>
<name>Comphenix Repository</name>
<url>http://repo.comphenix.net/content/groups/public</url>
</repository>
<repository>
<snapshots />
<id>cnaude-repo</id>
<url>http://cnaude.freeshell.org/repo/</url>
</repository>
Expand Down
12 changes: 9 additions & 3 deletions pom.xml
Expand Up @@ -26,7 +26,7 @@
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Bukkit -->
Expand All @@ -49,11 +49,14 @@
</snapshots>
</repository>

<repository>
<!--<repository>
<id>comphenix-rep</id>
<name>Comphenix Repository</name>
<url>http://repo.comphenix.net/content/groups/public</url>
</repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>-->

<!-- Vault
<repository>
Expand All @@ -65,6 +68,9 @@
<repository>
<id>cnaude-repo</id>
<url>http://cnaude.freeshell.org/repo/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- For JUnitBenchmarks -->

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -725,6 +725,7 @@ private void loadConfig() {
optionPair.put("game_command", config.getString(commandKey + "game_command", "@help"));
optionPair.put("private_listen", config.getString(commandKey + "private_listen", "true"));
optionPair.put("channel_listen", config.getString(commandKey + "channel_listen", "true"));
optionPair.put("perm", config.getString(commandKey + "perm", ""));
for (String s : optionPair.keySet()) {
config.set(commandKey + s, optionPair.get(s));
}
Expand Down
Expand Up @@ -14,6 +14,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.pircbotx.Channel;
import org.pircbotx.User;

Expand Down Expand Up @@ -41,7 +43,7 @@ public IRCMessageHandler(PurpleIRC plugin) {
* @param message
* @param privateMessage
*/
public void processMessage(PurpleBot ircBot, User user, Channel channel, String message, boolean privateMessage) {
public void processMessage(PurpleBot ircBot, User user, Channel channel, String message, boolean privateMessage) {
plugin.logDebug("processMessage: " + message);
String myChannel = channel.getName();
if (ircBot.muteList.get(myChannel).contains(user.getNick())) {
Expand Down Expand Up @@ -77,6 +79,7 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String

String gameCommand = (String) ircBot.commandMap.get(myChannel).get(command).get("game_command");
String modes = (String) ircBot.commandMap.get(myChannel).get(command).get("modes");
String perm = (String) ircBot.commandMap.get(myChannel).get(command).get("perm");
boolean privateCommand = Boolean.parseBoolean(ircBot.commandMap.get(myChannel).get(command).get("private"));
boolean ctcpResponse = Boolean.parseBoolean(ircBot.commandMap.get(myChannel).get(command).get("ctcp"));

Expand All @@ -89,6 +92,8 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String
plugin.logDebug("Target: " + target);

boolean modeOkay = false;
boolean permOkay = checkPerm(perm, user.getNick());

if (modes.equals("*")) {
modeOkay = true;
}
Expand All @@ -106,9 +111,9 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String
}
if (modes.contains("s") && !modeOkay) {
modeOkay = user.getChannelsSuperOpIn().contains(channel);
}
}

if (modeOkay) {
if (modeOkay && permOkay) {
if (gameCommand.equals("@list")) {
sendMessage(ircBot, target, plugin.getMCPlayers(ircBot, myChannel), ctcpResponse);
} else if (gameCommand.equals("@uptime")) {
Expand Down Expand Up @@ -179,7 +184,7 @@ public void processMessage(PurpleBot ircBot, User user, Channel channel, String
if (privateMessage && !ircBot.relayPrivateChat) {
plugin.logDebug("Message NOT dispatched for broadcast due to \"relay-private-chat\" being false and this is a private message ...");
return;
}
}
plugin.logDebug("Message dispatched for broadcast...");
ircBot.broadcastChat(user.getNick(), myChannel, message, false);
}
Expand Down Expand Up @@ -207,4 +212,19 @@ private String getCommands(CaseInsensitiveMap<CaseInsensitiveMap<CaseInsensitive
}
return "";
}

private boolean checkPerm(String perm, String playerName) {
if (perm.isEmpty()) {
return true;
}
Player player = plugin.getServer().getPlayer(playerName);

if (player != null) {
plugin.logDebug("[checkPerm] Player " + playerName + " permission node " + perm + "=" + player.hasPermission(perm));
return player.hasPermission(perm);
} else {
plugin.logDebug("[checkPerm] Player not online: " + playerName);
return false;
}
}
}

0 comments on commit 230601c

Please sign in to comment.