Esempio n. 1
0
        protected virtual void HandleXfr(NotificationConnection c, Command cmd)
        {
            // >>> XFR TrID SB
            // <<< XFR TrID SB Address SP AuthChallengeInfo

            if (cmd.Params[0] != "SB")                // only XFRs to Switchboard servers are supported, besides what else is there to XFR to?

            {
                Command errResponse = new Command(Error.SyntaxError, cmd.TrId);
                Server.Send(c, errResponse);
                return;
            }

            // provision the new session

            SwitchboardServer  sb      = SwitchboardServer.Instance;
            SwitchboardSession session = sb.CreateSession(c.User);

            SwitchboardInvitation invite = session.CreateInvitation(c.User);

            invite.Protocol = c.Protocol.Name;

            Command xfrResponse = new Command(Verb.Xfr, cmd.TrId, "SB", sb.GetEndPointForClient(c.Socket.LocalEndPoint).ToString(), "CKI", invite.Key);

            Server.Send(c, xfrResponse);
        }
Esempio n. 2
0
 public BaseSwitchboardProtocol(SwitchboardServer server) : base("BASE", 0, server)
 {
     _protocols = new List <SwitchboardProtocol>()
     {
         new Msnp2SwitchboardProtocol(server)
     };
     _protocols.Sort((px, py) => py.Pref.CompareTo(px.Pref));                 // descending sort order
 }
Esempio n. 3
0
        public async void RunInitialize(CancellationToken token)
        {
            try
            {
                var traceFilename = String.Format("logs\\outputoutput{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));
                Trace.Listeners.Add(new TextWriterLogger(File.Create(traceFilename), _synco));
                var textStream = new MemoryStream();
                Trace.Listeners.Add(new TextWriterLogger(textStream, _synco));

                var endPoint = new IPEndPoint(IPAddress.Loopback, 8080);
                var handler  = new SimpleReverseProxyHandler(ConfigurationManager.AppSettings.Get("RemoteUrl"));
                var server   = new SwitchboardServer(endPoint, handler);

                var lastStreamLength = -0L;

                server.Start();
                //long lastPosition = -1;
                var previousPosition = textStream.Position;
                TestUrl = String.Format("Intercepting at http://{0}:{1}", endPoint.Address, endPoint.Port);
                while (true)
                {
                    lock (_synco)
                    {
                        if (textStream.Position > previousPosition)
                        {
                            textStream.Position = 0L;
                            var sr = new StreamReader(textStream); //new StreamReader(copyStream);

                            var currentMemStream = sr.ReadToEnd();

                            if (currentMemStream.Length > lastStreamLength)
                            {
                                lastStreamLength        = textStream.Position;
                                Status                  = currentMemStream;
                                CurrentTransferredBytes = lastStreamLength;
                                //String.Format("{0}: {1}.{2}", currentMemStream, System.DateTime.Now.ToLongTimeString(), System.Environment.NewLine);
                            }

                            textStream.Position = previousPosition;
                        }
                        if (token.IsCancellationRequested)
                        {
                            server.Stop();
                            break;
                        }
                    }
                    await Task.Delay(100);
                }
            }

            catch (Exception exception)
            {
                Status = String.Format("Failed to load. {0}", exception);
            }
        }
Esempio n. 4
0
        private void ServerDone(object Sender, RunWorkerCompletedEventArgs e)
        {
            StatusLabel.Text                = "Status: Offline";
            StartStopServerButton.Text      = "Start Server";
            ConnectionDetailsButton.Enabled = false;
            DisconnectButton.Enabled        = false;

            ConnectionsListView.Items.Clear();
            ConnectionsListView.Enabled = false;
            MainServer = null;
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // Dump all debug data to the console, coloring it if possible
            Trace.Listeners.Add(new ConsoleLogger());

            var endPoint = new IPEndPoint(IPAddress.Loopback, 8080);
            var handler  = new SimpleReverseProxyHandler("http://www.nytimes.com");
            var server   = new SwitchboardServer(endPoint, handler);

            server.Start();

            Console.WriteLine("Point your browser at http://{0}", endPoint);

            Console.ReadLine();
        }
Esempio n. 6
0
        //------------------------------[Server Background Worker]------------------------------

        private void ServerTime(object sender, DoWorkEventArgs e)
        {
            //First lets start a server.
            MainServer = new SwitchboardServer(this, IP, Port, Welcome, AllowAnon, AllowMulti);

            //now
            while (!ServerBWorker.CancellationPending)
            {
                MainServer.Tick();
                Thread.Sleep(50);  //sleep to make sure this doesn't drive my computer insane
            }

            //if there is a cancellation pending:
            MainServer.Close();
        }
Esempio n. 7
0
        private static bool StartServers()
        {
            Console.Write("Loading User Database...");

            //String path = @"C:\Documents and Settings\David\My Documents\Visual Studio Projects\W3b.MsnpServer\Data\PinkEgoBox.sqlite";
            //String path = @"D:\Users\David\My Documents\Visual Studio Projects\Solutions\W3b.MsnpServer\Data\PinkEgoBox.sqlite";
            _dbPath = UtilityMethods.FindFile(new DirectoryInfo(Environment.CurrentDirectory), "PinkEgoBox.sqlite", 5);
            if (_dbPath == null)
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Unable to locate database file");
                Console.ResetColor();
                return(false);
            }

            User.LoadDatabase(_dbPath);

            Console.WriteLine("Done");

            Console.WriteLine("Starting Servers...");

            _dispatchServer = DispatchServer.Instance;
            _dispatchServer.Start();

            Console.ForegroundColor = _dispatchServer.ConsoleColor;
            Console.WriteLine("Dispatch Server started, listening on " + _dispatchServer.EndPoint.ToString2());

            //////////////////////

            _notificationServer = NotificationServer.Instance;
            _notificationServer.Start();

            Console.ForegroundColor = _notificationServer.ConsoleColor;
            Console.WriteLine("Notification Server started, listening on " + _notificationServer.EndPoint.ToString2());

            //////////////////////

            _switchboardServer = SwitchboardServer.Instance;
            _switchboardServer.Start();

            Console.ForegroundColor = _switchboardServer.ConsoleColor;
            Console.WriteLine("Switchboard Server started, listening on " + _switchboardServer.EndPoint.ToString2());
            Console.ResetColor();

            return(true);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var traceFilename = String.Format("outputoutput{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));

            Trace.Listeners.Add(new TextWriterLogger(File.Create(traceFilename), new object()));

            // Dump all debug data to the console, coloring it if possible
            Trace.Listeners.Add(new ConsoleLogger());

            var endPoint = new IPEndPoint(IPAddress.Loopback, 8080);
            var handler  = new SimpleReverseProxyHandler("http://www.road.is/travel-info/road-conditions-and-weather/the-entire-country/island1e.html");
            var server   = new SwitchboardServer(endPoint, handler);

            server.Start();

            Console.WriteLine("Point your browser at http://{0}", endPoint);

            Console.ReadLine();
        }
Esempio n. 9
0
 protected SwitchboardProtocol(String name, int pref, SwitchboardServer server) : base(name, pref)
 {
     Server = server;
 }
Esempio n. 10
0
 public Msnp2SwitchboardProtocol(SwitchboardServer server) : base("MSNP2", 2, server)
 {
 }
Esempio n. 11
0
 protected BaseSwitchboardProtocol(String name, int pref, SwitchboardServer server) : base(name, pref, server)
 {
 }