protected override void OnStart(string[] args)
        {
            ServicePointManager.DefaultConnectionLimit = 1000;

            _server = new Server();
            _server.Encoding = new UTF8Encoding(false);
            //_server.Encoding = encoding;
            _server.ConnectionAttached += new EventHandler<ConnectionAttachEventArgs>(_server_ConnectionAttached);
            //_server.Proxy = proxy;

            // gzip を有効に
            Config.Default.EnableCompression = true;

            StringWriter sw = new StringWriter();
            sw.WriteLine("TwitterIrcGateway Server v{0} を開始しました。", typeof(Server).Assembly.GetName().Version);
            sw.WriteLine();
            //sw.WriteLine(" BindAddress: {0}, Port: {1}", bindAddress, options.Port);
            sw.WriteLine("EnableTrace: {0}", Config.Default.EnableTrace);
            sw.WriteLine("IgnoreWatchError: {0}", Config.Default.IgnoreWatchError);
            sw.WriteLine("Interval: {0}", Config.Default.Interval);
            sw.WriteLine("ResolveTinyUrl: {0}", Config.Default.ResolveTinyUrl);
            sw.WriteLine("Encoding: {0}", _server.Encoding.EncodingName);
            sw.WriteLine("SetTopicOnStatusChanged: {0}", Config.Default.SetTopicOnStatusChanged);
            sw.WriteLine("EnableDropProtection: {0}", Config.Default.EnableDropProtection);
            sw.WriteLine("IntervalDirectMessage: {0}", Config.Default.IntervalDirectMessage);
            //sw.WriteLine("CookieLoginMode: {0}", Config.Default.CookieLoginMode);
            sw.WriteLine("ChannelName: {0}", Config.Default.ChannelName);
            sw.WriteLine("EnableRepliesCheck: {0}", Config.Default.EnableRepliesCheck);
            sw.WriteLine("IntervalReplies: {0}", Config.Default.IntervalReplies);
            sw.WriteLine("DisableUserList: {0}", Config.Default.DisableUserList);
            sw.WriteLine("BroadcastUpdate: {0}", Config.Default.BroadcastUpdate);
            sw.WriteLine("ClientMessageWait: {0}", Config.Default.ClientMessageWait);
            sw.WriteLine("BroadcastUpdateMessageIsNotice: {0}", Config.Default.BroadcastUpdateMessageIsNotice);
            sw.WriteLine("EnableCompression: {0}", Config.Default.EnableCompression);
            //            sw.WriteLine("Proxy: {0}", options.Proxy);
            //            sw.WriteLine("PostFetchMode: {0}", options.PostFetchMode);

            Settings settings = new Settings();
            _server.Start(IPAddress.Parse(settings.BindAddress), settings.Port);
            if (settings.SslPort > 0)
            {
                _sslServer = new Server(true);
                _sslServer.ConnectionAttached += _server_ConnectionAttached;
                _sslServer.Encoding = _server.Encoding;
                _sslServer.Certificate = new X509Certificate2(settings.CertFilename, "");
                _sslServer.Start(IPAddress.Parse(settings.BindAddress), settings.SslPort);
            }

            EventLog.WriteEntry(sw.ToString(), EventLogEntryType.Information, 0);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IPAddress bindAddress = IPAddress.Loopback;
            Encoding encoding = Encoding.GetEncoding("ISO-2022-JP");
            IWebProxy proxy = WebRequest.DefaultWebProxy;

            CommandLineOptions options;
            if (CommandLineParser.TryParse(args, out options))
            {
                // Encoding
                if (String.Compare(options.Encoding, "UTF-8", true) == 0)
                    encoding = new UTF8Encoding(false);
                else
                    encoding = Encoding.GetEncoding(options.Encoding);

                // Listening IP
                if (!IPAddress.TryParse(options.BindAddress, out bindAddress))
                {
                    ShowUsage();
                    return;
                }

                // Proxy
                try
                {
                    if (!String.IsNullOrEmpty(options.Proxy))
                        proxy = new WebProxy(options.Proxy);
                }
                catch (UriFormatException)
                {
                    ShowUsage();
                    return;
                }
            }
            else
            {
                ShowUsage();
                return;
            }

            Config.Default.EnableTrace = options.EnableTrace;
            Config.Default.IgnoreWatchError = options.IgnoreWatchError;
            Config.Default.Interval = options.Interval;
            Config.Default.ResolveTinyUrl = options.ResolveTinyurl;
            Config.Default.EnableDropProtection = options.EnableDropProtection;
            Config.Default.SetTopicOnStatusChanged = options.SetTopicOnstatuschanged;
            Config.Default.IntervalDirectMessage = options.IntervalDirectmessage;
            //Config.Default.CookieLoginMode = options.CookieLoginMode;
            Config.Default.ChannelName = "#"+options.ChannelName;
            Config.Default.EnableRepliesCheck = options.EnableRepliesCheck;
            Config.Default.IntervalReplies = options.IntervalReplies;
            Config.Default.DisableUserList = options.DisableUserlist;
            Config.Default.BroadcastUpdate = options.BroadcastUpdate;
            Config.Default.ClientMessageWait = options.ClientMessageWait;
            Config.Default.BroadcastUpdateMessageIsNotice = options.BroadcastUpdateMessageIsNotice;
            Config.Default.POSTFetchMode = options.PostFetchMode;
            Config.Default.EnableCompression = options.EnableCompression;
            Config.Default.DisableNoticeAtFirstTime = options.DisableNoticeAtFirstTime;

            Server _server = new Server();
            _server.Encoding = encoding;
            _server.ConnectionAttached += new EventHandler<ConnectionAttachEventArgs>(_server_ConnectionAttached);
            _server.Proxy = proxy;
            if (!String.IsNullOrEmpty(options.OAuthClientKey))
                _server.OAuthClientKey = options.OAuthClientKey;
            if (!String.IsNullOrEmpty(options.OAuthSecretKey))
                _server.OAuthSecretKey = options.OAuthSecretKey;

            Console.WriteLine("Start TwitterIrcGateway Server v{0}", typeof(Server).Assembly.GetName().Version);
            Console.WriteLine("[Configuration] BindAddress: {0}, Port: {1}", bindAddress, options.Port);
            Console.WriteLine("[Configuration] EnableTrace: {0}", Config.Default.EnableTrace);
            Console.WriteLine("[Configuration] IgnoreWatchError: {0}", Config.Default.IgnoreWatchError);
            Console.WriteLine("[Configuration] Interval: {0}", Config.Default.Interval);
            Console.WriteLine("[Configuration] ResolveTinyUrl: {0}", Config.Default.ResolveTinyUrl);
            Console.WriteLine("[Configuration] Encoding: {0}", _server.Encoding.EncodingName);
            Console.WriteLine("[Configuration] SetTopicOnStatusChanged: {0}", Config.Default.SetTopicOnStatusChanged);
            Console.WriteLine("[Configuration] EnableDropProtection: {0}", Config.Default.EnableDropProtection);
            Console.WriteLine("[Configuration] IntervalDirectMessage: {0}", Config.Default.IntervalDirectMessage);
            //Console.WriteLine("[Configuration] CookieLoginMode: {0}", Config.Default.CookieLoginMode);
            Console.WriteLine("[Configuration] ChannelName: {0}", Config.Default.ChannelName);
            Console.WriteLine("[Configuration] EnableRepliesCheck: {0}", Config.Default.EnableRepliesCheck);
            Console.WriteLine("[Configuration] IntervalReplies: {0}", Config.Default.IntervalReplies);
            Console.WriteLine("[Configuration] DisableUserList: {0}", Config.Default.DisableUserList);
            Console.WriteLine("[Configuration] BroadcastUpdate: {0}", Config.Default.BroadcastUpdate);
            Console.WriteLine("[Configuration] ClientMessageWait: {0}", Config.Default.ClientMessageWait);
            Console.WriteLine("[Configuration] BroadcastUpdateMessageIsNotice: {0}", Config.Default.BroadcastUpdateMessageIsNotice);
            Console.WriteLine("[Configuration] Proxy: {0}", options.Proxy);
            Console.WriteLine("[Configuration] PostFetchMode: {0}", options.PostFetchMode);
            Console.WriteLine("[Configuration] EnableCompression: {0}", options.EnableCompression);
            Console.WriteLine("[Configuration] DisableNoticeAtFirstTime: {0}", options.DisableNoticeAtFirstTime);
            Console.WriteLine("[Configuration] OAuthClientKey: {0}", options.OAuthClientKey);
            Console.WriteLine("[Configuration] OAuthSecretKey: {0}", options.OAuthSecretKey);

            _server.Start(bindAddress, options.Port);

            while (true)
                Thread.Sleep(1000);
        }
Ejemplo n.º 3
0
        public Boolean Initialize()
        {
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
            Int32 port = _settings.Port;
            IPAddress ipAddr = _settings.LocalOnly ? IPAddress.Loopback : IPAddress.Any;

            ContextMenu ctxMenu = new ContextMenu();
            ctxMenu.MenuItems.Add(new MenuItem("�I��(&X)", ContextMenuItemExit));
            _notifyIcon = new NotifyIcon();
            _notifyIcon.Text = String.Format("{0} (IP: {1} / �|�[�g {2})", Name, ipAddr, port);
            _notifyIcon.ContextMenu = ctxMenu;
            _notifyIcon.Icon = Resource.ApplicationIcon;

            Config.Default.EnableTrace = _settings.EnableTrace;
            Config.Default.IgnoreWatchError = _settings.IgnoreWatchError;
            Config.Default.Interval = _settings.Interval;
            Config.Default.ResolveTinyUrl = _settings.ResolveTinyUrl;
            Config.Default.EnableDropProtection = _settings.EnableDropProtection;
            Config.Default.SetTopicOnStatusChanged = _settings.SetTopicOnStatusChanged;
            Config.Default.IntervalDirectMessage = _settings.IntervalDirectMessage;
            //Config.Default.CookieLoginMode = _settings.CookieLoginMode;
            Config.Default.ChannelName = "#"+_settings.TwitterChannelName;
            Config.Default.EnableRepliesCheck = _settings.EnableRepliesCheck;
            Config.Default.IntervalReplies = _settings.IntervalReplies;
            Config.Default.DisableUserList = _settings.DisableUserList;
            Config.Default.BroadcastUpdate = _settings.BroadcastUpdate;
            Config.Default.ClientMessageWait = _settings.ClientMessageWait;
            Config.Default.BroadcastUpdateMessageIsNotice = _settings.BroadcastUpdateMessageIsNotice;
            Config.Default.POSTFetchMode = _settings.POSTFetchMode;
            Config.Default.EnableCompression = _settings.EnableCompression;
            Config.Default.DisableNoticeAtFirstTime = _settings.DisableNoticeAtFirstTime;

            _server = new Server();
            _server.ConnectionAttached += new EventHandler<ConnectionAttachEventArgs>(_server_ConnectionAttached);
            if (!String.IsNullOrEmpty(_settings.OAuthClientKey))
                _server.OAuthClientKey = _settings.OAuthClientKey;
            if (!String.IsNullOrEmpty(_settings.OAuthSecretKey))
                _server.OAuthSecretKey = _settings.OAuthSecretKey;
            try
            {
                _server.Encoding = (String.Compare(_settings.Charset, "UTF-8", true) == 0)
                    ? new UTF8Encoding(false) // BOM �Ȃ�
                    : Encoding.GetEncoding(_settings.Charset);
            }
            catch (ArgumentException)
            {
                _server.Encoding = Encoding.GetEncoding("UTF-8");
            }

            // start
            try
            {
                _server.Start(ipAddr, port);
                _notifyIcon.Visible = true;
                _notifyIcon.ShowBalloonTip(1000 * 10, Name, String.Format("IRC�T�[�o���|�[�g {0} �ŊJ�n����܂����B", port), ToolTipIcon.Info);
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message, Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            return true;
        }