Exemple #1
0
 public void Stop()
 {
     Log.Info("TVServerXBMC: Stop()");
     if (listenThread != null)
     {
         Log.Debug("TVServerXBMC: Listenthread is aborting");
         listenThread.Abort();
         listenThread = null;
     }
     if (connected)
     {
         TVServerConnection.CloseAll();
     }
 }
Exemple #2
0
        public void Start(TvControl.IController controller)
        {
            // set up our remote control interface
            try {
                connected = TVServerConnection.Init(controller);
                if (connected)
                {
                    Log.Info("TVServerXBMC: Start listening on port " + serverPort);

                    // start a thread for the listener

                    Listener l = new Listener(serverPort);
                    if (l.StartListening())
                    {
                        // start a thread to listen for clients
                        //(new Thread(new ThreadStart(ListenForClients)).Start ();
                        try
                        {
                            listenThread = new Thread(new ThreadStart(l.ListenForClients));
                            listenThread.Start();
                        }
                        catch
                        {
                            l.Stop();
                        }
                    }
                    else
                    {
                        connected = false;
                    }
                }
                else
                {
                    Log.Error("TVServerXBMC: TVServerConnection init failed.");
                }
            }
            catch
            {
                Log.Error("TVServerXBMC: TVServerConnection.Init failed!");
                Console.WriteLine("TVServerConnection.Init failed!");
            }
        }
Exemple #3
0
        public void HandleConnection()
        {
            NetworkStream cStream = this.client.GetStream();
            StreamReader  reader  = new StreamReader(cStream);

            writer = new DataWriter(cStream);

            // first we get what version of the protocol
            // we expect "TVServerXBMC:0-2"
            String versionInfo = reader.ReadLine();

            if (versionInfo == null)
            {
                return;
            }

            // version 2 is not backards compatible
            versionInfo = Uri.UnescapeDataString(versionInfo);
            if (versionInfo.ToLower().Contains("telnet"))
            {
                // human connection
                writer.setArgumentSeparator("|");
                writer.setListSeparator(Environment.NewLine);
                writer.setHumanEncoders();

                //reader side:
                cmd_sep = ":";
                arg_sep = "|";

                WriteLine("Protocol Accepted; TVServerXBMC version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                Console.WriteLine("Correct protocol, telnet connection accepted!");
                Log.Debug("TVServerXBMC: telnet connection accepted!");

                username   = "******";
                clientType = ClientType.telnet;
            }
            else if (Regex.IsMatch(versionInfo, "^TVServerXBMC:0-[0-3]$", RegexOptions.IgnoreCase))
            {
                WriteLine("Protocol-Accept;0-3");
                Console.WriteLine("Correct protocol, connection accepted!");
                Log.Debug("TVServerXBMC: connection accepted!");
                username   = "******";
                clientType = ClientType.python;
            }
            else if (Regex.IsMatch(versionInfo, "^PVRclientXBMC:0-[1]$", RegexOptions.IgnoreCase))
            {
                writer.setArgumentSeparator("|");
                //reader side:
                cmd_sep = ":";
                arg_sep = "|";

                WriteLine("Protocol-Accept:0|" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                Console.WriteLine("Correct protocol, connection accepted!");
                Log.Debug("TVServerXBMC: connection accepted from XBMC PVR addon");

                username   = "******" + clientnr;
                clientType = ClientType.pvrclient;
            }
            else
            {
                WriteLine("Unexpected Protocol");
                client.Close();
                Console.WriteLine("Unexpected protocol:" + versionInfo);
                Log.Debug("TVServerXBMC: Unexpected protocol:" + versionInfo);

                clientType = ClientType.unknown;
                return;
            }

            me = TVServerConnection.RequestUser(username);

            ProcessConnection(reader);
            reader.Dispose();
            cStream.Dispose();
        }