| 1 | // $Id$
|
|---|
| 2 | using System;
|
|---|
| 3 | using System.Collections;
|
|---|
| 4 | using System.Text;
|
|---|
| 5 | using System.Diagnostics;
|
|---|
| 6 |
|
|---|
| 7 | namespace Circuit.Net.Irc
|
|---|
| 8 | {
|
|---|
| 9 | public abstract class
|
|---|
| 10 | IRCMessage
|
|---|
| 11 | {
|
|---|
| 12 | private Boolean _isServerMessage = false;
|
|---|
| 13 | private String _rawMessage = "";
|
|---|
| 14 | private String _senderHost = "";
|
|---|
| 15 | private String _senderNick = "";
|
|---|
| 16 | private String _sender = "";
|
|---|
| 17 | private String _prefix = "";
|
|---|
| 18 | private String _command = "";
|
|---|
| 19 | private String _commandParam = "";
|
|---|
| 20 | private String[] _commandParams;
|
|---|
| 21 |
|
|---|
| 22 | protected void
|
|---|
| 23 | SetCommand(String command)
|
|---|
| 24 | {
|
|---|
| 25 | _command = command;
|
|---|
| 26 | }
|
|---|
| 27 | private void
|
|---|
| 28 | SetPrefix()
|
|---|
| 29 | {
|
|---|
| 30 | if (_senderNick == "")
|
|---|
| 31 | _prefix = "";
|
|---|
| 32 | else if (_senderHost == "")
|
|---|
| 33 | _prefix = _senderNick;
|
|---|
| 34 | else
|
|---|
| 35 | _prefix = _senderNick + "!" + _senderHost;
|
|---|
| 36 |
|
|---|
| 37 | }
|
|---|
| 38 | public Boolean IsServerMessage
|
|---|
| 39 | {
|
|---|
| 40 | get { return _isServerMessage; }
|
|---|
| 41 | set { _isServerMessage = value; }
|
|---|
| 42 | }
|
|---|
| 43 | public String Sender
|
|---|
| 44 | {
|
|---|
| 45 | get { return _sender; }
|
|---|
| 46 | set
|
|---|
| 47 | {
|
|---|
| 48 | String[] part = Split(value, new char[] {'!'}, 2);
|
|---|
| 49 | if (part.Length == 2) {
|
|---|
| 50 | // nick!~user@host
|
|---|
| 51 | _senderNick = part[0];
|
|---|
| 52 | _senderHost = part[1];
|
|---|
| 53 | } else {
|
|---|
| 54 | // nick
|
|---|
| 55 | _senderHost = "";
|
|---|
| 56 | _senderNick = value;
|
|---|
| 57 | }
|
|---|
| 58 | _sender = value;
|
|---|
| 59 | this.SetPrefix();
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | public String SenderHost
|
|---|
| 63 | {
|
|---|
| 64 | get { return _senderHost; }
|
|---|
| 65 | set { _senderHost = value; this.SetPrefix(); }
|
|---|
| 66 | }
|
|---|
| 67 | public String SenderNick
|
|---|
| 68 | {
|
|---|
| 69 | get { return _senderNick; }
|
|---|
| 70 | set { _senderNick = value; this.SetPrefix(); }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | public String Prefix
|
|---|
| 74 | {
|
|---|
| 75 | get { return _prefix; }
|
|---|
| 76 | set { this.Sender = value; }
|
|---|
| 77 | }
|
|---|
| 78 | public String Command
|
|---|
| 79 | {
|
|---|
| 80 | get { return _command; }
|
|---|
| 81 | }
|
|---|
| 82 | public String CommandParam
|
|---|
| 83 | {
|
|---|
| 84 | get {
|
|---|
| 85 | StringBuilder sb = new StringBuilder();
|
|---|
| 86 | for (Int32 i = 0; i < _commandParams.Length; i++) {
|
|---|
| 87 | if (i+1 == _commandParams.Length || _commandParams[i+1] == null || _commandParams[i+1] == "") {
|
|---|
| 88 | sb.Append(":");
|
|---|
| 89 | sb.Append(_commandParams[i]);
|
|---|
| 90 | sb.Append(" ");
|
|---|
| 91 | break;
|
|---|
| 92 | } else {
|
|---|
| 93 | sb.Append(_commandParams[i]);
|
|---|
| 94 | sb.Append(" ");
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 | sb.Remove(sb.Length-1, 1);
|
|---|
| 98 | _commandParam = sb.ToString();
|
|---|
| 99 |
|
|---|
| 100 | //return _commandParam;
|
|---|
| 101 | return sb.ToString();
|
|---|
| 102 | }
|
|---|
| 103 | set {
|
|---|
| 104 | String[] param = value.Split(new Char[]{' '});
|
|---|
| 105 | _commandParam = value;
|
|---|
| 106 | _commandParams = new String[15];
|
|---|
| 107 | for (Int32 i = 0; i < 15; i++) {
|
|---|
| 108 | if (i < param.Length && i < _commandParams.Length) {
|
|---|
| 109 | if (param[i].StartsWith(":")) {
|
|---|
| 110 | _commandParams[i] = String.Join(" ", param, i, param.Length - i).Substring(1);
|
|---|
| 111 | break;
|
|---|
| 112 | } else {
|
|---|
| 113 | _commandParams[i] = param[i];
|
|---|
| 114 | }
|
|---|
| 115 | } else {
|
|---|
| 116 | _commandParams[i] = "";
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | public String[] CommandParams
|
|---|
| 122 | {
|
|---|
| 123 | get { return _commandParams; }
|
|---|
| 124 | set { _commandParams = value; }
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | public String RawMessage
|
|---|
| 128 | {
|
|---|
| 129 | get {
|
|---|
| 130 | StringBuilder sb = new StringBuilder();
|
|---|
| 131 | if (_prefix.Length != 0) {
|
|---|
| 132 | sb.Append(":");
|
|---|
| 133 | sb.Append(_prefix);
|
|---|
| 134 | sb.Append(" ");
|
|---|
| 135 | }
|
|---|
| 136 | sb.Append(_command);
|
|---|
| 137 | sb.Append(" ");
|
|---|
| 138 | sb.Append(this.CommandParam);
|
|---|
| 139 |
|
|---|
| 140 | //return _rawMessage;
|
|---|
| 141 | return sb.ToString();
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | public new virtual String
|
|---|
| 146 | ToString()
|
|---|
| 147 | {
|
|---|
| 148 | return this.RawMessage;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | public
|
|---|
| 152 | IRCMessage(String raw)
|
|---|
| 153 | {
|
|---|
| 154 | String[] parts;
|
|---|
| 155 | _rawMessage = raw;
|
|---|
| 156 |
|
|---|
| 157 | try {
|
|---|
| 158 | if (raw.StartsWith(":")) {
|
|---|
| 159 | parts = Split(raw, new Char[]{' '}, 3);
|
|---|
| 160 | _prefix = parts[0].Substring(1);
|
|---|
| 161 | _command = parts[1];
|
|---|
| 162 | _commandParam = parts[2];
|
|---|
| 163 | } else {
|
|---|
| 164 | parts = Split(raw, new Char[]{' '}, 2);
|
|---|
| 165 | _command = parts[0];
|
|---|
| 166 | _commandParam = parts[1];
|
|---|
| 167 | _prefix = "";
|
|---|
| 168 | }
|
|---|
| 169 | } catch (IndexOutOfRangeException) {
|
|---|
| 170 | throw new IRCInvalidMessageException(raw);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | this.CommandParam = _commandParam;
|
|---|
| 174 | this.Sender = _prefix;
|
|---|
| 175 | if (_prefix.Length == 0)
|
|---|
| 176 | this.IsServerMessage = false;
|
|---|
| 177 | }
|
|---|
| 178 | public
|
|---|
| 179 | IRCMessage()
|
|---|
| 180 | {
|
|---|
| 181 | _commandParams = new String[15];
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | public static IRCMessage
|
|---|
| 185 | CreateMessage(String raw)
|
|---|
| 186 | {
|
|---|
| 187 | //Trace.WriteLine(raw);
|
|---|
| 188 | OtherMessage om = new OtherMessage(raw);
|
|---|
| 189 |
|
|---|
| 190 | switch (om.Command.ToUpper()) {
|
|---|
| 191 | case "NOTICE":
|
|---|
| 192 | return new NoticeMessage(raw);
|
|---|
| 193 | case "PRIVMSG":
|
|---|
| 194 | return new PrivMsgMessage(raw);
|
|---|
| 195 | case "NICK":
|
|---|
| 196 | return new NickMessage(raw);
|
|---|
| 197 | case "JOIN":
|
|---|
| 198 | return new JoinMessage(raw);
|
|---|
| 199 | case "PART":
|
|---|
| 200 | return new PartMessage(raw);
|
|---|
| 201 | case "QUIT":
|
|---|
| 202 | return new QuitMessage(raw);
|
|---|
| 203 | case "TOPIC":
|
|---|
| 204 | return new TopicMessage(raw);
|
|---|
| 205 | case "USER":
|
|---|
| 206 | return new UserMessage(raw);
|
|---|
| 207 | case "MODE":
|
|---|
| 208 | return new ModeMessage(raw);
|
|---|
| 209 | default: //case "372": case "001": case "002":
|
|---|
| 210 | try {
|
|---|
| 211 | if (Int32.Parse(om.Command) > 0)
|
|---|
| 212 | return new NumericReplyMessage(raw);
|
|---|
| 213 | } catch (FormatException) {
|
|---|
| 214 | }
|
|---|
| 215 | return om;
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | // TODO: .NET CF
|
|---|
| 220 | private String[] Split(String str, Char[] delim, Int32 count)
|
|---|
| 221 | {
|
|---|
| 222 | String[] parts = str.Split(delim);
|
|---|
| 223 | String[] partsNew = new String[count];
|
|---|
| 224 | if (count > parts.Length)
|
|---|
| 225 | {
|
|---|
| 226 | count = parts.Length;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | Int32 maxIndex = count-1;
|
|---|
| 230 | StringBuilder sb = new StringBuilder();
|
|---|
| 231 | for (Int32 i = 0; i < parts.Length; i++)
|
|---|
| 232 | {
|
|---|
| 233 | if (i < maxIndex)
|
|---|
| 234 | {
|
|---|
| 235 | partsNew[i] = parts[i];
|
|---|
| 236 | }
|
|---|
| 237 | else
|
|---|
| 238 | {
|
|---|
| 239 | // TODO: delim[0] => new Char{ ... }
|
|---|
| 240 | sb.Append(parts[i]).Append(delim[0]);
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 | sb.Length = sb.Length - 1;
|
|---|
| 244 | partsNew[maxIndex] = sb.ToString();
|
|---|
| 245 |
|
|---|
| 246 | return partsNew;
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | public class
|
|---|
| 251 | OtherMessage : IRCMessage
|
|---|
| 252 | {
|
|---|
| 253 | public
|
|---|
| 254 | OtherMessage(String raw) : base(raw)
|
|---|
| 255 | {
|
|---|
| 256 | }
|
|---|
| 257 | public override String
|
|---|
| 258 | ToString()
|
|---|
| 259 | {
|
|---|
| 260 | return this.RawMessage;
|
|---|
| 261 | }
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | public class
|
|---|
| 265 | NumericReplyMessage : IRCMessage
|
|---|
| 266 | {
|
|---|
| 267 | private Int32 _replyNumber = 0;
|
|---|
| 268 | private String _content;
|
|---|
| 269 |
|
|---|
| 270 | public
|
|---|
| 271 | NumericReplyMessage(Int32 i)
|
|---|
| 272 | {
|
|---|
| 273 | this.SetCommand(i.ToString("000"));
|
|---|
| 274 | _replyNumber = i;
|
|---|
| 275 | }
|
|---|
| 276 | public
|
|---|
| 277 | NumericReplyMessage(String raw) : base(raw)
|
|---|
| 278 | {
|
|---|
| 279 | _replyNumber = Int32.Parse(this.Command);
|
|---|
| 280 | //this.Content = this.CommandParams[1];
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | public Int32
|
|---|
| 284 | ReplyNumber
|
|---|
| 285 | {
|
|---|
| 286 | get { return _replyNumber; }
|
|---|
| 287 | set { _replyNumber = value; this.SetCommand(value.ToString("000")); }
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | [Obsolete]
|
|---|
| 291 | public String
|
|---|
| 292 | ReplyNumberName
|
|---|
| 293 | {
|
|---|
| 294 | get
|
|---|
| 295 | {
|
|---|
| 296 | //if (_replyNumber < 400)
|
|---|
| 297 | //return Enum.GetName(typeof(NumericReply), _replyNumber);
|
|---|
| 298 | //else
|
|---|
| 299 | //return Enum.GetName(typeof(ErrorReply), _replyNumber);
|
|---|
| 300 | return String.Empty;
|
|---|
| 301 | }
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | public override String
|
|---|
| 305 | ToString()
|
|---|
| 306 | {
|
|---|
| 307 | try {
|
|---|
| 308 | return _replyNumber.ToString("000") + ": " + this.CommandParam;
|
|---|
| 309 | } catch (ArgumentException e) {
|
|---|
| 310 | //Trace.WriteLine(e);
|
|---|
| 311 | return _replyNumber.ToString("000") + ": " + this.CommandParam;
|
|---|
| 312 | }
|
|---|
| 313 | //return _rawMessage;
|
|---|
| 314 | }
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | public class
|
|---|
| 318 | PrivMsgMessage : IRCMessage
|
|---|
| 319 | {
|
|---|
| 320 | private String _receiver;
|
|---|
| 321 | private String _content;
|
|---|
| 322 |
|
|---|
| 323 | public String Receiver
|
|---|
| 324 | {
|
|---|
| 325 | get { return _receiver; }
|
|---|
| 326 | set { this.CommandParams[0] = _receiver = value; }
|
|---|
| 327 | }
|
|---|
| 328 | public String Content
|
|---|
| 329 | {
|
|---|
| 330 | set { this.CommandParams[1] = _content = value; }
|
|---|
| 331 | get { return _content; }
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | public
|
|---|
| 335 | PrivMsgMessage() : base()
|
|---|
| 336 | {
|
|---|
| 337 | this.SetCommand("PRIVMSG");
|
|---|
| 338 | }
|
|---|
| 339 | public
|
|---|
| 340 | PrivMsgMessage(String raw) : base(raw)
|
|---|
| 341 | {
|
|---|
| 342 | this.Receiver = this.CommandParams[0];
|
|---|
| 343 | this.Content = this.CommandParams[1];
|
|---|
| 344 | }
|
|---|
| 345 | public
|
|---|
| 346 | PrivMsgMessage(String receiver, String message) : base()
|
|---|
| 347 | {
|
|---|
| 348 | this.SetCommand("PRIVMSG");
|
|---|
| 349 | this.Receiver = receiver;
|
|---|
| 350 | this.Content = message;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | public override String
|
|---|
| 354 | ToString()
|
|---|
| 355 | {
|
|---|
| 356 | return String.Format("PrivMsg: ({0}->{1}) {2}", this.SenderNick, _receiver, this.Content);
|
|---|
| 357 | }
|
|---|
| 358 | }
|
|---|
| 359 | public class
|
|---|
| 360 | NickMessage : IRCMessage
|
|---|
| 361 | {
|
|---|
| 362 | private String _newNick;
|
|---|
| 363 | public String NewNick
|
|---|
| 364 | {
|
|---|
| 365 | get { return _newNick; }
|
|---|
| 366 | set { this.CommandParams[0] = _newNick = value; }
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | public
|
|---|
| 370 | NickMessage() : base()
|
|---|
| 371 | {
|
|---|
| 372 | this.SetCommand("NICK");
|
|---|
| 373 | }
|
|---|
| 374 | public
|
|---|
| 375 | NickMessage(String raw) : base(raw)
|
|---|
| 376 | {
|
|---|
| 377 | _newNick = this.CommandParams[0];
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | public override String
|
|---|
| 381 | ToString()
|
|---|
| 382 | {
|
|---|
| 383 | if (this.SenderNick.Length == 0)
|
|---|
| 384 | return String.Format("Nick: {0}", _newNick);
|
|---|
| 385 | else
|
|---|
| 386 | return String.Format("Nick: {0} -> {1}", this.SenderNick, _newNick);
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 | public class
|
|---|
| 390 | NoticeMessage : IRCMessage
|
|---|
| 391 | {
|
|---|
| 392 | private String _receiver;
|
|---|
| 393 | private String _content;
|
|---|
| 394 | public String Receiver
|
|---|
| 395 | {
|
|---|
| 396 | get { return _receiver; }
|
|---|
| 397 | set { this.CommandParams[0] = _receiver = value; }
|
|---|
| 398 | }
|
|---|
| 399 | public String Content
|
|---|
| 400 | {
|
|---|
| 401 | set { this.CommandParams[1] = _content = value; }
|
|---|
| 402 | get { return _content; }
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | public
|
|---|
| 406 | NoticeMessage() : base()
|
|---|
| 407 | {
|
|---|
| 408 | this.SetCommand("NOTICE");
|
|---|
| 409 | }
|
|---|
| 410 | public
|
|---|
| 411 | NoticeMessage(String raw) : base(raw)
|
|---|
| 412 | {
|
|---|
| 413 | this.Receiver = this.CommandParams[0];
|
|---|
| 414 | this.Content = this.CommandParams[1];
|
|---|
| 415 | }
|
|---|
| 416 | public
|
|---|
| 417 | NoticeMessage(String receiver, String message) : base()
|
|---|
| 418 | {
|
|---|
| 419 | this.SetCommand("NOTICE");
|
|---|
| 420 | this.Receiver = receiver;
|
|---|
| 421 | this.Content = message;
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | public override String
|
|---|
| 425 | ToString()
|
|---|
| 426 | {
|
|---|
| 427 | if (this.Sender.Length != 0)
|
|---|
| 428 | return String.Format("Notice: ({0}) [{1}] {2}", this.SenderNick, this.Receiver, this.Content);
|
|---|
| 429 | else
|
|---|
| 430 | return String.Format("Notice: [{0}] {1}", _receiver, this.Content);
|
|---|
| 431 | }
|
|---|
| 432 | }
|
|---|
| 433 | public class
|
|---|
| 434 | JoinMessage : IRCMessage
|
|---|
| 435 | {
|
|---|
| 436 | private String _channel;
|
|---|
| 437 | public String Channel
|
|---|
| 438 | {
|
|---|
| 439 | get { return _channel; }
|
|---|
| 440 | set { this.CommandParams[0] = _channel = value; }
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | public
|
|---|
| 444 | JoinMessage() : base()
|
|---|
| 445 | {
|
|---|
| 446 | this.SetCommand("JOIN");
|
|---|
| 447 | }
|
|---|
| 448 | public
|
|---|
| 449 | JoinMessage(String raw) : base(raw)
|
|---|
| 450 | {
|
|---|
| 451 | _channel = this.CommandParams[0];
|
|---|
| 452 | }
|
|---|
| 453 | public
|
|---|
| 454 | JoinMessage(String channel, String param)
|
|---|
| 455 | {
|
|---|
| 456 | this.SetCommand("JOIN");
|
|---|
| 457 | Channel = channel;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | public override String
|
|---|
| 461 | ToString()
|
|---|
| 462 | {
|
|---|
| 463 | if (this.SenderNick.Length == 0)
|
|---|
| 464 | return String.Format("Join: {0}", _channel);
|
|---|
| 465 | else
|
|---|
| 466 | return String.Format("Join: {0} - {1}", this.SenderNick, _channel);
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 | public class
|
|---|
| 470 | PartMessage : IRCMessage
|
|---|
| 471 | {
|
|---|
| 472 | private String _channel;
|
|---|
| 473 | private String _message;
|
|---|
| 474 |
|
|---|
| 475 | public String Channel
|
|---|
| 476 | {
|
|---|
| 477 | get { return _channel; }
|
|---|
| 478 | set { _channel = value; }
|
|---|
| 479 | }
|
|---|
| 480 | public String Message
|
|---|
| 481 | {
|
|---|
| 482 | get { return _message; }
|
|---|
| 483 | set { _message = value; }
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | public
|
|---|
| 487 | PartMessage() : base()
|
|---|
| 488 | {
|
|---|
| 489 | this.SetCommand("PART");
|
|---|
| 490 | }
|
|---|
| 491 | public
|
|---|
| 492 | PartMessage(String raw) : base(raw)
|
|---|
| 493 | {
|
|---|
| 494 | _channel = this.CommandParams[0];
|
|---|
| 495 | _message = this.CommandParams[1];
|
|---|
| 496 | }
|
|---|
| 497 | public
|
|---|
| 498 | PartMessage(String channel, String message)
|
|---|
| 499 | {
|
|---|
| 500 | this.SetCommand("PART");
|
|---|
| 501 | _channel = this.CommandParams[0] = channel;
|
|---|
| 502 | _message = this.CommandParams[1] = message;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | public override String
|
|---|
| 506 | ToString()
|
|---|
| 507 | {
|
|---|
| 508 | if (this.SenderNick.Length == 0)
|
|---|
| 509 | return String.Format("Part: {0} ({1})", _channel, _message);
|
|---|
| 510 | else
|
|---|
| 511 | return String.Format("Part: {0} - {1} ({2})", this.SenderNick, _channel, _message);
|
|---|
| 512 | }
|
|---|
| 513 | }
|
|---|
| 514 | public class
|
|---|
| 515 | QuitMessage : IRCMessage
|
|---|
| 516 | {
|
|---|
| 517 | private String _message;
|
|---|
| 518 |
|
|---|
| 519 | public String Message
|
|---|
| 520 | {
|
|---|
| 521 | get { return _message; }
|
|---|
| 522 | set { _message = value; }
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | public
|
|---|
| 526 | QuitMessage() : base()
|
|---|
| 527 | {
|
|---|
| 528 | this.SetCommand("QUIT");
|
|---|
| 529 | }
|
|---|
| 530 | public
|
|---|
| 531 | QuitMessage(String raw) : base(raw)
|
|---|
| 532 | {
|
|---|
| 533 | _message = this.CommandParams[0];
|
|---|
| 534 | }
|
|---|
| 535 | public
|
|---|
| 536 | QuitMessage(String msg, String dummy)
|
|---|
| 537 | {
|
|---|
| 538 | this.SetCommand("QUIT");
|
|---|
| 539 | this.CommandParams[0] = _message = msg;
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | public override String
|
|---|
| 543 | ToString()
|
|---|
| 544 | {
|
|---|
| 545 | return String.Format("Quit: {0} ({1})", this.SenderNick, _message);
|
|---|
| 546 | }
|
|---|
| 547 | }
|
|---|
| 548 | public class
|
|---|
| 549 | TopicMessage : IRCMessage
|
|---|
| 550 | {
|
|---|
| 551 | private String _topic;
|
|---|
| 552 | private String _channel;
|
|---|
| 553 |
|
|---|
| 554 | public
|
|---|
| 555 | TopicMessage() : base()
|
|---|
| 556 | {
|
|---|
| 557 | this.SetCommand("TOPIC");
|
|---|
| 558 | }
|
|---|
| 559 | public
|
|---|
| 560 | TopicMessage(String raw) : base(raw)
|
|---|
| 561 | {
|
|---|
| 562 | _channel = this.CommandParams[0];
|
|---|
| 563 | _topic = this.CommandParams[1];
|
|---|
| 564 | }
|
|---|
| 565 | public
|
|---|
| 566 | TopicMessage(String channel, String param)
|
|---|
| 567 | {
|
|---|
| 568 | this.SetCommand("TOPIC");
|
|---|
| 569 | this.CommandParams[0] = _channel = channel;
|
|---|
| 570 | this.CommandParams[1] = _topic = param;
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | public override String
|
|---|
| 574 | ToString()
|
|---|
| 575 | {
|
|---|
| 576 | return String.Format("Topic: [{0}] {1}", _channel, _topic);
|
|---|
| 577 | }
|
|---|
| 578 | }
|
|---|
| 579 | public class
|
|---|
| 580 | UserMessage : IRCMessage
|
|---|
| 581 | {
|
|---|
| 582 | private String _user = "user";
|
|---|
| 583 | private String _hostName = "*";
|
|---|
| 584 | private String _serverName = "*";
|
|---|
| 585 | private String _realName = "";
|
|---|
| 586 |
|
|---|
| 587 | public
|
|---|
| 588 | UserMessage() : base()
|
|---|
| 589 | {
|
|---|
| 590 | this.SetCommand("USER");
|
|---|
| 591 | }
|
|---|
| 592 | public
|
|---|
| 593 | UserMessage(String raw) : base(raw)
|
|---|
| 594 | {
|
|---|
| 595 | this.SetCommand("USER");
|
|---|
| 596 | _user = this.CommandParams[0];
|
|---|
| 597 | _hostName = this.CommandParams[1];
|
|---|
| 598 | _serverName = this.CommandParams[2];
|
|---|
| 599 | _realName = this.CommandParams[3];
|
|---|
| 600 | }
|
|---|
| 601 | public
|
|---|
| 602 | UserMessage(String user, String realname)
|
|---|
| 603 | {
|
|---|
| 604 | this.SetCommand("USER");
|
|---|
| 605 | _user = this.CommandParams[0] = user;
|
|---|
| 606 | _hostName = this.CommandParams[1] = "*";
|
|---|
| 607 | _serverName = this.CommandParams[2] = "*";
|
|---|
| 608 | _realName = this.CommandParams[3] = realname;
|
|---|
| 609 | }
|
|---|
| 610 | public override String
|
|---|
| 611 | ToString()
|
|---|
| 612 | {
|
|---|
| 613 | return String.Format("User: {0} [{1} {2}] ({3})", _user, _hostName, _serverName, _realName);
|
|---|
| 614 | }
|
|---|
| 615 | }
|
|---|
| 616 | public class
|
|---|
| 617 | ModeMessage : IRCMessage
|
|---|
| 618 | {
|
|---|
| 619 | private String _modeargs = "";
|
|---|
| 620 | private String _target = "";
|
|---|
| 621 |
|
|---|
| 622 | public
|
|---|
| 623 | ModeMessage() : base()
|
|---|
| 624 | {
|
|---|
| 625 | this.SetCommand("MODE");
|
|---|
| 626 | }
|
|---|
| 627 | public
|
|---|
| 628 | ModeMessage(String raw) : base(raw)
|
|---|
| 629 | {
|
|---|
| 630 | _target = this.CommandParams[0];
|
|---|
| 631 | _modeargs = this.CommandParams[1];
|
|---|
| 632 | }
|
|---|
| 633 | public
|
|---|
| 634 | ModeMessage(String target, String param)
|
|---|
| 635 | {
|
|---|
| 636 | this.SetCommand("MODE");
|
|---|
| 637 | this.CommandParams[0] = _target = target;
|
|---|
| 638 | this.CommandParams[1] = _modeargs = param;
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | public override String
|
|---|
| 642 | ToString()
|
|---|
| 643 | {
|
|---|
| 644 | if (this.Sender.Length == 0)
|
|---|
| 645 | return String.Format("Mode: ({0}) {1}", _target, _modeargs);
|
|---|
| 646 | else
|
|---|
| 647 | return String.Format("Mode: ({0}->{1}) {2}", this.Sender, _target, _modeargs);
|
|---|
| 648 |
|
|---|
| 649 | }
|
|---|
| 650 | }
|
|---|
| 651 | } |
|---|