private void CmdUptime(ChannelMessageEvent ev, string[] line)
 {
     if (_game == null) return;
     TimeSpan uptime = DateTime.Now - GameStartTime;
     _irc.SendMessage(Channel, GameDisplayName + " has been running for: " +
         Math.Floor(uptime.TotalMinutes) + ":" + uptime.Seconds.ToString("00") + ".");
 }
 private void CmdKill(ChannelMessageEvent ev, string[] line)
 {
     if (_canKill && _game != null) {
         KillGame();
         _irc.SendMessage(Channel, "Game killed.");
     }
 }
 private void CmdList(ChannelMessageEvent ev, string[] line)
 {
     if (_game != null) return;
     _irc.SendMessage(Channel, "Games available:");
     foreach (string l in _loader.List()) {
         _irc.SendMessage(Channel, l);
     }
 }
Exemple #4
0
        private IRCQEvent HandleLine(string sender, string command, string[] param, string text)
        {
            if (command == "PING") {
                return new PingEvent(false, text);
            }

            // Assuming the line will contain a sender and target and preparing for it
            bool isChannel = Channel.IsValidChannelName(param[0]);
            UserData sender_u = Entities.GetUserFromPrefix(sender);
            UserData target_u = null;
            ChannelData target_c = null;
            if (param.Length > 0) {
                if (isChannel) target_c = Entities.GetChannel(param[0]);
                else target_u = Entities.GetUser(param[0]);
            }

            IRCQEvent send = null;

            if (text.StartsWith("\u0001") && text.EndsWith("\u0001")) { // CTCP message
                text = text.Substring(1, text.Length - 2); // cut off control characters
                if (command == "PRIVMSG") {
                    if (text.ToUpper().StartsWith("ACTION ")) {
                        text = text.Substring(7);
                        if (isChannel) {
                            send = new ChannelMessageEvent(false, (User)sender_u, (Channel)target_c,
                                                           MessageType.Action, text);
                        } else {
                            send = new UserMessageEvent(false, (User)sender_u, (User)target_u,
                                                        MessageType.Action, text);
                        }
                    } else {
                        if (isChannel) {
                            send = new ChannelCtcpEvent(false, (User)sender_u, (Channel)target_c,
                                                        CtcpType.Request, text);
                        } else {
                            send = new CtcpEvent(false, (User)sender_u, (User)target_u,
                                                 CtcpType.Response, text);
                        }
                    }
                } else if (command == "NOTICE") {
                    send = new CtcpEvent(false, (User)sender_u, (User)target_u, CtcpType.Response, text);
                }
            } else if (command == "PRIVMSG" || command == "NOTICE") {
                MessageType t = command == "PRIVMSG" ? MessageType.Normal : MessageType.Notice;
                if (isChannel) {
                    send = new ChannelMessageEvent(false, (User)sender_u, (Channel)target_c, t, text);
                } else {
                    send = new UserMessageEvent(false, (User)sender_u, (User)Entities.Self, t, text);
                }
            } else if (command == "JOIN") {
                if (sender_u.isclient) { // Client joining a new channel - requesting more info
                    WriteOut("MODE " + param[0]);
                }
                Entities.Join(target_c, sender_u); // Join user and channel before exporting
                send = new JoinEvent(false, (User)sender_u, (Channel)target_c, null);
            } else if (command == "PART") {
                // Export before deleting data
                send = new PartEvent(false, (User)sender_u, (Channel)target_c, text);
                if (sender_u.isclient)
                    Entities.DropChannel(target_c);
                else
                    Entities.Unjoin(target_c, sender_u);
            } else if (command == "NICK") {
                // Export before altering data
                send = new NickChangeEvent(false, (User)sender_u, text);
                sender_u.nick = text;
            } else if (command == "QUIT") {
                // Export before deleting data
                send = new QuitEvent(false, (User)sender_u, text);
                Entities.DropUser(sender_u);
            } else if (command == "KICK") {
                target_u = Entities.GetUser(param[1]);

                // Export before deleting data
                send = new KickEvent(false, (User)sender_u, (Channel)target_c, (User)target_u, text);
                if (target_u.isclient)
                    Entities.DropChannel(target_c);
                else
                    Entities.Unjoin(target_c, target_u);
            } else if (command == "MODE") {
                if (isChannel) {
                    // Must rebuild mode string from params
                    string mode = "";
                    for (int i = 1; i < param.Length; i++) {
                        mode += " " + param[i];
                    }
                    if (mode.Length > 0) target_c.ModeSet(mode.Substring(1));

                    // Mode has already been applied when exported
                    send = new ChannelModeEvent(false, (User)sender_u, (Channel)target_c, param[1]);
                } else {
                    send = new ServerModeEvent(false, (User)target_u, text);
                }
            } else if (command == "TOPIC") {
                // Export before updating data
                send = new TopicEvent(false, (User)sender_u, (Channel)target_c, text);

                if (text == "") {
                    target_c.topic = "";
                    target_c.topic_setter = "";
                    target_c.topic_settime = null;
                } else {
                    target_c.topic = text;
                    target_c.topic_setter = sender_u.nick;
                    target_c.topic_settime = DateTime.Now;
                }
            } else if (command == "INVITE") {
                send = new InviteEvent(false, (User)sender_u, (User)Entities.Self, text);
            } else {
                send = null; // TODO server raw unknown event instead of null
            }

            return send;
        }