123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761 |
- /*
- * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.parser.irc;
-
- import com.dmdirc.parser.common.ChannelListModeItem;
- import com.dmdirc.parser.interfaces.ChannelClientInfo;
- import com.dmdirc.parser.interfaces.ChannelInfo;
- import com.dmdirc.parser.interfaces.ClientInfo;
- import com.dmdirc.parser.interfaces.Parser;
- import com.dmdirc.parser.common.QueuePriority;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Hashtable;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Queue;
-
- /**
- * Contains Channel information.
- *
- * @author Shane Mc Cormack
- * @author Chris Smith
- * @see IRCParser
- */
- public class IRCChannelInfo implements ChannelInfo {
- /**
- * Boolean repreenting the status of names requests.
- * When this is false, any new names reply will cause current known channelclients to be removed.
- */
- private boolean bAddingNames = true;
-
- /** Unixtimestamp representing time when the channel was created. */
- private long nCreateTime = 0;
-
- /** Current known topic in the channel. */
- private String sTopic = "";
- /** Last known user to set the topic (Full host where possible). */
- private String sTopicUser = "";
- /** Unixtimestamp representing time when the topic was set. */
- private long nTopicTime = 0;
- /** Has this channel ever had a topic? */
- private boolean hadTopic = false;
-
- /** Known boolean-modes for channel. */
- private long nModes;
- /** Reference to the parser object that owns this channel, Used for modes. */
- private final IRCParser myParser; // Reference to parser object that owns this channel. Used for Modes
-
- /** Channel Name. */
- private final String sName;
-
- /** Hashtable containing references to ChannelClients. */
- private final Map<String, IRCChannelClientInfo> hChannelUserList = new Hashtable<String, IRCChannelClientInfo>();
- /** Hashtable storing values for modes set in the channel that use parameters. */
- private final Map<Character, String> hParamModes = new Hashtable<Character, String>();
- /** Hashtable storing list modes. */
- private final Map<Character, ArrayList<ChannelListModeItem>> hListModes = new Hashtable<Character, ArrayList<ChannelListModeItem>>();
- /**
- * LinkedList storing status of mode adding.
- * if an item is in this list for a mode, we are expecting new items for the list
- */
- private final List<Character> lAddingModes = new LinkedList<Character>();
- /** Modes waiting to be sent to the server. */
- private final List<String> lModeQueue = new LinkedList<String>();
- /** A Map to allow applications to attach misc data to this object */
- private Map myMap;
-
- /** Queue of requested list modes */
- private final Queue<Character> listModeQueue = new LinkedList<Character>();
- /** Listmode Queue Time */
- private long listModeQueueTime = System.currentTimeMillis();
- /** Have we asked the server for the list modes for this channel yet? */
- private boolean askedForListModes = false;
- /** Has OnChannelGotListModes ever been called for this channel? */
- private boolean hasGotListModes = false;
-
- /**
- * Create a new channel object.
- *
- * @param tParser Refernce to parser that owns this channelclient (used for modes)
- * @param name Channel name.
- */
- public IRCChannelInfo(final IRCParser tParser, final String name) {
- myMap = new HashMap<Object, Object>();
- myParser = tParser;
- sName = name;
- }
-
- /**
- * Get the listModeQueue.
- *
- * @return The listModeQueue
- */
- public Queue<Character> getListModeQueue() {
- Queue<Character> result = listModeQueue;
- final long now = System.currentTimeMillis();
- // Incase of breakage, if getListModeQueue() was last called greater than
- // 60 seconds ago, we reset the list.
- if (now-(30*1000) > listModeQueueTime) {
- result = new LinkedList<Character>();
- myParser.callDebugInfo(IRCParser.DEBUG_LMQ, "Resetting LMQ");
- }
- listModeQueueTime = now;
- return result;
- }
-
- /**
- * Ask the server for all the list modes for this channel.
- */
- public void requestListModes() {
- final IRCChannelClientInfo me = getChannelClient(myParser.getLocalClient());
-
- if (me == null) {
- // In a normal situation of non bouncer-brokenness this won't happen
- return;
- }
-
- askedForListModes = true;
-
- final String thisIRCD = myParser.getIRCD(true).toLowerCase();
- final boolean isFreenode = (thisIRCD.equals("hyperion") || thisIRCD.equals("dancer"));
- final boolean isUnreal = thisIRCD.equals("unreal");
- final boolean isStarChat = thisIRCD.equals("starchat");
- final boolean isHybrid = thisIRCD.equals("hybrid") || thisIRCD.equals("oftc-hybrid");
- final boolean isCharybdis = thisIRCD.equals("charybdis");
-
- // We are considered opped if we have a mode higher than voice (or if we have any modes if voice doesn't exist)
- long voiceValue = 0;
- if (myParser.prefixModes.get('v') != null) { voiceValue = myParser.prefixModes.get('v');}
- final boolean isOpped = me.getImportantModeValue() > voiceValue;
-
- int modecount = 1;
- if (!isUnreal && myParser.h005Info.containsKey("MODES")) {
- try {
- modecount = Integer.parseInt(myParser.h005Info.get("MODES"));
- } catch (NumberFormatException e) { /* use default modecount */}
- }
-
- // Support for potential future decent mode listing in the protocol
- //
- // See my proposal: http://shane.dmdirc.com/listmodes.php
- // Add listmode handler
- final boolean supportLISTMODE = myParser.h005Info.containsKey("LISTMODE");
-
- String listmodes = "";
- int i = 0;
- for (Character cTemp : myParser.chanModesOther.keySet()) {
- final int nTemp = myParser.chanModesOther.get(cTemp);
- if (nTemp == IRCParser.MODE_LIST) {
- if ((isFreenode || isHybrid || isCharybdis) && (cTemp == 'e' || cTemp == 'I') && !isOpped) {
- // IRCD doesn't allow non-ops to ask for these modes.
- continue;
- } else if (isStarChat && cTemp == 'H') {
- // IRCD Denies the mode exists
- continue;
- }
- i++;
- listmodes = listmodes + cTemp;
- if (i >= modecount && !supportLISTMODE) {
- myParser.sendString("MODE "+getName()+" "+listmodes, QueuePriority.LOW);
- i = 0;
- listmodes = "";
- }
- }
- }
- if (i > 0) {
- if (supportLISTMODE) {
- myParser.sendString("LISTMODE "+getName()+" "+listmodes, QueuePriority.LOW);
- } else {
- myParser.sendString("MODE "+getName()+" "+listmodes, QueuePriority.LOW);
- }
- }
- }
-
-
- /**
- * Has this channel ever had a topic? (even an empty one!)
- *
- * @return True if a topic has ever been known for this channel.
- */
- public synchronized boolean hadTopic() {
- return hadTopic;
- }
-
- /**
- * Change the value of hadTopic to true.
- */
- public synchronized void setHadTopic() {
- this.hadTopic = true;
- }
-
- /**
- * Have we ever asked the server for this channels listmodes?
- *
- * @return True if requestListModes() has ever been used, else false
- */
- public boolean hasAskedForListModes() {
- return askedForListModes;
- }
-
- /**
- * Returns true if OnChannelGotListModes ever been called for this channel.
- *
- * @return True if OnChannelGotListModes ever been called for this channel.
- */
- public boolean hasGotListModes() {
- return hasGotListModes;
- }
-
- /**
- * Set if OnChannelGotListModes ever been called for this channel.
- *
- * @param newValue new value for if OnChannelGotListModes ever been called for this channel.
- */
- protected void setHasGotListModes(final boolean newValue) {
- hasGotListModes = newValue;
- }
-
- /**
- * Set the Map object attatched to this object.
- *
- * @param newMap New Map to attatch.
- */
- public void setMap(final Map newMap) {
- myMap = newMap;
- }
-
- /**
- * Get the Map object attatched to this object.
- *
- * @return Map to attatched to this.
- */
- public Map getMap() {
- return myMap;
- }
-
- /**
- * Set if we are getting a names request or not.
- *
- * @param newValue if false, any new names reply will cause current known channelclients to be removed.
- */
- public void setAddingNames(final boolean newValue) { bAddingNames = newValue; }
-
- /**
- * Get if we are getting a names request or not.
- *
- * @return if false, any new names reply will cause current known channelclients to be removed.
- */
- public boolean isAddingNames() { return bAddingNames; }
-
- /** {@inheritDoc} */
- @Override
- public String getName() { return sName; }
-
- /** {@inheritDoc} */
- @Override
- public int getChannelClientCount() { return hChannelUserList.size(); }
-
- /** {@inheritDoc} */
- @Override
- public Collection<ChannelClientInfo> getChannelClients() {
- return new ArrayList<ChannelClientInfo>(hChannelUserList.values());
- }
-
- /**
- * Empty the channel (Remove all known channelclients).
- */
- protected void emptyChannel() {
- IRCClientInfo cTemp = null;
- for (IRCChannelClientInfo client : hChannelUserList.values()) {
- cTemp = client.getClient();
- cTemp.delChannelClientInfo(client);
- if (cTemp != myParser.getLocalClient() && !cTemp.checkVisibility()) {
- myParser.removeClient(cTemp);
- }
- }
- hChannelUserList.clear();
- }
-
- /** {@inheritDoc} */
- @Override
- public IRCChannelClientInfo getChannelClient(final String sWho) {
- return getChannelClient(sWho, false);
- }
-
- /** {@inheritDoc} */
- @Override
- public IRCChannelClientInfo getChannelClient(final String sWho, final boolean createFake) {
- final String who = myParser.getStringConverter().toLowerCase(IRCClientInfo.parseHost(sWho));
- if (hChannelUserList.containsKey(who)) {
- return hChannelUserList.get(who);
- }
- if (createFake) {
- return new IRCChannelClientInfo(myParser, (new IRCClientInfo(myParser, sWho)).setFake(true), this);
- } else {
- return null;
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public IRCChannelClientInfo getChannelClient(final ClientInfo cWho) {
- for (IRCChannelClientInfo client : hChannelUserList.values()) {
- if (client.getClient() == cWho) {
- return client;
- }
- }
- return null;
- }
-
- /**
- * Get the ChannelClientInfo object associated with a ClientInfo object.
- *
- * @param cClient Client object to be added to channel
- * @return ChannelClientInfo object added, or an existing object if already known on channel
- */
- protected IRCChannelClientInfo addClient(final IRCClientInfo cClient) {
- IRCChannelClientInfo cTemp = getChannelClient(cClient);
- if (cTemp == null) {
- cTemp = new IRCChannelClientInfo(myParser, cClient, this);
- hChannelUserList.put(myParser.getStringConverter().toLowerCase(cTemp.getClient().getNickname()), cTemp);
- }
- return cTemp;
- }
-
- /**
- * Remove ChannelClientInfo object associated with a ClientInfo object.
- *
- * @param cClient Client object to be removed from channel
- */
- protected void delClient(final IRCClientInfo cClient) {
- IRCChannelClientInfo cTemp = getChannelClient(cClient);
- if (cTemp != null) {
- final IRCClientInfo clTemp = cTemp.getClient();
- clTemp.delChannelClientInfo(cTemp);
- if (clTemp != myParser.getLocalClient() && !clTemp.checkVisibility()) {
- myParser.removeClient(clTemp);
- }
- hChannelUserList.remove(myParser.getStringConverter().toLowerCase(cTemp.getClient().getNickname()));
- }
- }
-
- /**
- * Rename a channelClient.
- *
- * @param oldNickname Nickname client used to be known as
- * @param cChannelClient ChannelClient object with updated client object
- */
- protected void renameClient(final String oldNickname, final IRCChannelClientInfo cChannelClient) {
- if (hChannelUserList.containsKey(oldNickname)) {
- final IRCChannelClientInfo cTemp = hChannelUserList.get(oldNickname);
- if (cTemp == cChannelClient) {
- // Remove the old key
- hChannelUserList.remove(oldNickname);
- // Add with the new key. (getNickname will return the new name not the
- // old one)
- hChannelUserList.put(myParser.getStringConverter().toLowerCase(cTemp.getClient().getNickname()), cTemp);
- }
- }
- }
-
- /**
- * Set the create time.
- *
- * @param nNewTime New unixtimestamp time for the channel creation (Seconds since epoch, not milliseconds)
- */
- protected void setCreateTime(final long nNewTime) { nCreateTime = nNewTime; }
- /**
- * Get the Create time.
- *
- * @return Unixtimestamp time for the channel creation (Seconds since epoch, not milliseconds)
- */
- public long getCreateTime() { return nCreateTime; }
-
- /**
- * Set the topic time.
- *
- * @param nNewTime New unixtimestamp time for the topic (Seconds since epoch, not milliseconds)
- */
- protected void setTopicTime(final long nNewTime) { nTopicTime = nNewTime; }
-
- /** {@inheritDoc} */
- @Override
- public long getTopicTime() { return nTopicTime; }
-
- /**
- * Set the topic.
- *
- * @param sNewTopic New contents of topic
- */
- protected void setInternalTopic(final String sNewTopic) { sTopic = sNewTopic; }
-
- /** {@inheritDoc} */
- @Override
- public String getTopic() { return sTopic; }
-
- /**
- * Set the topic creator.
- *
- * @param sNewUser New user who set the topic (nickname if gotten on connect, full host if seen by parser)
- */
- protected void setTopicUser(final String sNewUser) { sTopicUser = sNewUser; }
-
- /** {@inheritDoc} */
- @Override
- public String getTopicSetter() { return sTopicUser; }
-
- /**
- * Set the channel modes (as an integer).
- *
- * @param nNewMode new long representing channel modes. (Boolean only)
- */
- protected void setMode(final long nNewMode) { nModes = nNewMode; }
- /**
- * Get the channel modes (as an integer).
- *
- * @return long representing channel modes. (Boolean only)
- */
- public long getMode() { return nModes; }
-
- /** {@inheritDoc} */
- @Override
- public String getModes() {
- final StringBuilder sModes = new StringBuilder("+");
- final StringBuilder sModeParams = new StringBuilder();
- String sTemp = "";
- long nTemp = 0;
- final long nChanModes = this.getMode();
- for (char cTemp : myParser.chanModesBool.keySet()) {
- nTemp = myParser.chanModesBool.get(cTemp);
- if ((nChanModes & nTemp) == nTemp) { sModes.append(cTemp); }
- }
- for (char cTemp : hParamModes.keySet()) {
- sTemp = hParamModes.get(cTemp);
- if (!sTemp.isEmpty()) {
- sModes.append(cTemp);
- sModeParams.append(" ").append(this.getMode(cTemp));
- }
- }
-
- return sModes.append(sModeParams).toString();
- }
-
- /**
- * Set a channel mode that requires a parameter.
- *
- * @param cMode Character representing mode
- * @param sValue String repreenting value (if "" mode is unset)
- */
- protected void setModeParam(final Character cMode, final String sValue) {
- if (sValue.isEmpty()) {
- if (hParamModes.containsKey(cMode)) {
- hParamModes.remove(cMode);
- }
- } else {
- hParamModes.put(cMode, sValue);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMode(final char cMode) {
- if (hParamModes.containsKey(cMode)) {
- return hParamModes.get(cMode);
- }
- return "";
- }
-
- /**
- * Add/Remove a value to a channel list.
- *
- * @param givenMode Character representing mode
- * @param givenItem ChannelListModeItem representing the item
- * @param bAdd Add or remove the value. (true for add, false for remove)
- */
- protected void setListModeParam(final Character givenMode, final ChannelListModeItem givenItem, final boolean bAdd) {
- Character cMode = givenMode;
- ChannelListModeItem newItem = givenItem;
- if (!myParser.chanModesOther.containsKey(cMode) || myParser.chanModesOther.get(cMode) != IRCParser.MODE_LIST) { return; }
-
- // Hyperion sucks.
- if (cMode == 'b' || cMode == 'q') {
- final String thisIRCD = myParser.getIRCD(true).toLowerCase();
- if ((thisIRCD.equals("hyperion") || thisIRCD.equals("dancer"))) {
- if (cMode == 'b' && givenItem.getItem().charAt(0) == '%') {
- cMode = 'q';
- } else if (cMode == 'q' && givenItem.getItem().charAt(0) != '%') {
- cMode = 'b';
- }
- if (givenItem.getItem().charAt(0) == '%') {
- newItem = new ChannelListModeItem(givenItem.getItem().substring(1), givenItem.getOwner(), givenItem.getTime());
- }
- }
- }
-
- if (!hListModes.containsKey(cMode)) {
- hListModes.put(cMode, new ArrayList<ChannelListModeItem>());
- }
- final ArrayList<ChannelListModeItem> lModes = hListModes.get(cMode);
- for (int i = 0; i < lModes.size(); i++) {
- if (myParser.getStringConverter().equalsIgnoreCase(lModes.get(i).getItem(), newItem.getItem())) {
- if (bAdd) { return; }
- else {
- lModes.remove(i);
- break;
- }
- }
- }
- if (bAdd) { lModes.add(newItem); }
- }
-
- /** {@inheritDoc} */
- @Override
- public Collection<ChannelListModeItem> getListMode(final char cMode) {
- if (!myParser.chanModesOther.containsKey(cMode) || myParser.chanModesOther.get(cMode) != IRCParser.MODE_LIST) { return null; }
-
- if (!hListModes.containsKey(cMode)) {
- hListModes.put(cMode, new ArrayList<ChannelListModeItem>());
- }
- return hListModes.get(cMode);
- }
-
- /**
- * Get the "adding state" of a list mode.
- *
- * @param cMode Character representing mode
- * @return false if we are not expecting a 367 etc, else true.
- */
- public boolean getAddState(final Character cMode) {
- synchronized (lAddingModes) {
- return lAddingModes.contains(cMode);
- }
- }
-
- /**
- * Get the "adding state" of a list mode.
- *
- * @param cMode Character representing mode
- * @param newState change the value returned by getAddState
- */
- protected void setAddState(final Character cMode, final boolean newState) {
- synchronized (lAddingModes) {
- if (newState) {
- lAddingModes.add(cMode);
- } else {
- if (lAddingModes.contains(cMode)) { lAddingModes.remove(cMode); }
- }
- }
- }
-
- /**
- * Reset the "adding state" of *all* list modes.
- */
- protected void resetAddState() {
- synchronized (lAddingModes) {
- lAddingModes.clear();
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void alterMode(final boolean positive, final Character mode, final String parameter) {
- int modecount = 1;
- int modeint = 0;
- String modestr = "";
- if (myParser.h005Info.containsKey("MODES")) {
- try {
- modecount = Integer.parseInt(myParser.h005Info.get("MODES"));
- } catch (NumberFormatException e) {
- modecount = 1;
- }
- }
- if (!myParser.isUserSettable(mode)) { return; }
-
- modestr = ((positive) ? "+" : "-") + mode;
- if (myParser.chanModesBool.containsKey(mode)) {
- final String teststr = ((positive) ? "-" : "+") + mode;
- if (lModeQueue.contains(teststr)) {
- lModeQueue.remove(teststr);
- return;
- } else if (lModeQueue.contains(modestr)) {
- return;
- }
- } else {
- // May need a param
- if (myParser.prefixModes.containsKey(mode)) {
- modestr = modestr + " " + parameter;
- } else {
- modeint = myParser.chanModesOther.get(mode);
- if ((modeint & IRCParser.MODE_LIST) == IRCParser.MODE_LIST) {
- modestr = modestr + " " + parameter;
- } else if (!positive && ((modeint & IRCParser.MODE_UNSET) == IRCParser.MODE_UNSET)) {
- modestr = modestr + " " + parameter;
- } else if (positive && ((modeint & IRCParser.MODE_SET) == IRCParser.MODE_SET)) {
- // Does mode require a param to unset aswell?
- // We might need to queue an unset first
- if (((modeint & IRCParser.MODE_UNSET) == IRCParser.MODE_UNSET)) {
- final String existingParam = getMode(mode);
- if (!existingParam.isEmpty()) {
- final String reverseModeStr = "-" + mode + " " + existingParam;
-
- myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Queueing mode: %s", reverseModeStr);
- lModeQueue.add(reverseModeStr);
- if (lModeQueue.size() == modecount) { flushModes(); }
- }
- }
- modestr = modestr + " " + parameter;
- }
- }
- }
- myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Queueing mode: %s", modestr);
- lModeQueue.add(modestr);
- if (lModeQueue.size() == modecount) { flushModes(); }
- }
-
- /** {@inheritDoc} */
- @Override
- public void flushModes() {
- if (lModeQueue.isEmpty()) { return; }
- final StringBuilder positivemode = new StringBuilder();
- final StringBuilder positiveparam = new StringBuilder();
- final StringBuilder negativemode = new StringBuilder();
- final StringBuilder negativeparam = new StringBuilder();
- final StringBuilder sendModeStr = new StringBuilder();
- String modestr;
- String[] modeparam;
- boolean positive;
- for (int i = 0; i < lModeQueue.size(); ++i) {
- modeparam = lModeQueue.get(i).split(" ");
- modestr = modeparam[0];
- positive = modestr.charAt(0) == '+';
- if (positive) {
- positivemode.append(modestr.charAt(1));
- if (modeparam.length > 1) { positiveparam.append(" ").append(modeparam[1]); }
- } else {
- negativemode.append(modestr.charAt(1));
- if (modeparam.length > 1) { negativeparam.append(" ").append(modeparam[1]); }
- }
- }
- if (negativemode.length() > 0) { sendModeStr.append("-").append(negativemode); }
- if (positivemode.length() > 0) { sendModeStr.append("+").append(positivemode); }
- if (negativeparam.length() > 0) { sendModeStr.append(negativeparam); }
- if (positiveparam.length() > 0) { sendModeStr.append(positiveparam); }
- myParser.callDebugInfo(IRCParser.DEBUG_INFO, "Sending mode: %s", sendModeStr.toString());
- myParser.sendRawMessage("MODE " + sName + " " + sendModeStr.toString());
- clearModeQueue();
- }
-
- /**
- * This function will clear the mode queue (WITHOUT Sending).
- */
- public void clearModeQueue() {
- lModeQueue.clear();
- }
-
- /** {@inheritDoc} */
- @Override
- public void sendMessage(final String message) {
- if (message.isEmpty()) { return; }
-
- myParser.sendString("PRIVMSG " + sName + " :" + message);
- }
-
- /**
- * Send a notice message to a target.
- *
- * @param sMessage Message to send
- */
- public void sendNotice(final String sMessage) {
- if (sMessage.isEmpty()) { return; }
-
- myParser.sendString("NOTICE " + sName + " :" + sMessage);
- }
-
- /** {@inheritDoc} */
- @Override
- public void sendAction(final String action) {
- if (action.isEmpty()) { return; }
- sendCTCP("ACTION", action);
- }
-
- /**
- * Send a CTCP to a target.
- *
- * @param sType Type of CTCP
- * @param sMessage Optional Additional Parameters
- */
- public void sendCTCP(final String sType, String sMessage) {
- if (sType.isEmpty()) { return; }
- final char char1 = (char) 1;
- if (!sMessage.isEmpty()) { sMessage = " " + sMessage; }
- sendMessage(char1 + sType.toUpperCase() + sMessage + char1);
- }
-
- /**
- * Send a CTCPReply to a target.
- *
- * @param sType Type of CTCP
- * @param sMessage Optional Additional Parameters
- */
- public void sendCTCPReply(final String sType, String sMessage) {
- if (sType.isEmpty()) { return; }
- final char char1 = (char) 1;
- if (!sMessage.isEmpty()) { sMessage = " " + sMessage; }
- sendNotice(char1 + sType.toUpperCase() + sMessage + char1);
- }
-
- /**
- * Get a string representation of the Channel.
- *
- * @return String representation of the Channel.
- */
- @Override
- public String toString() { return sName; }
-
- /** {@inheritDoc} */
- @Override
- public Parser getParser() { return myParser; }
-
- /** {@inheritDoc} */
- @Override
- public void part(final String reason) {
- myParser.partChannel(sName, reason);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setTopic(final String topic) {
- myParser.sendRawMessage("TOPIC " + sName + " :" + topic);
- }
-
- /** {@inheritDoc} */
- @Override
- public void sendWho() {
- myParser.sendRawMessage("WHO " + sName);
- }
-
- }
|