예제 #1
0
        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;
        }
예제 #2
0
파일: Line.cs 프로젝트: xbayrockx/OpenRA
 public virtual Channel GetChannel()
 {
     return(Client.GetChannel(Target));
 }