From 9a702f5d1a2a87cc6b5ac361c74491e56d1d3427 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Wed, 10 Mar 2010 21:14:20 +0100 Subject: [PATCH] Check conversation type on handler execution where needed --- src/org/yaaic/command/handler/DeopHandler.java | 4 ++++ src/org/yaaic/command/handler/DevoiceHandler.java | 4 ++++ src/org/yaaic/command/handler/KickHandler.java | 4 ++++ src/org/yaaic/command/handler/MeHandler.java | 4 ++++ src/org/yaaic/command/handler/NamesHandler.java | 4 ++++ src/org/yaaic/command/handler/OpHandler.java | 4 ++++ src/org/yaaic/command/handler/VoiceHandler.java | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/src/org/yaaic/command/handler/DeopHandler.java b/src/org/yaaic/command/handler/DeopHandler.java index 0453e7b..9e07f9a 100644 --- a/src/org/yaaic/command/handler/DeopHandler.java +++ b/src/org/yaaic/command/handler/DeopHandler.java @@ -39,6 +39,10 @@ public class DeopHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() != Conversation.TYPE_CHANNEL) { + throw new CommandException("Only usable from within a channel"); + } + if (params.length == 2) { service.getConnection(server.getId()).deOp(conversation.getName(), params[1]); } else { diff --git a/src/org/yaaic/command/handler/DevoiceHandler.java b/src/org/yaaic/command/handler/DevoiceHandler.java index 2b7549a..3cc326c 100644 --- a/src/org/yaaic/command/handler/DevoiceHandler.java +++ b/src/org/yaaic/command/handler/DevoiceHandler.java @@ -39,6 +39,10 @@ public class DevoiceHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() != Conversation.TYPE_CHANNEL) { + throw new CommandException("Only usable from within a channel"); + } + if (params.length == 2) { service.getConnection(server.getId()).deVoice(conversation.getName(), params[1]); } else { diff --git a/src/org/yaaic/command/handler/KickHandler.java b/src/org/yaaic/command/handler/KickHandler.java index fbecb2f..1ff0151 100644 --- a/src/org/yaaic/command/handler/KickHandler.java +++ b/src/org/yaaic/command/handler/KickHandler.java @@ -41,6 +41,10 @@ public class KickHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() != Conversation.TYPE_CHANNEL) { + throw new CommandException("Only usable from within a channel"); + } + if (params.length == 2) { service.getConnection(server.getId()).kick(conversation.getName(), params[1]); } else { diff --git a/src/org/yaaic/command/handler/MeHandler.java b/src/org/yaaic/command/handler/MeHandler.java index a7cb23d..39c15e5 100644 --- a/src/org/yaaic/command/handler/MeHandler.java +++ b/src/org/yaaic/command/handler/MeHandler.java @@ -44,6 +44,10 @@ public class MeHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() == Conversation.TYPE_SERVER) { + throw new CommandException("Only usable from within a channel or a query"); + } + if (params.length > 1) { String action = BaseHandler.mergeParams(params); String nickname = service.getConnection(server.getId()).getNick(); diff --git a/src/org/yaaic/command/handler/NamesHandler.java b/src/org/yaaic/command/handler/NamesHandler.java index b6eebe9..dfb7548 100644 --- a/src/org/yaaic/command/handler/NamesHandler.java +++ b/src/org/yaaic/command/handler/NamesHandler.java @@ -45,6 +45,10 @@ public class NamesHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() != Conversation.TYPE_CHANNEL) { + throw new CommandException("Only usable from within a channel"); + } + StringBuffer userList = new StringBuffer("Users " + conversation.getName() + ":"); for (User user : service.getConnection(server.getId()).getUsers(conversation.getName())) { userList.append(" "); diff --git a/src/org/yaaic/command/handler/OpHandler.java b/src/org/yaaic/command/handler/OpHandler.java index 8fbb72f..bf1dc89 100644 --- a/src/org/yaaic/command/handler/OpHandler.java +++ b/src/org/yaaic/command/handler/OpHandler.java @@ -39,6 +39,10 @@ public class OpHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() != Conversation.TYPE_CHANNEL) { + throw new CommandException("Only usable from within a channel"); + } + if (params.length == 2) { service.getConnection(server.getId()).op(conversation.getName(), params[1]); } else { diff --git a/src/org/yaaic/command/handler/VoiceHandler.java b/src/org/yaaic/command/handler/VoiceHandler.java index 1c7b6a6..2e95061 100644 --- a/src/org/yaaic/command/handler/VoiceHandler.java +++ b/src/org/yaaic/command/handler/VoiceHandler.java @@ -39,6 +39,10 @@ public class VoiceHandler extends BaseHandler @Override public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { + if (conversation.getType() != Conversation.TYPE_CHANNEL) { + throw new CommandException("Only usable from within a channel"); + } + if (params.length == 2) { service.getConnection(server.getId()).voice(conversation.getName(), params[1]); } else {