Esempio n. 1
0
        /// <summary>
        /// Connects to the mud server.  Requires that the event handlers for required events be passed in here where they will
        /// be wired up.
        /// </summary>
        public async void Connect(EventHandler <string> lineReceived, EventHandler <string> dataReceived, EventHandler connectionClosed)
        {
            try
            {
                if (Telnet != null)
                {
                    Telnet.Dispose();
                    Telnet = null;
                }

                Conveyor.EchoLog($"Connecting: {App.Settings.ProfileSettings.IpAddress}:{App.Settings.ProfileSettings.Port}", LogType.Information);

                var ctc = new CancellationTokenSource();
                Telnet = new TelnetClient(App.Settings.ProfileSettings.IpAddress, App.Settings.ProfileSettings.Port, TimeSpan.FromSeconds(0), ctc.Token);
                Telnet.ConnectionClosed += connectionClosed;
                Telnet.LineReceived     += lineReceived;
                Telnet.DataReceived     += dataReceived;
                await Telnet.Connect();
            }
            catch (Exception ex)
            {
                Telnet.Dispose();
                Conveyor.EchoLog($"Connection Failed: {ex.Message}", LogType.Error);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Disconnects from the mud server if there is a connection.
 /// </summary>
 public void Disconnect()
 {
     if (Telnet != null)
     {
         Telnet.Dispose();
         Telnet = null;
         return;
     }
 }
Esempio n. 3
0
 protected virtual void Dispose(bool disposing)
 {
     if (!isDisposed)
     {
         isDisposed = true;
         if (disposing)
         {
             Disconnect();
             Disconnected       = null;
             RunScriptRequested = null;
             if (tn != null)
             {
                 tn.telnetDataEventOccurred -= tn_DataEventReceived;
                 tn.Dispose();
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Connects to the mud server.  Requires that the event handlers for required events be passed in here where they will
        /// be wired up.
        /// </summary>
        public async Task Connect(EventHandler <string> lineReceived, EventHandler <string> dataReceived, EventHandler connectionClosed)
        {
            try
            {
                if (Telnet != null)
                {
                    Telnet.Dispose();
                    Telnet = null;
                }

                // If there was a last host and it was not the current IP to connect to it likely means
                // a new profile was loaded, in that case we're going to reset the ScriptingHost to it's default
                // so things aren't hanging around.
                if (!string.IsNullOrWhiteSpace(_lastHost) && !string.Equals(_lastHost, App.Settings.ProfileSettings.IpAddress))
                {
                    this.ScriptHost?.Reset();
                    Conveyor.EchoLog("Host change detected: Scripting environment reset.", LogType.Information);

                    // Refresh the scripts so they will load when needed.
                    this.ScriptHost?.RefreshScripts();
                }

                // We can set this now, when we come back in if the IP changes they we'll reset above.
                _lastHost = App.Settings.ProfileSettings.IpAddress;

                Conveyor.EchoLog($"Connecting: {App.Settings.ProfileSettings.IpAddress}:{App.Settings.ProfileSettings.Port}", LogType.Information);

                var ctc = new CancellationTokenSource();
                this.Telnet = new TelnetClient(App.Settings.ProfileSettings.IpAddress, App.Settings.ProfileSettings.Port, TimeSpan.FromSeconds(0), ctc.Token);
                this.Telnet.ConnectionClosed += connectionClosed;
                this.Telnet.LineReceived     += lineReceived;
                this.Telnet.DataReceived     += dataReceived;
                await this.Telnet.ConnectAsync();
            }
            catch (Exception ex)
            {
                Telnet?.Dispose();
                Conveyor.EchoLog($"Connection Failed: {ex.Message}", LogType.Error);
            }
        }
Esempio n. 5
0
        protected virtual void Dispose(bool disposing)
        {
            if (isDisposed)
            {
                return;
            }
            isDisposed = true;

            if (disposing)
            {
                Disconnect();
                if (tnDataDelegate != null)
                {
                    tn.telnetDataEvent -= tnDataDelegate;
                }
                tnDataDelegate = null;
                OnDisconnect   = null;
                RunScriptEvent = null;
                if (tn != null)
                {
                    tn.Dispose();
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Disconnects from the mud server if there is a connection.
 /// </summary>
 public void Disconnect()
 {
     Telnet?.Dispose();
     Telnet = null;
 }