/// <summary> /// Retrieve the modes for the specified channel. /// </summary> /// <param name="channel">The channel for which to retrieve modes.</param> public void Mode(IrcTarget channel) { if (channel.IsChannel) { this.Send("MODE", channel); } }
public FileControl(IrcSession session, IrcTarget target, DccMethod method) : base(ChatPageType.DccFile, session, target, "DCC") { this.DccMethod = method; InitializeComponent(); this.Id = "dcc-file"; this.Header = this.Title = string.Format("{0} [DCC]", target.Name); }
internal AliasEventArgs(string name, string[] arguments, IrcPeer from, IrcTarget to, IrcTarget replyTo) { this.Name = name; this.Arguments = new List<string>(arguments).AsReadOnly(); this.From = from; this.To = to; this.ReplyTo = replyTo; }
public ChatPage(ChatPageType type, IrcSession session, IrcTarget target, string id) : this() { this.Type = type; this.Session = session; this.Target = target; this.Id = id; this.IsCloseable = true; }
public void DccChat(IrcSession session, IrcTarget target) { var page = new ChatControl(ChatPageType.DccChat, session, target); App.Create(session, page, true); page.StartListen((port) => { session.SendCtcp(target, new CtcpCommand("DCC", "CHAT", "chat", ConvertIPAddressToString(session.ExternalAddress), port.ToString()), false); }); }
public VoiceControl(IrcSession session, IrcTarget target, NicknameList nickList) { _session = session; _target = target; _nickList = nickList; _peers = new Dictionary<IPEndPoint, VoicePeer>(); InitializeComponent(); this.DataContext = this; if (nickList.Contains(_session.Nickname)) { _self = nickList[_session.Nickname]; } }
public static bool IsUncluttered(IrcTarget target) { if (target == null || !target.IsChannel) { return false; } if(App.Settings.Current.Formatting.HideAllClutter) { return true; } return ExistsInUnclutteredList(target); }
public void DccSend(IrcSession session, IrcTarget target, FileInfo file) { var page = new FileControl(session, target, DccMethod.Send); App.Create(session, page, true); page.StartSend(file, (port) => { if (port > 0) { session.SendCtcp(target, new CtcpCommand("DCC", "SEND", file.Name, ConvertIPAddressToString(session.ExternalAddress), port.ToString(), file.Length.ToString(), "T"), false); } }); }
private void OnMode(IrcMessage message) { if (message.Parameters.Count > 0) { if (IrcTarget.IsChannelName(message.Parameters[0])) { this.RaiseEvent(this.ChannelModeChanged, new IrcChannelModeEventArgs(message)); } else { var e = new IrcUserModeEventArgs(message); this.UserModes = (from m in e.Modes.Where((newMode) => newMode.Set).Select((newMode) => newMode.Mode).Union(this.UserModes).Distinct() where !e.Modes.Any((newMode) => !newMode.Set && newMode.Mode == m) select m).ToArray(); this.RaiseEvent(this.UserModeChanged, new IrcUserModeEventArgs(message)); } } }
public ChatControl(ChatPageType type, IrcSession session, IrcTarget target) : base(type, session, target, type == ChatPageType.Server ? "server" : (type == ChatPageType.DccChat ? "dcc-chat" : string.Format("{0}.{1}", session.NetworkName, target.Name).ToLowerInvariant())) { _history = new LinkedList<string>(); _nickList = new NicknameList(); InitializeComponent(); var state = App.Settings.Current.Windows.States[this.Id]; if (this.Type == ChatPageType.DccChat) { this.Header = string.Format("[CHAT] {0}", this.Target.Name); } else if (this.Type == ChatPageType.Chat || this.Type == ChatPageType.Server) { this.Header = this.Target == null ? "Server" : this.Target.ToString(); this.SubscribeEvents(); if (!this.IsServer) { _logFile = App.OpenLogFile(this.Id); var logLines = new List<ChatLine>(); while (_logFile.Buffer.Count > 0) { var cl = _logFile.Buffer.Dequeue(); cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None; logLines.Add(cl); } boxOutput.AppendBulkLines(logLines); } if (this.IsChannel) { colNickList.MinWidth = MinNickListWidth; colNickList.Width = new GridLength(state.NickListWidth); this.Write("Join", string.Format("Now talking on {0}", this.Target.Name)); this.Session.AddHandler(new IrcCodeHandler((e) => { if (e.Message.Parameters.Count > 2 && this.Target.Equals(new IrcTarget(e.Message.Parameters[1]))) { _channelModes = e.Message.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray(); this.SetTitle(); } e.Handled = true; return true; }, IrcCode.RPL_CHANNELMODEIS)); this.Session.Mode(this.Target); splitter.IsEnabled = true; var nameHandler = new IrcCodeHandler((e) => { if (e.Message.Parameters.Count >= 3) { var to = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]); if (this.Target.Equals(to)) { _nickList.AddRange(e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' '). Where((n) => n.Length > 0)); } } e.Handled = true; return false; }, IrcCode.RPL_NAMEREPLY); this.Session.AddHandler(nameHandler); this.Session.AddHandler(new IrcCodeHandler((e) => { this.Session.RemoveHandler(nameHandler); e.Handled = true; return true; }, IrcCode.RPL_ENDOFNAMES)); } else if (this.IsNickname) { _prefix = this.Target.Name; } } else { throw new ArgumentException("Page type is not supported."); } boxOutput.ColumnWidth = state.ColumnWidth; this.Loaded += new RoutedEventHandler(ChatControl_Loaded); this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded); this.PrepareContextMenus(); boxOutput.ContextMenu = this.GetDefaultContextMenu(); }
public ChatContext(IrcSession ircSession, IrcTarget target) { this.Session = ircSession; this.Target = target; }
private void TriviaNextQuestion(IrcTarget to, bool increment) { var chan = to.Name; if (increment) { _games[chan].QuestionNum++; } else { this.Irc.PrivateMessage(to, string.Format(QuestionSkipped, this.SkipThreshold)); } if (_games[chan].Timer != null) { _games[chan].Timer.Cancel(); _games[chan].Timer = null; } _games[chan].State = GameState.Asking; _games[chan].CurrentHint = 0; _games[chan].Skips.Clear(); if (_games[chan].QuestionNum < this.QuestionsPerGame) { this.Irc.PrivateMessage(to, string.Format(QuestionNext, this.BeforeQuestionDelay)); _games[chan].Timer = new Timer(this.Dispatcher, TriviaLoop, this.BeforeQuestionDelay*1000, to); } else { TriviaGameOver(to); } }
private void session_RawMessageReceived(object sender, IrcEventArgs e) { if (e.Message.Command == "PRIVMSG" && e.Message.Parameters.Count == 2 && (!CtcpCommand.IsCtcpCommand(e.Message.Parameters[1]) || CtcpCommand.Parse(e.Message.Parameters[1]).Command == "ACTION")) { var target = new IrcTarget(e.Message.Parameters[0]); if (target.Type == IrcTargetType.Nickname && e.Message.From is IrcPeer) { this.Invoke(() => { App.Create(sender as IrcSession, new IrcTarget((IrcPeer)e.Message.From), false); }); } } }
/// <summary> /// Determine whether the specified target refers to this session by comparing the nickname to the session's current nickname. /// </summary> /// <param name="target">The target to evaluate.</param> /// <returns>True if the target refers to this session, false otherwise.</returns> public bool IsSelf(IrcTarget target) { return(target != null && !target.IsChannel && string.Compare(target.Name, this.Nickname, StringComparison.OrdinalIgnoreCase) == 0); }
private void Execute(string command, string arguments) { string[] args; switch (command) { case "QUOTE": args = Split(command, arguments, 1, 1); this.Session.Quote(args[0]); break; case "QUIT": args = Split(command, arguments, 0, 1); this.Session.AutoReconnect = false; this.Session.Quit(args.Length == 0 ? "Leaving" : args[0]); break; case "NICK": args = Split(command, arguments, 1, 1); this.Session.Nick(args[0]); break; case "NOTICE": args = Split(command, arguments, 2, 2); this.Session.Notice(new IrcTarget(args[0]), args[1]); break; case "JOIN": case "J": args = Split(command, arguments, 1, 2); if (args.Length == 2) { this.Session.Join(args[0], args[1]); } else { this.Session.Join(args[0]); } break; case "PART": case "LEAVE": args = Split(command, arguments, 1, 1, true); this.Session.Part(args[0]); break; case "TOPIC": args = Split(command, arguments, 1, 2, true); if (args.Length > 1) { this.Session.Topic(args[0], args[1]); } else { this.Session.Topic(args[0]); } break; case "INVITE": args = Split(command, arguments, 2, 2); this.Session.Invite(args[1], args[0]); break; case "KICK": args = Split(command, arguments, 2, 3, true); if (args.Length > 2) { this.Session.Kick(args[0], args[1], args[2]); } else { this.Session.Kick(args[0], args[1]); } break; case "MOTD": args = Split(command, arguments, 0, 1); if (args.Length > 0) { this.Session.Motd(args[0]); } else { this.Session.Motd(); } break; case "WHO": args = Split(command, arguments, 1, 1); this.Session.Who(args[0]); break; case "WHOIS": args = Split(command, arguments, 1, 2); if (args != null) { if (args.Length == 2) { this.Session.WhoIs(args[0], args[1]); } else if (args.Length == 1) { this.Session.WhoIs(args[0]); } } break; case "WHOWAS": args = Split(command, arguments, 1, 1); this.Session.WhoWas(args[0]); break; case "AWAY": args = Split(command, arguments, 0, 1); if (args.Length > 0) { this.Session.Away(args[0]); } else { this.Session.UnAway(); } break; case "USERHOST": args = Split(command, arguments, 1, int.MaxValue); this.Session.UserHost(args); break; case "MODE": args = Split(command, arguments, 1, 2); var target = new IrcTarget(args[0]); if (!target.IsChannel) { if (!this.Session.IsSelf(target)) { throw new CommandException("Can't change modes for another user."); } if (args.Length > 1) { this.Session.Mode(args[1]); } else { this.Session.Mode(""); } } else { if (args.Length > 1) { this.Session.Mode(target.Name, args[1]); } else { this.Session.Mode(target.Name, ""); } } break; case "SERVER": { args = Split(command, arguments, 1, 3); int port = 0; bool useSsl = false; if (args.Length > 1 && (args[1] = args[1].Trim()).Length > 0) { if (args[1][0] == '+') { useSsl = true; } int.TryParse(args[1], out port); } string password = null; if (args.Length > 2) { password = args[2]; } if (port == 0) { port = 6667; } if (this.IsConnected) { this.Session.AutoReconnect = false; this.Session.Quit("Changing servers"); } this.Perform = ""; this.Connect(args[0], port, useSsl, false, password); } break; case "ME": case "ACTION": if (this.IsServer) { this.Write("Error", "Can't talk in this window."); } if (this.IsConnected) { args = Split(command, arguments, 1, int.MaxValue); this.Write("Own", string.Format("{0} {1}", this.Session.Nickname, string.Join(" ", args))); if (this.Type == ChatPageType.Chat) { this.Session.SendCtcp(this.Target, new CtcpCommand("ACTION", args), false); } else if (this.Type == ChatPageType.DccChat) { _dcc.QueueMessage(string.Format("\u0001ACTION {0}\u0001", string.Join(" ", args))); } } break; case "SETUP": App.ShowSettings(); break; case "CLEAR": boxOutput.Clear(); break; case "MSG": if (this.IsConnected) { args = Split(command, arguments, 2, 2); this.Session.PrivateMessage(new IrcTarget(args[0]), args[1]); this.Write("Own", string.Format("-> [{0}] {1}", args[0], args[1])); } break; case "LIST": args = Split(command, arguments, 0, 2); if (args.Length > 1) { this.Session.List(args[0], args[1]); } else if (args.Length > 0) { this.Session.List(args[0]); } else { this.Session.List(); } break; case "OP": case "DEOP": case "VOICE": case "DEVOICE": if (!this.IsChannel) { this.Write("Error", "Cannot perform that action in this window."); } else { char mode = (command == "OP" || command == "DEOP") ? 'o' : 'v'; args = Split(command, arguments, 1, int.MaxValue); var modes = from s in args select new IrcChannelMode(command == "OP" || command == "VOICE", mode, s); this.Session.Mode(this.Target.Name, modes); } break; case "HELP": foreach (var s in App.HelpText.Split(Environment.NewLine.ToCharArray())) { if (s.Length > 0) { this.Write("Client", s); } } break; case "CTCP": args = Split(command, arguments, 2, int.MaxValue); this.Session.SendCtcp(new IrcTarget(args[0]), new CtcpCommand(args[1], args.Skip(2).ToArray()), false); break; case "QUERY": args = Split(command, arguments, 1, 1); ChatWindow.ChatCommand.Execute(args[0], this); break; case "BAN": args = Split(command, arguments, 1, 1); ChatControl.BanCommand.Execute(args[0], this); break; case "UNBAN": args = Split(command, arguments, 1, 1); ChatControl.UnbanCommand.Execute(args[0], this); break; case "IGNORE": { args = Split(command, arguments, 0, 2); if (args.Length == 0) { var ignores = App.GetIgnoreInfo(); if (ignores.Any()) { this.Write("Own", "Ignore list:"); foreach (string i in ignores) { this.Write("Own", " " + i); } } else { this.Write("Own", "Ignore list is empty."); } break; } string mask = args[0]; string sactions = args.Length > 1 ? args[1] : "All"; IgnoreActions actions; if (!Enum.TryParse(sactions, true, out actions)) { this.Write("Error", "Invalid ignore action(s)."); break; } if (!mask.Contains('!') && !mask.Contains('@')) { mask = mask + "!*@*"; } App.AddIgnore(mask, actions); this.Write("Own", "Added to ignore list: " + mask); } break; case "UNIGNORE": { args = Split(command, arguments, 1, 2); string mask = args[0]; string sactions = args.Length > 1 ? args[1] : "All"; IgnoreActions actions; if (!Enum.TryParse(sactions, true, out actions)) { this.Write("Error", "Invalid ignore action(s)."); break; } if (!mask.Contains('!') && !mask.Contains('@')) { mask = mask + "!*@*"; } if (App.RemoveIgnore(mask, actions)) { this.Write("Own", "Removed from ignore list: " + mask); } else { this.Write("Error", "Specified pattern was not on ignore list."); } } break; case "DCC": { if (!this.IsConnected) { return; } args = Split(command, arguments, 2, 3); string dccCmd = args[0].ToUpperInvariant(); switch (dccCmd) { case "CHAT": App.ChatWindow.DccChat(this.Session, new IrcTarget(args[1])); break; case "SEND": case "XMIT": string path = null; if (args.Length < 3) { this.Write("Error", "File name is required."); break; } try { if (System.IO.Path.IsPathRooted(args[2]) && System.IO.File.Exists(args[2])) { path = args[2]; } else if (!System.IO.File.Exists(path = System.IO.Path.Combine(App.Settings.Current.Dcc.DownloadFolder, args[2]))) { this.Write("Error", "Could not find file " + args[2]); break; } } catch (ArgumentException) { this.Write("Error", string.Format("Invalid pathname: {0}", args[2])); break; } if (dccCmd == "XMIT") { App.ChatWindow.DccXmit(this.Session, new IrcTarget(args[1]), new System.IO.FileInfo(path)); } else { App.ChatWindow.DccSend(this.Session, new IrcTarget(args[1]), new System.IO.FileInfo(path)); } break; default: this.Write("Error", "Unsupported DCC mode " + args[0]); break; } } break; default: this.Write("Error", string.Format("Unrecognized command: {0}", command)); break; } }
public static bool Create(IrcSession session, IrcTarget target, bool makeActive) { var detached = App.Current.Windows.OfType<ChannelWindow>().Where((cw) => cw.Page.Session == session && target.Equals(cw.Page.Target) && cw.Page.Type == ChatPageType.Chat).FirstOrDefault(); if (detached != null) { if (makeActive) { detached.Activate(); } return false; } var window = App.ChatWindow; var page = window.FindPage(ChatPageType.Chat, session, target); if (page != null) { if (makeActive) { window.Show(); if (window.WindowState == WindowState.Minimized) { window.WindowState = WindowState.Normal; } window.Activate(); window.SwitchToPage(page); } return false; } else { page = new ChatControl(target == null ? ChatPageType.Server : ChatPageType.Chat, session, target); Create(session, page, makeActive); return true; } }
public static bool ExistsInUnclutteredList(IrcTarget target) { return _uncluttered.Contains(target.Name.ToUpperInvariant()); }
private void session_RawMessageReceived(object sender, IrcEventArgs e) { if (e.Message.Command == "PRIVMSG" && e.Message.Parameters.Count == 2 && (!CtcpCommand.IsCtcpCommand(e.Message.Parameters[1]) || CtcpCommand.Parse(e.Message.Parameters[1]).Command == "ACTION")) { var target = new IrcTarget(e.Message.Parameters[0]); if (App.IsIgnoreMatch(e.Message.From, target.IsChannel ? IgnoreActions.Channel : IgnoreActions.Private)) { return; } if (!target.IsChannel && e.Message.From is IrcPeer) { if (App.Create(sender as IrcSession, new IrcTarget((IrcPeer)e.Message.From), false) && _notifyIcon != null && _notifyIcon.IsVisible) { _notifyIcon.Show("IRC Message", string.Format("You received a message from {0}.", ((IrcPeer)e.Message.From).Nickname)); } } } }
private void Session_RawMessageReceived(object sender, IrcEventArgs e) { int code; if(int.TryParse(e.Message.Command, out code)) { var ircCode = (IrcCode)code; switch(ircCode) { case IrcCode.NameReply: if (!_hasNames && e.Message.Parameters.Count >= 3 && this.IsChannel) { var target = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]); if (this.Target.Equals(target)) { this.Invoke(() => { foreach (var nick in e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' ')) { this.AddNick(nick); } }); e.Handled = true; } } break; case IrcCode.EndOfNames: if (!_hasNames && this.IsChannel) { _hasNames = true; e.Handled = true; } break; } } }
private bool HandleDcc(IrcSession session, IrcTarget target, string[] args) { if (args.Length < 1) { return false; } string type = args[0].ToUpperInvariant(); IPAddress addr; int port; switch (type) { case "CHAT": { if (args.Length < 4 || args[1].ToUpperInvariant() != "CHAT" || !IPAddress.TryParse(args[2], out addr) || !int.TryParse(args[3], out port)) { session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", "CHAT", "unavailable"), true); return true; } var page = new ChatControl(ChatPageType.DccChat, session, target); page.StartAccept(addr, port); page.NotifyState = NotifyState.Alert; App.Create(session, page, false); App.Alert(Window.GetWindow(page), string.Format("{0} wants to chat with you.", target.Name)); } break; case "XMIT": { if (args.Length < 5 || string.Compare(args[1], "CLEAR", StringComparison.OrdinalIgnoreCase) != 0 || !IPAddress.TryParse(args[2], out addr) || !int.TryParse(args[3], out port)) { session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", "XMIT", "unavailable"), true); return true; } string name = args[4]; long size = 0; if (args.Length > 5) { long.TryParse(args[5], out size); } var page = new FileControl(session, target, DccMethod.Xmit); page.StartReceive(addr, port, name, size); page.NotifyState = NotifyState.Alert; App.Create(session, page, false); App.Alert(Window.GetWindow(page), string.Format("{0} wants to send you a file.", target.Name)); } break; case "SEND": { if (args.Length < 4 || !IPAddress.TryParse(args[2], out addr) || !int.TryParse(args[3], out port)) { session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", "SEND", "unavailable"), true); return true; } string name = args[1]; long size = 0; if (args.Length > 4) { long.TryParse(args[4], out size); } var page = new FileControl(session, target, DccMethod.Send); page.StartReceive(addr, port, name, size); page.NotifyState = NotifyState.Alert; App.Create(session, page, false); App.Alert(Window.GetWindow(page), string.Format("{0} wants to send you a file.", target.Name)); } break; default: session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", args[0], "unavailable"), true); break; } return true; }
internal IrcJoinEventArgs(IrcMessage message) : base(message) { this.Who = message.From as IrcPeer; this.Channel = message.Parameters.Count > 0 ? new IrcTarget(message.Parameters[0]) : null; }
/// <summary> /// Send a CTCP message to another client. /// </summary> /// <param name="target">The user to which the CTCP command will be delivered.</param> /// <param name="command">The CTCP command to send.</param> /// <param name="isResponse">Indicates whether the CTCP message is a response to a command that was received. This parameter /// is important for preventing an infinite back-and-forth loop between two clients.</param> public void SendCtcp(IrcTarget target, CtcpCommand command, bool isResponse) { this.Send(isResponse ? "NOTICE" : "PRIVMSG", target, command.ToString()); }
/// <summary> /// Send a notice to a user or channel. /// </summary> /// <param name="target">The user or channel that the notice will be delivered to.</param> /// <param name="text">The notice text.</param> public void Notice(IrcTarget target, string text) { this.Send("NOTICE", target, text); }
/// <summary> /// Send a message to the server. /// </summary> /// <param name="command">The name of the command.</param> /// <param name="target">The target of the command.</param> /// <param name="parameters">The optional command parameters.</param> public void Send(string command, IrcTarget target, params string[] parameters) { this.Send(command, (new[] { target.ToString() }).Union(parameters).ToArray()); }
private void TriviaStart(IrcTarget to) { var chan = to.Name; _requests[chan].Clear(); _games.Add(chan, new Game()); _games[chan].Provider = CreateProvider(); this.Irc.PrivateMessage(to, string.Format(TriviaStartMessage, this.BeforeQuestionDelay)); this.Irc.PrivateMessaged += new EventHandler<IrcMessageEventArgs>(TriviaGuess); _games[chan].Timer = new Timer(this.Dispatcher, TriviaLoop, this.BeforeQuestionDelay*1000, to); }
/// <summary> /// Send a private message to a user or channel. /// </summary> /// <param name="target">The user or channel that the message will be delivered to.</param> /// <param name="text">The message text.</param> public void PrivateMessage(IrcTarget target, string text) { this.Send("PRIVMSG", target, text); }
private void Execute(IrcTarget replyTo, string line) { object output = null; line = line.Trim(); if (!line.EndsWith(";")) line = line + ";"; try { output = Evaluator.Evaluate(line); } catch (Exception ex) { this.Irc.PrivateMessage(replyTo, string.Format("ERROR: {0}", ex.Message)); } if (errOut.Length > 0) { this.Irc.PrivateMessage(replyTo, string.Format("ERROR: {0}", errOut.ToString())); errOut.Clear(); } if (output != null) { this.Irc.PrivateMessage(replyTo, output.ToString()); } }
private void Execute(string command, string arguments) { string[] args; switch (command) { case "QUOTE": args = Split(command, arguments, 1, 1); this.Session.Quote(args[0]); break; case "QUIT": args = Split(command, arguments, 0, 1); this.Session.AutoReconnect = false; this.Session.Quit(args.Length == 0 ? "Leaving" : args[0]); break; case "NICK": args = Split(command, arguments, 1, 1); this.Session.Nick(args[0]); break; case "NOTICE": args = Split(command, arguments, 2, 2); this.Session.Notice(new IrcTarget(args[0]), args[1]); break; case "JOIN": case "J": args = Split(command, arguments, 1, 1); this.Session.Join(args[0]); break; case "PART": case "LEAVE": args = Split(command, arguments, 1, 1, true); this.Session.Part(args[0]); break; case "TOPIC": args = Split(command, arguments, 1, 2, true); if (args.Length > 1) { this.Session.Topic(args[0], args[1]); } else { this.Session.Topic(args[0]); } break; case "INVITE": args = Split(command, arguments, 2, 2); this.Session.Invite(args[1], args[0]); break; case "KICK": args = Split(command, arguments, 2, 3, true); if (args.Length > 2) { this.Session.Kick(args[0], args[1], args[2]); } else { this.Session.Kick(args[0], args[1]); } break; case "MOTD": args = Split(command, arguments, 0, 1); if (args.Length > 0) { this.Session.Motd(args[0]); } else { this.Session.Motd(); } break; case "WHO": args = Split(command, arguments, 1, 1); this.Session.Who(args[0]); break; case "WHOIS": args = Split(command, arguments, 1, 2); if (args != null) { if (args.Length == 2) { this.Session.WhoIs(args[0], args[1]); } else if (args.Length == 1) { this.Session.WhoIs(args[0]); } } break; case "WHOWAS": args = Split(command, arguments, 1, 1); this.Session.WhoWas(args[0]); break; case "AWAY": args = Split(command, arguments, 0, 1); if (args.Length > 0) { this.Session.Away(args[0]); } else { this.Session.UnAway(); } break; case "USERHOST": args = Split(command, arguments, 1, int.MaxValue); this.Session.UserHost(args); break; case "MODE": args = Split(command, arguments, 1, 2); var target = new IrcTarget(args[0]); if (target.Type == IrcTargetType.Nickname) { if (args.Length > 1) { this.Session.Mode(args[1]); } else { this.Session.Mode(""); } } else { if (args.Length > 1) { this.Session.Mode(target.Name, args[1]); } else { this.Session.Mode(target.Name, ""); } } break; case "SERVER": args = Split(command, arguments, 1, 2); int port = 0; if (args.Length > 1) { int.TryParse(args[1], out port); } if (port == 0) { port = 6667; } if (this.IsConnected) { this.Session.AutoReconnect = false; this.Session.Quit("Changing servers"); } this.Perform = ""; this.Connect(args[0], port, false); break; case "ME": case "ACTION": if (this.IsServer) { this.Write("Error", "Can't talk in this window."); } args = Split(command, arguments, 1, int.MaxValue); this.Session.SendCtcp(this.Target, new CtcpCommand("ACTION", args), false); this.Write("Own", string.Format("{0} {1}", this.Session.Nickname, string.Join(" ", args))); break; case "SETUP": App.ShowSettings(); break; case "CLEAR": boxOutput.Clear(); break; case "MSG": args = Split(command, arguments, 2, 2); this.Session.PrivateMessage(new IrcTarget(args[0]), args[1]); this.Write("Own", string.Format("-> [{0}] {1}", args[0], args[1])); break; case "LIST": args = Split(command, arguments, 1, 2); if (args.Length > 1) { this.Session.List(args[0], args[1]); } else { this.Session.List(args[0]); } break; case "OP": case "DEOP": case "VOICE": case "DEVOICE": if (!this.IsChannel) { this.Write("Error", "Cannot perform that action in this window."); } else { char mode = (command == "OP" || command == "DEOP") ? 'o' : 'v'; args = Split(command, arguments, 1, int.MaxValue); var modes = from s in args select new IrcChannelMode(command == "OP" || command == "VOICE", mode, s); this.Session.Mode(this.Target.Name, modes); } break; case "HELP": foreach (var s in App.HelpText.Split(Environment.NewLine.ToCharArray())) { if (s.Length > 0) { this.Write("Client", s); } } break; case "CTCP": args = Split(command, arguments, 2, int.MaxValue); this.Session.SendCtcp(new IrcTarget(args[0]), new CtcpCommand(args[1], args.Skip(2).ToArray()), false); break; case "QUERY": args = Split(command, arguments, 1, 1); ChatWindow.ChatCommand.Execute(args[0], this); break; case "BAN": args = Split(command, arguments, 1, 1); ChatControl.BanCommand.Execute(args[0], this); break; case "UNBAN": args = Split(command, arguments, 1, 1); ChatControl.UnbanCommand.Execute(args[0], this); break; default: this.Write("Error", string.Format("Unrecognized command: {0}", command)); break; } }
private void TriviaGameOver(IrcTarget to) { var chan = to.Name; if (_games[chan].Timer != null) { _games[chan].Timer.Cancel(); _games[chan].Timer = null; } int topScore = 0; var scores = _games[chan].Scores; var winners = new List<string>(); if (scores.Count < 1) { this.Irc.PrivateMessage(to, NoWinner); } else { foreach (var k in scores.Keys) { if (scores[k] > topScore) { winners.Clear(); winners.Add(k); topScore = scores[k]; } else if (scores[k] == topScore) { winners.Add(k); } } } var sb = new StringBuilder(); if (winners.Count > 1) { sb.Append("Game over. It's a tie between "); for (int i = 0; i < winners.Count; i++) { sb.Append(winners[i]); if (i < winners.Count - 2) { sb.Append(", "); } else if (i < winners.Count - 1) { sb.Append(" and "); } } sb.Append(" with ").Append(topScore).Append(" point"); if (topScore > 1) { sb.Append("s"); } sb.Append(" each."); this.Irc.PrivateMessage(to, sb.ToString()); this.Irc.PrivateMessage(to, GameTie); } else if (winners.Count == 1) { sb.Append("Game over. The game's winner is ").Append(winners[0]).Append(" with ").Append(topScore).Append(" point"); if (topScore > 1) { sb.Append("s"); } sb.Append(". "); sb.Append(GameWinner); this.Irc.PrivateMessage(to, sb.ToString()); } var runnersUp = new Dictionary<int, List<string>>(); if (topScore > 0) { foreach (var k in scores.Keys) { if (scores[k] < topScore) { if (runnersUp.ContainsKey(scores[k])) { runnersUp[scores[k]].Add(k); } else { runnersUp.Add(scores[k], new List<string>()); runnersUp[scores[k]].Add(k); } } } } sb.Length = 0; int place = 0; for (int i = topScore - 1; i >= 1 && place <= 2; i--) { if (!runnersUp.ContainsKey(i)) continue; switch (place) { case 0: sb.Append("First Loser"); break; case 1: sb.Append("Second Loser"); break; case 2: sb.Append("Third Loser"); break; default: break; } if (runnersUp[i].Count > 1) sb.Append("s"); sb.Append(" at ").Append(i).Append(" point"); if (i > 1) sb.Append("s"); sb.Append(": "); foreach (var s in runnersUp[i]) { sb.Append(s).Append(", "); } sb.Length = sb.Length - 2; this.Irc.PrivateMessage(to, sb.ToString()); sb.Length = 0; place++; } this.Irc.PrivateMessage(to, GameOver); if (_games[chan].Provider is IDisposable) { ((IDisposable)_games[chan].Provider).Dispose(); } _games.Remove(chan); }
public ChatPage FindPage(ChatPageType type, IrcSession session, IrcTarget target) { return this.Items.Where((i) => i.Page.Type == type && i.Page.Session == session && i.Page.Target != null && i.Page.Target.Equals(target)).Select((i) => i.Page).FirstOrDefault(); }