From 860d446d28776ec842fa53e8e08538d4e093d6e9 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 12 Oct 2011 03:14:07 +0200 Subject: EssentialsUpdate WIP --- .../net/irc/martyr/commands/WelcomeCommand.java | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 EssentialsUpdate/src/f00f/net/irc/martyr/commands/WelcomeCommand.java (limited to 'EssentialsUpdate/src/f00f/net/irc/martyr/commands/WelcomeCommand.java') diff --git a/EssentialsUpdate/src/f00f/net/irc/martyr/commands/WelcomeCommand.java b/EssentialsUpdate/src/f00f/net/irc/martyr/commands/WelcomeCommand.java new file mode 100644 index 000000000..ecbe9b1ac --- /dev/null +++ b/EssentialsUpdate/src/f00f/net/irc/martyr/commands/WelcomeCommand.java @@ -0,0 +1,125 @@ +package f00f.net.irc.martyr.commands; + +import f00f.net.irc.martyr.CommandRegister; +import f00f.net.irc.martyr.InCommand; +import f00f.net.irc.martyr.clientstate.ClientState; +import f00f.net.irc.martyr.util.FullNick; +import f00f.net.irc.martyr.util.ParameterIterator; +import java.util.logging.Logger; + + +/** + * Defines the commands that a server issues to welcome us. These are + * identified with 001, 002... etc. These commands are only received + * after we register, unlike the NOTICE command. + */ +public class WelcomeCommand extends AbstractInCommand +{ + static Logger log = Logger.getLogger(WelcomeCommand.class.getName()); + + private String notice; + private String nick; + + /** Factory */ + public WelcomeCommand() + { + this( null, null ); + } + + /** + * Used by parse to create an instance of WelcomeCommand. + * + * @param nick Nick that send the welcome + * @param notice Notice that was sent + * */ + public WelcomeCommand( String nick, String notice ) + { + this.notice = notice; + this.nick = nick; + //log.debug("WelcomeCommand: Nick is: `" + nick + "'"); + //log.debug("WelcomeCommand: Notice is: `"+notice+"'"); + } + + /** + * Parses a string and produces a formed command object, if it can. + * Should return null if it cannot form the command object. + */ + public InCommand parse( String prefix, String identifier, String params ) + { + ParameterIterator pi = new ParameterIterator( params ); + String nick = pi.next().toString(); + String notice; + if( pi.hasNext() ) + { + // We are looking at a "nick :msg" pair + notice = pi.next().toString(); + } + else + { + // There is only one parameter, a notice. + notice = nick; + nick = null; + } + if( pi.hasNext() ) + { + //log.severe("WelcomeCommand: More than two parameters, confused."); + } + + + //String str = getParameter( params, 0 ); + // + return new WelcomeCommand( nick, notice ); + } + + /** + * Sets the nick of the client state, if there is one included with + * this command. + */ + public boolean updateClientState( ClientState state ) + { + //log.debug("WelcomeCommand: updated client state with: " + new FullNick( nick )); + state.setNick( new FullNick( nick ) ); + + return true; + } + + /** + * Returns the string IRC uses to identify this command. Examples: + * NICK, PING, KILL, 332. In our case, there is no one thing. + */ + public String getIrcIdentifier() + { + return "001"; + } + + public void selfRegister( CommandRegister commandRegister ) + { + commandRegister.addCommand( "001", this ); + commandRegister.addCommand( "002", this ); + commandRegister.addCommand( "003", this ); + commandRegister.addCommand( "004", this ); + commandRegister.addCommand( "005", this ); + } + + public String getNotice() + { + return notice; + } + + /** + * @return the nick received with this command, or null if there isn't + * one. + * */ + public String getNick() + { + return nick; + } + + public String toString() + { + return "WelcomeCommand"; + } + +} + + -- cgit v1.2.3