summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-10-12 03:14:07 +0200
committersnowleo <schneeleo@gmail.com>2011-10-12 03:14:26 +0200
commit860d446d28776ec842fa53e8e08538d4e093d6e9 (patch)
tree0c4598eae4eb8c59fd36e8312eab1b27a8018794 /EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java
parent9ec398b39b0f48392a9d635041b392c7dba2ca0c (diff)
downloadEssentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar
Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar.gz
Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar.lz
Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar.xz
Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.zip
EssentialsUpdate WIP
Diffstat (limited to 'EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java')
-rw-r--r--EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java131
1 files changed, 131 insertions, 0 deletions
diff --git a/EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java b/EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java
new file mode 100644
index 000000000..32f2d1e75
--- /dev/null
+++ b/EssentialsUpdate/src/f00f/net/irc/martyr/commands/JoinCommand.java
@@ -0,0 +1,131 @@
+package f00f.net.irc.martyr.commands;
+
+import f00f.net.irc.martyr.InCommand;
+import f00f.net.irc.martyr.clientstate.Channel;
+import f00f.net.irc.martyr.clientstate.ClientState;
+import f00f.net.irc.martyr.util.FullNick;
+import java.util.logging.Logger;
+
+
+/**
+ * Defines JOIN command.
+ */
+public class JoinCommand extends AbstractCommand
+{
+
+ static Logger log = Logger.getLogger(JoinCommand.class.getName());
+
+ private String channel;
+ private String secret;
+ private FullNick user;
+
+ /** For use as a factory */
+ public JoinCommand()
+ {
+ this.user = null;
+ this.channel = null;
+ this.secret = null;
+ }
+
+ /**
+ * This constructor is used with an incoming JOIN command from the server.
+ *
+ * @param user User that joined the channel
+ * @param channel Channel that was joined
+ */
+ private JoinCommand( FullNick user, String channel )
+ {
+ this.user = user;
+ this.channel = channel;
+ this.secret = null;
+ }
+
+ /**
+ * This constructor is used to make a request to join a channel that
+ * requires a secret key to join.
+ *
+ * @param channel The channel
+ * @param secret The secret key required to enter the channel, or null of
+ * none.
+ */
+ public JoinCommand( String channel, String secret )
+ {
+ this.secret = secret;
+ this.user = null;
+ this.channel = channel;
+ }
+
+ /**
+ * This constructor is used to make a request to join a channel.
+ *
+ * @param channel Channel that will be joined
+ */
+ public JoinCommand( String channel )
+ {
+ this.secret = null;
+ this.user = null;
+ this.channel = channel;
+ }
+
+ public InCommand parse( String prefix, String identifier, String params )
+ {
+ return new JoinCommand( new FullNick( prefix ), getParameter( params, 0 ) );
+ }
+
+ public String getIrcIdentifier()
+ {
+ return "JOIN";
+ }
+
+ public String renderParams()
+ {
+ if( secret == null )
+ return channel;
+ else
+ return channel + " " + secret;
+ }
+
+ public String getChannel()
+ {
+ return channel;
+ }
+
+ public String getSecret()
+ {
+ return secret;
+ }
+
+ public FullNick getUser()
+ {
+ return user;
+ }
+
+ public boolean weJoined( ClientState state )
+ {
+ return user.equals( state.getNick() );
+ }
+
+ public boolean updateClientState( ClientState state )
+ {
+ if( weJoined( state ) )
+ {
+ // We've joined a group.
+ //log.debug("JOIN: We've joined " + channel);
+ state.addChannel( channel );
+ return true;
+ }
+ else
+ {
+ // Someone else joined the group.
+ //log.debug("JOIN: " + user + " joined " + channel);
+ // 1) Grab group
+ Channel channelObj = state.getChannel( channel );
+ // 2) Add user
+ channelObj.addMember( user, this );
+ return true;
+ }
+ }
+
+}
+
+