Beispiel #1
0
        public ServerControl(Func <ButtplugServer> aFactory)
        {
            InitializeComponent();
            _logManager = new ButtplugLogManager();
            _log        = _logManager.GetLogger(GetType());
            _ws         = new ButtplugWebsocketServer();
            _bpFactory  = aFactory;
            _config     = new ButtplugConfig("B******g");
            _connUrls   = new ConnUrlList();
            _port       = 12345;

            // Usually, if we throw errors then connect, it's not actually an error. If we don't
            // connect after a second of throwing an exception, pop the toaster, but not before then.
            _toastTimer = new Timer
            {
                Interval  = 1000,
                AutoReset = false,
                Enabled   = false,
            };
            _toastTimer.Elapsed += PopToaster;

            if (uint.TryParse(_config.GetValue("b******g.server.port", "12345"), out uint pres))
            {
                _port = pres;
            }

            _secure = true;
            if (bool.TryParse(_config.GetValue("b******g.server.secure", "true"), out bool sres))
            {
                _secure = sres;
            }

            _loopback = true;
            if (bool.TryParse(_config.GetValue("b******g.server.loopbackOnly", "true"), out bool lres))
            {
                _loopback = lres;
            }

            _hostname = _config.GetValue("b******g.server.hostname", "localhost");

            PortTextBox.Text           = _port.ToString();
            SecureCheckBox.IsChecked   = _secure;
            LoopbackCheckBox.IsChecked = _loopback;

            ConnectionUrl.ItemsSource = _connUrls;

            _ws.OnException        += WebSocketExceptionHandler;
            _ws.ConnectionAccepted += WebSocketConnectionAccepted;
            _ws.ConnectionUpdated  += WebSocketConnectionAccepted;
            _ws.ConnectionClosed   += WebSocketConnectionClosed;

            _log.OnLogException += ExceptionLogged;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ButtplugWSClient"/> class.
        /// </summary>
        /// <param name="aClientName">The name of the client (used by the server for UI and permissions).</param>
        public ButtplugWSClient(string aClientName)
        {
            _clientName = aClientName;
            IButtplugLogManager bpLogManager = new ButtplugLogManager();

            _bpLogger = bpLogManager.GetLogger(GetType());
            _parser   = new ButtplugJsonMessageParser(bpLogManager);
            _bpLogger.Info("Finished setting up ButtplugClient");
            _owningDispatcher = SynchronizationContext.Current ?? new SynchronizationContext();
            _tokenSource      = new CancellationTokenSource();
            _counter          = 0;
        }
        private void LogListBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (sender != LogListBox)
            {
                return;
            }

            if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C)
            {
                var builder = new StringBuilder();
                foreach (var item in LogListBox.SelectedItems)
                {
                    if (item is string)
                    {
                        builder.AppendLine(item as string);
                    }
                    else if (item is ListBoxItem)
                    {
                        builder.AppendLine((item as ListBoxItem).Content as string);
                    }
                }

                try
                {
                    Clipboard.SetText(builder.ToString());
                }
                catch (Exception ex)
                {
                    // We've seen weird instances of can't open clipboard
                    // but it's pretty rare. Log it.
                    var logMan = new ButtplugLogManager();
                    var log    = logMan.GetLogger(GetType());
                    log.LogException(ex);
                }
            }
        }