123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /*
- * Copyright (c) 2006-2014 DMDirc Developers
- *
- * 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.interfaces.ChannelClientInfo;
- import com.dmdirc.parser.interfaces.ChannelInfo;
-
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.Map;
-
- /**
- * Contains information about a client on a channel.
- *
- * @see IRCParser
- */
- public class IRCChannelClientInfo implements ChannelClientInfo {
-
- /** Reference to ClientInfo object this represents. */
- private final IRCClientInfo cClient;
- /** The channel modes associated with this user. */
- private String modes = "";
- /** Manager to use when dealing with prefix modes. */
- private final PrefixModeManager modeManager;
- /** The parser to use to kick people. */
- private final IRCParser parser;
- /** Reference to the channel object that owns this channel client. */
- private final ChannelInfo myChannel;
- /** A Map to allow applications to attach misc data to this object. */
- private Map<Object, Object> myMap;
-
- /**
- * Create a ChannelClient instance of a CLient.
- *
- * @param tParser Refernce to parser that owns this channelclient (used for modes)
- * @param prefixModeManager Manager to use to access prefix mode information.
- * @param client Client that this channelclient represents
- * @param channel Channel that owns this channelclient
- */
- public IRCChannelClientInfo(final IRCParser tParser, final PrefixModeManager prefixModeManager,
- final IRCClientInfo client, final ChannelInfo channel) {
- myMap = new HashMap<>();
- modeManager = prefixModeManager;
- parser = tParser;
- cClient = client;
- myChannel = channel;
- cClient.addChannelClientInfo(this);
- }
-
- /**
- * Set the Map object attatched to this object.
- *
- * @param newMap New Map to attatch.
- * @see #getMap
- */
- public void setMap(final Map<Object, Object> newMap) {
- myMap = newMap;
- }
-
- @Override
- public Map<Object, Object> getMap() {
- return myMap;
- }
-
- @Override
- public IRCClientInfo getClient() {
- return cClient;
- }
-
- @Override
- public ChannelInfo getChannel() {
- return myChannel;
- }
-
- /**
- * Get the nickname of the client object represented by this channelclient.
- *
- * @return Nickname of the Client object represented by this channelclient
- */
- public String getNickname() {
- return cClient.getNickname();
- }
-
- /**
- * Set the modes this client has (Prefix modes).
- *
- * @param modes The new modes this client has, sorted most-to-least important.
- */
- public void setChanMode(final String modes) {
- this.modes = modes;
- }
-
- @Override
- public String getAllModes() {
- return modes;
- }
-
- @Override
- public String getAllModesPrefix() {
- return modeManager.getPrefixesFor(modes);
- }
-
- @Override
- public String getImportantMode() {
- return modes.isEmpty() ? "" : modes.substring(0, 1);
- }
-
- @Override
- public String getImportantModePrefix() {
- return modes.isEmpty() ? "" : getAllModesPrefix().substring(0, 1);
- }
-
- /**
- * Get the String Value of ChannelClientInfo (e.g. @Nickname).
- *
- * @return String Value of user (inc prefix) (e.g. @Nickname)
- */
- @Override
- public String toString() {
- return getImportantModePrefix() + getNickname();
- }
-
- @Override
- public void kick(final String message) {
- parser.sendString("KICK " + myChannel + ' ' + getNickname(), message);
- }
-
- /**
- * Get the "Complete" String Value of ChannelClientInfo (ie @+Nickname).
- *
- * @return String Value of user (inc prefix) (ie @+Nickname)
- */
- public String toFullString() {
- return getAllModesPrefix() + getNickname();
- }
-
- @Override
- public int compareTo(final ChannelClientInfo arg0) {
- return modeManager.compareImportantModes(getAllModes(), arg0.getAllModes());
- }
-
- @Override
- public Comparator<String> getImportantModeComparator() {
- return modeManager::compareImportantModes;
- }
-
- /**
- * Determines if this client is opped or not.
- *
- * @return True if the client is opped, false otherwise.
- */
- public boolean isOpped() {
- return modeManager.isOpped(getAllModes());
- }
-
- /**
- * Adds the specified mode to this client model.
- *
- * @param mode The mode to be added.
- */
- public void addMode(final char mode) {
- modes = modeManager.insertMode(modes, mode);
- }
-
- /**
- * Removes the specified mode from this client model.
- *
- * @param mode The mode to be removed.
- */
- public void removeMode(final char mode) {
- modes = modeManager.removeMode(modes, mode);
- }
- }
|