You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChannelClientInfo.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. *
  22. * SVN: $Id$
  23. */
  24. package uk.org.ownage.dmdirc.parser;
  25. import java.util.Enumeration;
  26. /**
  27. * Contains information about a client on a channel.
  28. *
  29. * @author Shane Mc Cormack
  30. * @author Chris Smith
  31. * @version $Id$
  32. * @see IRCParser
  33. */
  34. public class ChannelClientInfo {
  35. /** Reference to ClientInfo object this represents. */
  36. private ClientInfo cClient = null;
  37. /** Integer representation of the channel modes assocated with this user. */
  38. private int nModes = 0;
  39. /** Reference to the parser object that owns this channel, Used for modes. */
  40. private IRCParser myParser;
  41. /**
  42. * Create a ChannelClient instance of a CLient.
  43. *
  44. * @param tParser Refernce to parser that owns this channelclient (used for modes)
  45. * @param client Client that this channelclient represents
  46. */
  47. public ChannelClientInfo(final IRCParser tParser, final ClientInfo client) { myParser = tParser; cClient = client; }
  48. /**
  49. * Get the client object represented by this channelclient.
  50. *
  51. * @return Client object represented by this channelclient
  52. */
  53. public ClientInfo getClient() { return cClient; }
  54. /**
  55. * Get the nickname of the client object represented by this channelclient.
  56. *
  57. * @return Nickname of the Client object represented by this channelclient
  58. */
  59. public String getNickname() { return cClient.getNickname(); }
  60. /**
  61. * Set the modes this client has (Prefix modes).
  62. *
  63. * @param nNewMode integer representing the modes this client has.
  64. */
  65. public void setChanMode(final int nNewMode) { nModes = nNewMode; }
  66. /**
  67. * Get the modes this client has (Prefix modes).
  68. *
  69. * @return integer representing the modes this client has.
  70. */
  71. public int getChanMode() { return nModes; }
  72. /**
  73. * Get the modes this client has (Prefix modes) as a string.
  74. * Returns all known modes that the client has.
  75. * getChanModeStr(false).charAt(0) can be used to get the highest mode (o)
  76. * getChanModeStr(true).charAt(0) can be used to get the highest prefix (@)
  77. *
  78. * @param bPrefix if this is true, prefixes will be returned (@+) not modes (ov)
  79. * @return String representing the modes this client has.
  80. */
  81. public String getChanModeStr(final boolean bPrefix) {
  82. String sModes = "";
  83. Character cTemp;
  84. int nTemp = 0, nCurrentModes = this.getChanMode();
  85. // for (int i = 1; i < myParser.nNextKeyPrefix; i = i*2) {
  86. for (int i = myParser.nNextKeyPrefix; i > 0; i = i/2) {
  87. if ((nCurrentModes & i) == i) {
  88. for (final Enumeration e = myParser.hPrefixModes.keys(); e.hasMoreElements();) {
  89. cTemp = (Character)e.nextElement();
  90. nTemp = myParser.hPrefixModes.get(cTemp);
  91. if (nTemp == i) {
  92. if (bPrefix) { cTemp = myParser.hPrefixMap.get(cTemp); }
  93. sModes = sModes+cTemp;
  94. break;
  95. }
  96. }
  97. }
  98. }
  99. return sModes;
  100. }
  101. /**
  102. * Get the value of the most important mode this client has (Prefix modes).
  103. * A higher value, is a more important mode, 0 = no modes.
  104. *
  105. * @return integer representing the value of the most important mode.
  106. */
  107. public int getImportantModeValue() {
  108. for (int i = myParser.nNextKeyPrefix; i > 0; i = i/2) {
  109. if ((nModes & i) == i) { return i; }
  110. }
  111. return 0;
  112. }
  113. /**
  114. * Get the most important mode this client has (o, v etc).
  115. *
  116. * @return String representing the most important mode.
  117. */
  118. public String getImportantMode() {
  119. String sModes = this.getChanModeStr(false);
  120. if (!sModes.equals("")) { sModes = ""+sModes.charAt(0); }
  121. return sModes;
  122. }
  123. /**
  124. * Get the most important prefix this client has (o, v etc).
  125. *
  126. * @return String representing the most important mode.
  127. */
  128. public String getImportantModePrefix() {
  129. String sModes = this.getChanModeStr(true);
  130. if (!sModes.equals("")) { sModes = ""+sModes.charAt(0); }
  131. return sModes;
  132. }
  133. /**
  134. * Get the String Value of ChannelClientInfo (ie @Nickname).
  135. *
  136. * @return String Value of user (inc prefix) (ie @Nickname)
  137. */
  138. public String toString() {
  139. String sModes = this.getImportantModePrefix();
  140. return sModes+this.getNickname();
  141. }
  142. /**
  143. * Get the "Complete" String Value of ChannelClientInfo (ie @+Nickname).
  144. *
  145. * @return String Value of user (inc prefix) (ie @+Nickname)
  146. */
  147. public String toFullString() { return this.getChanModeStr(true)+this.getNickname(); }
  148. /**
  149. * Get SVN Version information.
  150. *
  151. * @return SVN Version String
  152. */
  153. public static String getSvnInfo () { return "$Id$"; }
  154. }