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.

IRCDataInEvent.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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. package com.dmdirc.parser.irc.events;
  23. import com.dmdirc.parser.events.DataInEvent;
  24. import com.dmdirc.parser.irc.IRCParser;
  25. import com.dmdirc.parser.irc.IRCReader.ReadLine;
  26. import java.time.LocalDateTime;
  27. import static com.google.common.base.Preconditions.checkNotNull;
  28. /**
  29. * Called on every incoming line BEFORE parsing.
  30. *
  31. * This extends the standard DataInEvent to provide access to IRC-Specific bits.
  32. */
  33. public class IRCDataInEvent extends DataInEvent {
  34. private final ReadLine line;
  35. private final String[] tokenisedData;
  36. private final String action;
  37. private final int numeric;
  38. private final boolean isNumeric;
  39. public IRCDataInEvent(final IRCParser parser, final LocalDateTime date, final ReadLine line) {
  40. super(parser, date, checkNotNull(line).getLine());
  41. this.line = line;
  42. tokenisedData = line.getTokens();
  43. // Action is slightly more complicated than for DataOut
  44. if (tokenisedData.length > 1) {
  45. if (tokenisedData[0].length() > 0 && tokenisedData[0].charAt(0) == ':') {
  46. if (tokenisedData[1].equalsIgnoreCase("NOTICE") && !parser.got001) {
  47. action = "NOTICE AUTH";
  48. } else {
  49. action = tokenisedData[1].toUpperCase();
  50. }
  51. } else if (tokenisedData[0].equalsIgnoreCase("NOTICE")) {
  52. action = "NOTICE AUTH";
  53. } else {
  54. action = tokenisedData[0].toUpperCase();
  55. }
  56. } else {
  57. action = "";
  58. }
  59. int num = -1;
  60. try { num = Integer.parseInt(action); } catch (final NumberFormatException e) { }
  61. numeric = num;
  62. isNumeric = (numeric != -1);
  63. }
  64. public String[] getTokenisedData() {
  65. return tokenisedData;
  66. }
  67. public ReadLine getLine() {
  68. return line;
  69. }
  70. public String getAction() {
  71. return action;
  72. }
  73. public boolean isNumeric() {
  74. return isNumeric;
  75. }
  76. public int getNumeric() {
  77. return numeric;
  78. }
  79. }