コード例 #1
0
ファイル: Line.cs プロジェクト: xbayrockx/OpenRA
 public override Channel GetChannel()
 {
     if (IrcUtils.IsChannel(AltTarget))
     {
         return(Client.GetChannel(AltTarget));
     }
     return(Client.GetChannel(Target));
 }
コード例 #2
0
ファイル: Line.cs プロジェクト: xbayrockx/OpenRA
 public NumericLine(Line line, int numeric)
     : base(line)
 {
     if (!IrcUtils.IsChannel(Target))
     {
         var numericParts = line.RawStringParts.Skip(1).TakeWhile(p => !p.StartsWith(":"));
         AltTarget = numericParts.LastOrDefault(IrcUtils.IsChannel);
         if (AltTarget == null)
         {
             AltTarget = numericParts.LastOrDefault();
         }
     }
     Numeric = (NumericCommand)numeric;
 }
コード例 #3
0
ファイル: IrcClientUser.cs プロジェクト: xbayrockx/OpenRA
        public void OnNumeric(NumericLine line)
        {
            switch (line.Numeric)
            {
            case NumericCommand.RPL_WELCOME:
                new User(line.Message.Substring(line.Message.LastIndexOf(' ') + 1)).CopyTo(this);
                break;

            case NumericCommand.RPL_NAMREPLY:
            {
                var channel   = line.GetChannel();
                var nicknames = line.Message.Replace("~", "").Replace("&", "").Replace("@", "").Replace("%", "").Replace("+", "").Split(' ');

                foreach (var nickname in nicknames.Where(n => !channel.Users.ContainsKey(n)))
                {
                    channel.Users.Add(nickname, new User {
                            Nickname = nickname
                        });
                }
            }
            break;

            case NumericCommand.RPL_TOPIC:
                line.GetChannel().Topic.Message = line.Message;
                break;

            case NumericCommand.RPL_TOPICWHOTIME:
            {
                var topic = line.GetChannel().Topic;
                topic.Author = new User(line[4]);
                topic.Time   = IrcUtils.DateTimeFromUnixTime(int.Parse(line[5]));
            }
            break;

            case NumericCommand.ERR_NICKNAMEINUSE:
                if (line.Target == "*")                         // no nickname set yet
                {
                    Client.SetNickname(Client.Nickname + new Random().Next(10000, 99999));
                }
                break;
            }
        }
コード例 #4
0
ファイル: IrcClient.cs プロジェクト: xbayrockx/OpenRA
        static void InstanceInitialize()
        {
            var s = Game.Settings.Irc;

            Instance.OnPublicMessage += l =>
            {
                var action = IrcUtils.FromAction(l.Message);
                if (action != null)
                {
                    AddAction(l.Prefix.Nickname, action);
                }
                else
                {
                    AddMessage(l.Prefix.Nickname, l.Message);
                }
            };
            Instance.OnPrivateMessage += l =>
            {
                var ctcp = IrcUtils.FromCtcp(l.Message);
                if (ctcp == null)
                {
                    return;
                }

                var split   = ctcp.Split(new[] { ' ' }, 2);
                var command = split[0];
                if (command.EqualsIC("VERSION"))
                {
                    var mod = Game.modData.Manifest.Mod;
                    Instance.CtcpRespond(l.Prefix.Nickname, command, "{0}: {1}".F(mod.Title, mod.Version));
                }
            };
            Instance.OnPrivateNotice += l =>
            {
                if (l.Target == "*")                 // Drop pre-register notices
                {
                    return;
                }
                AddNotice(l.Prefix.Nickname, l.Message);
            };
            Instance.OnRegister += l =>
            {
                Instance.Join(MainChannel);
                Game.Settings.Irc.Nickname = Instance.LocalUser.Nickname;
                Game.Settings.Save();
            };
            Instance.OnConnecting  += () => AddHistory("Connecting");
            Instance.OnConnect     += () => AddHistory("Connected");
            Instance.OnPart        += l => AddHistory("{0} left{1}".F(l.Prefix.Nickname, l.Message != null ? ": " + l.Message : ""));
            Instance.OnJoin        += l => AddHistory("{0} joined".F(l.Prefix.Nickname));
            Instance.OnQuit        += l => AddHistory("{0} quit{1}".F(l.Prefix.Nickname, l.Message != null ? ": " + l.Message : ""));
            Instance.OnKick        += l => AddHistory("{0} kicked {1}{2}".F(l.Prefix.Nickname, l.KickeeNickname, l.Message != null ? ": " + l.Message : ""));
            Instance.OnNicknameSet += l =>
            {
                AddHistory("{0} set their nickname to {1}".F(l.Prefix.Nickname, l.NewNickname));
                if (l.NewNickname == Instance.LocalUser.Nickname)
                {
                    Instance.Nickname          = l.NewNickname;
                    Game.Settings.Irc.Nickname = l.NewNickname;
                    Game.Settings.Save();
                }
            };
            Instance.OnTopicSet += l => AddHistory("{0} set the topic to {1}".F(l.Prefix.Nickname, l.Message));
            Instance.OnNumeric  += l =>
            {
                if (l.Numeric == NumericCommand.RPL_TOPIC)
                {
                    var topic = Instance.GetChannel(MainChannel).Topic;
                    AddHistory("Topic is {0}".F(topic.Message));
                }
                else if (l.Numeric == NumericCommand.RPL_TOPICWHOTIME)
                {
                    var topic = Instance.GetChannel(MainChannel).Topic;
                    AddHistory("Topic set by {0} at {1}".F(topic.Author.Nickname, topic.Time.ToLocalTime()));
                }
                else if (l.Numeric == NumericCommand.RPL_NOTOPIC)
                {
                    AddHistory("No topic is set");
                }
                else if (l.Numeric == NumericCommand.ERR_NICKNAMEINUSE)
                {
                    AddHistory("Nickname {0} is already in use".F(l.AltTarget));
                }
                else if (l.Numeric == NumericCommand.ERR_ERRONEUSNICKNAME)
                {
                    AddHistory("Nickname {0} is erroneus".F(l.AltTarget));
                }
            };
            Instance.OnDisconnect += () =>
            {
                if (Instance.ConnectionFailure != null)
                {
                    AddHistory("Disconnected: {0}".F(Instance.ConnectionFailure.Message));
                    if (s.ReconnectDelay >= 0)
                    {
                        AddHistory("Reconnecting in {0} seconds".F(s.ReconnectDelay / 1000));
                        Instance.ConnectionState = IrcConnectionState.Reconnecting;
                        Game.RunAfterDelay(s.ReconnectDelay, () =>
                        {
                            if (Instance.IsReconnecting)
                            {
                                Instance.Connect(Instance.Hostname, Instance.Port, Instance.ConnectionTimeout, Instance.Nickname, Instance.Username, Instance.Realname);
                            }
                        });
                    }
                }
                else
                {
                    AddHistory("Disconnected");
                }
            };
            Instance.OnLineRead += l =>
            {
                if (s.Debug)
                {
                    AddHistory(l.RawString);
                }
            };
            Game.OnQuit += Instance.Disconnect;
        }
コード例 #5
0
ファイル: IrcClient.cs プロジェクト: xbayrockx/OpenRA
 public void Act(string target, string message)
 {
     Message(target, IrcUtils.ToAction(message));
 }
コード例 #6
0
ファイル: IrcClient.cs プロジェクト: xbayrockx/OpenRA
 public void CtcpRespond(string target, string command, string response)
 {
     Notice(target, IrcUtils.ToCtcp("{0} {1}".F(command, response)));
 }
コード例 #7
0
ファイル: IrcClient.cs プロジェクト: xbayrockx/OpenRA
 public void CtcpRequest(string target, string command, string request)
 {
     Message(target, IrcUtils.ToCtcp("{0} {1}".F(command, request)));
 }
コード例 #8
0
ファイル: IrcClient.cs プロジェクト: xbayrockx/OpenRA
        void ProcessLine(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return;
            }

            var l = new Line(this, line);

            OnLineRead(l);

            int numeric;

            if (int.TryParse(l.Command, out numeric))
            {
                var nl = new NumericLine(l, numeric);
                LocalUser.OnNumeric(nl);
                OnNumeric(nl);
                switch (nl.Numeric)
                {
                case NumericCommand.RPL_WELCOME:
                    OnRegister(nl);
                    break;

                case NumericCommand.RPL_ENDOFNAMES:
                    OnSync(nl);
                    break;
                }
            }
            else
            {
                switch (l.Command)
                {
                case "PING":
                    Pong(l.Message);
                    OnPing(l);
                    break;

                case "PRIVMSG":
                    if (IrcUtils.IsChannel(l.Target))
                    {
                        OnPublicMessage(l);
                    }
                    else
                    {
                        OnPrivateMessage(l);
                    }
                    break;

                case "NOTICE":
                    if (IrcUtils.IsChannel(l.Target))
                    {
                        OnPublicNotice(l);
                    }
                    else
                    {
                        OnPrivateNotice(l);
                    }
                    break;

                case "JOIN":
                    var jl = new JoinLine(l);
                    LocalUser.OnJoin(jl);
                    OnJoin(jl);
                    break;

                case "PART":
                    LocalUser.OnPart(l);
                    OnPart(l);
                    break;

                case "NICK":
                    var nsl = new NicknameSetLine(l);
                    LocalUser.OnNicknameSet(nsl);
                    OnNicknameSet(nsl);
                    break;

                case "QUIT":
                    OnQuit(l);
                    LocalUser.OnQuit(l);
                    break;

                case "KICK":
                    var kl = new KickLine(l);
                    LocalUser.OnKick(kl);
                    OnKick(kl);
                    break;

                case "TOPIC":
                    LocalUser.OnTopicSet(l);
                    OnTopicSet(l);
                    break;
                }
            }
        }