示例#1
0
        /// <summary>
        /// Starts the plugin
        /// </summary>
        public void Start(TvControl.IController controller)
        {
            // set up our remote control interface
            Log.WriteFile("TVServerKodi: plugin started");

            try
            {
                LoadSettings();

                connected = TVServerConnection.Init(controller);
                if (connected)
                {
                    if (GlobalServiceProvider.Instance.IsRegistered <ITvServerEvent>())
                    {
                        GlobalServiceProvider.Instance.TryGet <ITvServerEvent>().OnTvServerEvent += events_OnTvServerEvent;
                        Log.Debug("TVServerKodi: Registered OnTvServerEvent with TV Server");
                    }

                    connected = StartListenThread();
                }
                else
                {
                    Log.Error("TVServerKodi: TVServerConnection init failed.");
                }
            }
            catch
            {
                Log.Error("TVServerKodi: TVServerConnection.Init failed!");
                Console.WriteLine("TVServerConnection.Init failed!");
            }
        }
示例#2
0
        private void StopListenThread()
        {
            try
            {
                if (m_listener != null)
                {
                    if (connected)
                    {
                        TVServerConnection.CloseAll();
                    }

                    Log.Info("TVServerKodi: Stop listening");

                    m_listener.Stop();
                    m_listener = null;
                }
            }
            catch
            {
                Log.Error("TVServerKodi: StopListenThread failed!");
                Console.WriteLine("StopListenThread failed!");
            }
        }
示例#3
0
        public void HandleConnection()
        {
            try
            {
                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; TVServerKodi version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    Console.WriteLine("Correct protocol, telnet connection accepted!");
                    Log.Debug("TVServerKodi: 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("TVServerKodi: 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("TVServerKodi: connection accepted from XBMC PVR addon");

                    username   = "******" + clientnr;
                    clientType = ClientType.pvrclient;
                }
                else if (Regex.IsMatch(versionInfo, "^PVRclientKodi: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("TVServerKodi: connection accepted from Kodi PVR addon");

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

                    clientType = ClientType.unknown;
                    return;
                }

                me = TVServerConnection.RequestUser(username);

                ProcessConnection(reader);
                reader.Dispose();
                cStream.Dispose();
            }
            catch (Exception e)
            {
                WriteLine("[ERROR]: HandleConnection failed");
                Log.Debug("TVServerKodi: HandleConnection failed");
                Log.Debug("TVServerKodi: Exception => " + e.Message);
                Log.Debug("TVServerKodi: Stack trace: " + e.StackTrace);
            }
        }